Skip to content

Commit 0122ed1

Browse files
committed
Support custom lambda build images tags
1 parent f05cc28 commit 0122ed1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

Diff for: README.rst

+8-6
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ These are the available arguments:
154154
| +----------+--------------------------------------+------------------------------------------------------------------------------------------+
155155
| | Optional | Default: Random hash | Allowed: ``commit`` hash | ``tag`` ver |
156156
+--------------------------------+----------+--------------------------------------+------------------------------------------------------------------------------------------+
157-
| --aws-profile-name | AWS profile name (if not provided, will use default aws env variables) |
157+
| --build-docker-repo | Use custom build docker repository (other than lambci/lambda) |
158158
| +----------+--------------------------------------+------------------------------------------------------------------------------------------+
159-
| | Optional | Default: None | Allowed: existing aws profile name |
159+
| | Optional | Default: lambci/lambda | Allowed: a valid docker repo without image tag part |
160160
+--------------------------------+----------+--------------------------------------+------------------------------------------------------------------------------------------+
161-
| --watch-log-stream | Watch lambda log stream in realtime after publishing the function |
161+
| --build-docker-image | Custom build docker image tag (if not provided, will use build-{[python|node][runtime-version]}) lambci/lambda repo |
162162
| +----------+--------------------------------------+------------------------------------------------------------------------------------------+
163-
| | Optional | Default: True | Allowed: Boolean |
163+
| | Optional | Default: None | Allowed: an existing docker image tag |
164164
+--------------------------------+----------+--------------------------------------+------------------------------------------------------------------------------------------+
165165

166166

@@ -172,14 +172,16 @@ Example
172172
aws-lambda-ci \
173173
--app-s3-bucket "kodhive-prd-useast1-ippan-core-artifacts" \
174174
--function-name "useast1-mimoto-api-v1-codeless" \
175-
--function-runtime "python3.7" \
175+
--function-runtime "python3.11" \
176176
--function-alias-name "latest" \
177177
--function-layer-name "useast1-mimoto-api-v1-codeless-deps" \
178178
--app-src-path "app/api/src" \
179179
--app-packages-descriptor-path "app/api/src/requirements/lambda.txt" \
180180
--source-version "1.0.1" \
181181
--aws-profile-name "kodhive_prd" \
182-
--watch-log-stream
182+
--watch-log-stream \
183+
--build-docker-repo public.ecr.aws/sam/build-python3.11 \
184+
--build-docker-image latest
183185
184186
Demos
185187
======

Diff for: ci.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
parser.add_argument('--build-docker-repo', dest='build_docker_repo', required=False, default="lambci/lambda",
5050
help="Use custom lambci/lambda build docker repository")
5151

52+
parser.add_argument('--build-docker-image', dest='build_docker_image', required=False, default=None,
53+
help="Build custom docker image tag (if not provided, will use build-{[python|node][runtime-version]})")
54+
5255
args = parser.parse_args()
5356

5457
# Validation
@@ -108,6 +111,7 @@ def wrapper(*args, **kwargs):
108111
FUNCTION_REGION = FUNCTION_LATEST_CONFIG["FunctionArn"].split(":")[3]
109112
FUNCTION_LATEST_VERSION = FUNCTION_LATEST_CONFIG["Version"]
110113
FUNCTION_LATEST_CODE_SHA = FUNCTION_LATEST_CONFIG["CodeSha256"]
114+
FUNCTION_LATEST_LAYERS = FUNCTION_LATEST_CONFIG.get("Layers", [])
111115
FUNCTION_CURRENT_GIT_VERSION = FUNCTION_LATEST_CONFIG["Description"] if FUNCTION_LATEST_CONFIG else "Virgin"
112116
FUNCTION_LATEST_LAYER_CONFIG = lam.list_layer_versions(LayerName=FUNCTION_LAYER_NAME, MaxItems=1)["LayerVersions"]
113117
FUNCTION_LATEST_LAYER_VERSION = FUNCTION_LATEST_LAYER_CONFIG[0]["Version"] if FUNCTION_LATEST_LAYER_CONFIG else 0
@@ -142,6 +146,7 @@ def wrapper(*args, **kwargs):
142146

143147
# Build repo
144148
BUILD_DOCKER_REPO = args.build_docker_repo
149+
BUILD_DOCKER_IMAGE = args.build_docker_image
145150

146151
COL_BLU = "\033[94m"
147152
COL_GRN = "\033[92m"
@@ -168,6 +173,10 @@ def build():
168173
if found_cache:
169174
deps_changed = application_dependencies_changed()
170175

176+
# Force Rebuild deps if there is no Layer attached to the lambda
177+
if not FUNCTION_LATEST_LAYERS:
178+
deps_changed = True
179+
171180
if deps_changed:
172181
# FETCH/PACKAGE DEPENDENCIES
173182
fetch_dependencies()
@@ -340,9 +349,13 @@ def npm():
340349

341350

342351
def docker_run(install_cmd):
352+
if BUILD_DOCKER_IMAGE:
353+
image_tag = BUILD_DOCKER_IMAGE
354+
else:
355+
image_tag = f"build-{FUNCTION_RUNTIME}"
343356
docker_cmd = (
344357
"docker", "run", f'-v "{WORKING_DIR}":/var/task',
345-
f"--rm {BUILD_DOCKER_REPO}:build-{FUNCTION_RUNTIME}",
358+
f"--rm {BUILD_DOCKER_REPO}:{image_tag}",
346359
f'/bin/sh -c "{install_cmd}"'
347360
)
348361
try:
@@ -474,7 +487,7 @@ def ci():
474487
summary(
475488
lambda_published_version, layer_published_version or FUNCTION_LATEST_LAYER_VERSION,
476489
code_changed=code_changed, deps_changed=deps_changed,
477-
)
490+
)
478491

479492

480493
# EntryPoint

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="aws-lambda-ci",
5-
version="0.0.2",
5+
version="0.0.8",
66
url="https://github.com/obytes/aws-lambda-ci",
77
license="Apache License 2.0",
88
author="Hamza Adami",

0 commit comments

Comments
 (0)