@@ -50,15 +50,26 @@ def pip_prefix(python_version):
50
50
return 'python' + python_version + ' -m '
51
51
52
52
53
- def build_in_docker (file_name , python_version ):
53
+ def build_in_docker (file_name , python_version , production_image ):
54
54
cwd = os .getcwd ()
55
- return [
55
+ cmds = []
56
+ if not production_image :
57
+ cmds = cmds + [
56
58
'docker' , 'build' , '-f' , docker_path () + dockerfile (python_version ),
57
- '-t' , image_name (python_version ), docker_path (), '&&' , 'docker' , 'run' ,
58
- '--rm' , '-ti' , '-v' , cwd + ':/app' , image_name (python_version ),
59
+ '-t' , image_name (python_version ), docker_path (), '&&' ]
60
+
61
+ cmds = cmds + ['docker' , 'run' , '--rm' , '-ti' , '-v' , cwd + ':/app' ]
62
+
63
+ if production_image :
64
+ cmds .append (production_image )
65
+ else :
66
+ cmds .append (image_name (python_version ))
67
+
68
+ cmds = cmds + [
59
69
'/bin/sh' , '-c' ,
60
- '\' cd app && test -d cloudfn || mkdir cloudfn && cd cloudfn '
70
+ '\' cd / app && test -d cloudfn || mkdir cloudfn && cd cloudfn '
61
71
'&& test -d ' + cache_dir (python_version ) + ' || virtualenv ' +
72
+ ' -p python' + python_version + ' ' +
62
73
cache_dir (python_version ) + ' ' +
63
74
'&& . ' + cache_dir (python_version ) + '/bin/activate && ' +
64
75
'test -f ../requirements.txt && ' + pip_prefix (python_version ) +
@@ -67,6 +78,7 @@ def build_in_docker(file_name, python_version):
67
78
get_django_settings () + ' ' +
68
79
' ' .join (build (file_name , python_version , True )) + '\' ' ,
69
80
]
81
+ return cmds
70
82
71
83
72
84
def build (file_name , python_version , production ):
@@ -98,9 +110,9 @@ def build(file_name, python_version, production):
98
110
return base
99
111
100
112
101
- def build_cmd (file_name , python_version , production ):
113
+ def build_cmd (file_name , python_version , production , product
10000
ion_image ):
102
114
if production :
103
- return build_in_docker (file_name , python_version )
115
+ return build_in_docker (file_name , python_version , production_image )
104
116
return build (file_name , python_version , production )
105
117
106
118
@@ -110,7 +122,8 @@ def build_function(
110
122
trigger_type ,
111
123
python_version ,
112
124
production ,
113
- verbose ):
125
+ production_image ,
126
+ verbose ):
114
127
115
128
start = time .time ()
116
129
@@ -129,12 +142,14 @@ def build_function(
129
142
Trigger: {trigger_type}
130
143
Python version: {python_version}
131
144
Production: {production}
145
+ Production Image: {production_image}
132
146
''' .format (
133
147
function_name = function_name ,
134
148
file_name = file_name ,
135
149
trigger_type = trigger_type ,
136
150
python_version = python_version ,
137
151
production = production ,
152
+ production_image = production_image ,
138
153
)
139
154
)
140
155
@@ -145,7 +160,7 @@ def build_function(
145
160
stderr = sys .stderr
146
161
147
162
(p , output ) = run_build_cmd (
148
- ' ' .join (build_cmd (file_name , python_version , production )),
163
+ ' ' .join (build_cmd (file_name , python_version , production , production_image )),
149
164
stdout ,
150
165
stderr )
151
166
if p .returncode == 0 :
@@ -226,6 +241,8 @@ def main():
226
241
choices = ['http' , 'pubsub' , 'bucket' ])
227
242
parser .add_argument ('-p' , '--production' , action = 'store_true' ,
228
243
help = 'Build function for production environment' )
244
+ parser .add_argument ('-i' , '--production_image' , type = str ,
245
+ help = 'Docker image to use for building production environment' )
229
246
parser .add_argument ('-f' , '--file_name' , type = str , default = 'main.py' ,
230
247
help = 'The file name of the file you wish to build' )
231
248
parser .add_argument ('--python_version' , type = str , default = '2.7' ,
@@ -242,5 +259,6 @@ def main():
242
259
args .trigger_type ,
243
260
args .python_version ,
244
261
args .production ,
262
+ args .production_image ,
245
263
args .verbose ,
246
264
)
0 commit comments