Added stuff
This commit is contained in:
1 parent
47dd9a1137
commit
7a249c596a
4 files changed
+87
-2
No files matched your search
@@ -0,0 +1,49 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import click
|
||||
from subprocess import check_call
|
||||
|
||||
|
||||
def index_of(str, char, cnt):
|
||||
for i, char_ in enumerate(str):
|
||||
if char == char_:
|
||||
cnt -= 1
|
||||
if cnt == 0:
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option('--file', required=True, type=click.Path(exists=True,
|
||||
dir_okay=False,
|
||||
resolve_path=True,
|
||||
path_type=Path))
|
||||
@click.option('--bucket-name', envvar='BUCKET_NAME')
|
||||
def main(file, bucket_name):
|
||||
"""Upload the gce cloud image."""
|
||||
img_id = file.name[:file.name.index('.raw.tar.gz')].replace('.', '-').replace('_', '-')
|
||||
img_family = 'nixos-image-24-11'
|
||||
s3_loc = f"gs://{bucket_name}/{file.name}"
|
||||
|
||||
cmd = [
|
||||
'gsutil', 'cp', file, s3_loc
|
||||
]
|
||||
check_call(cmd)
|
||||
|
||||
cmd = [
|
||||
'gcloud', 'compute','images','create', img_id,
|
||||
'--source-uri', s3_loc, '--family', img_family
|
||||
]
|
||||
# check_call(cmd)
|
||||
# print(' '.join(cmd))
|
||||
# return
|
||||
|
||||
cmd = [
|
||||
'gcloud', 'compute', 'images', 'add-iam-policy-binding',
|
||||
img_id, "--member", 'allAuthenticatedUsers', "--role", 'roles/compute.imageUser'
|
||||
]
|
||||
check_call(cmd)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user