8000 custom docker image support · thadchas/cloud-functions-python@2cf7ce4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cf7ce4

Browse files
committed
custom docker image support
1 parent 1fa5ef0 commit 2cf7ce4

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ positional arguments:
4545
optional arguments:
4646
-h, --help show this help message and exit
4747
-p, --production Build function for production environment
48+
-i, --production_image
49+
Docker image to use for building production environment
4850
-f FILE_NAME, --file_name FILE_NAME
4951
The file name of the file you wish to build
5052
--python_version {2.7,3.5}

cloudfn/cli.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,26 @@ def pip_prefix(python_version):
5050
return 'python' + python_version + ' -m '
5151

5252

53-
def build_in_docker(file_name, python_version):
53+
def build_in_docker(file_name, python_version, production_image):
5454
cwd = os.getcwd()
55-
return [
55+
cmds = []
56+
if not production_image:
57+
cmds = cmds + [
5658
'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 + [
5969
'/bin/sh', '-c',
60-
'\'cd app && test -d cloudfn || mkdir cloudfn && cd cloudfn '
70+
'\'cd /app && test -d cloudfn || mkdir cloudfn && cd cloudfn '
6171
'&& test -d ' + cache_dir(python_version) + ' || virtualenv ' +
72+
' -p python' + python_version + ' ' +
6273
cache_dir(python_version) + ' ' +
6374
'&& . ' + cache_dir(python_version) + '/bin/activate && ' +
6475
'test -f ../requirements.txt && ' + pip_prefix(python_version) +
@@ -67,6 +78,7 @@ def build_in_docker(file_name, python_version):
6778
get_django_settings() + ' ' +
6879
' '.join(build(file_name, python_version, True)) + '\'',
6980
]
81+
return cmds
7082

7183

7284
def build(file_name, python_version, production):
@@ -98,9 +110,9 @@ def build(file_name, python_version, production):
98110
return base
99111

100112

101-
def build_cmd(file_name, python_version, production):
113+
def build_cmd(file_name, python_version, production, production_image):
102114
if production:
103-
return build_in_docker(file_name, python_version)
115+
return build_in_docker(file_name, python_version, production_image)
104116
return build(file_name, python_version, production)
105117

106118

@@ -110,7 +122,8 @@ def build_function(
110122
trigger_type,
111123
python_version,
112124
production,
113-
verbose):
125+
production_image,
126+
verbose):
114127

115128
start = time.time()
116129

@@ -129,12 +142,14 @@ def build_function(
129142
Trigger: {trigger_type}
130143
Python version: {python_version}
131144
Production: {production}
145+
Production Image: {production_image}
132146
'''.format(
133147
function_name=function_name,
134148
file_name=file_name,
135149
trigger_type=trigger_type,
136150
python_version=python_version,
137151
production=production,
152+
production_image=production_image,
138153
)
139154
)
140155

@@ -145,7 +160,7 @@ def build_function(
145160
stderr = sys.stderr
146161

147162
(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)),
149164
stdout,
150165
stderr)
151166
if p.returncode == 0:
@@ -226,6 +241,8 @@ def main():
226241
choices=['http', 'pubsub', 'bucket'])
227242
parser.add_argument('-p', '--production', action='store_true',
228243
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')
229246
parser.add_argument('-f', '--file_name', type=str, default='main.py',
230247
help='The file name of the file you wish to build')
231248
parser.add_argument('--python_version', type=str, default='2.7',
@@ -242,5 +259,6 @@ def main():
242259
args.trigger_type,
243260
args.python_version,
244261
args.production,
262+
args.production_image,
245263
args.verbose,
246264
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM python:3.5-jessie
2+
3+
RUN pip install virtualenv

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pycloudfn',
5-
version='0.1.207',
5+
version='0.1.208',
66
description='GCP Cloud functions in python',
77
url='https://github.com/MartinSahlen/cloud-functions-python',
88
author='Martin Sahlen',

0 commit comments

Comments
 (0)
0