-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-upload.py
More file actions
67 lines (63 loc) · 2.86 KB
/
docker-upload.py
File metadata and controls
67 lines (63 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import subprocess
import json
def main():
path = str(input('Enter path (empty for cwd): ')).strip().rstrip('/')
if path == '':
path = '.'
if os.path.exists(path):
os.chdir(path)
repository_url = None
project_name = None
image_name = None
useconfig = 'n'
if os.path.exists('./docker-upload-config.json'):
while True:
useconfig = str(input('Would you like to load settings from the config file? (y/n)')).lower()
if useconfig in ['y', 'yes']:
with open('./docker-upload-config.json', 'r') as f:
config = json.load()
repository_url = str(config['repository_url'])
project_name = str(config['project_name'])
image_name = str(config['image_name'])
break
elif useconfig in ['n', 'no']:
break
else:
print('Input not understood, please try again')
continue
version = str(input('Enter version number: ')).strip()
if repository_url is None:
repository_url = str(input('Enter repository url: ')).strip().rstrip('/')
if project_name is None:
project_name = str(input('Enter project name: ')).strip()
if image_name is None:
image_name = str(input('Enter image name: ')).strip()
print(f"Creating tag with version: {version}")
subprocess.run(['git', 'tag', version])
print('Pushing tag to git')
subprocess.run(['git', 'push', 'origin', version])
print('Building docker image')
subprocess.run(['docker', 'build', '--pull', '--rm', '-f', 'dockerfile', '-t', f"{image_name}:{version}", '.'])
print('Tagging docker image')
subprocess.run(['docker', 'tag', f"{image_name}:{version}", f"{repository_url}/{project_name}/{image_name}:{version}"])
print('Pushing docker image')
subprocess.run(['docker', 'push', f"{repository_url}/{project_name}/{image_name}:{version}"])
print('Done!')
if useconfig in ['n', 'no']:
while True:
saveconfig = str(input('Would you like to save these settings to a config file? (y/n): ')).lower()
if saveconfig in ['y', 'yes']:
with open('docker-upload-config.json', 'w') as f:
json.dump({'repository_url': repository_url, 'project_name': project_name, 'image_name': image_name}, f)
print('Config saved!')
break
elif saveconfig in ['n', 'no']:
break
else:
print('Input not understood, please try again')
continue
else:
print('Path does not exist!')
if __name__ == '__main__':
main()