This repository has been archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrebuild.py
54 lines (47 loc) · 1.56 KB
/
rebuild.py
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
'''
Removes container, removes image, builds image, starts container
Fill in the required image/container tag/name and any args
All containers use 'docker run' with '--name [CONTAINER]'
Script assumes Dockerfile at .
'''
from os import system
def sprint(string, color):
'''Tries to print with termcolor.cprint'''
try:
from termcolor import cprint
printer = 'col'
except ModuleNotFoundError:
printer = 'nocol'
if printer == 'col':
cprint(string, color)
elif printer == 'nocol':
print(string)
def spacer(string):
'''Tests and modifies spaces in *_args'''
if string == '':
return ''
if string[len(string)-1] == ' ':
return string
string = string + ' '
return string
def remake(container, build_args, start_args):
'''Remove container and image, build image and start container CONTAINER'''
build_args = spacer(build_args)
start_args = spacer(start_args)
remove_container = 'docker rm '+container
remove_image = 'docker rmi '+container
build_image = 'docker build '+build_args+'-t '+container+' .'
start_container = 'docker run --name '+container+' '+start_args+container
sprint(remove_container, 'yellow')
system(remove_container)
sprint(remove_image, 'yellow')
system(remove_image)
sprint(build_image, 'yellow')
system(build_image)
sprint(start_container, 'yellow')
system(start_container)
if __name__ == '__main__':
CONTAINER = 'kiosky'
BUILD_ARGS = ''
START_ARGS = '-p 80:80'
remake(CONTAINER, BUILD_ARGS, START_ARGS)