Skip to content

Commit 6e3abc7

Browse files
authored
Merge pull request #35 from cisagov/improvement/build_for_single_python_version
Target a single Python runtime
2 parents 4a283c0 + 522e0ea commit 6e3abc7

File tree

12 files changed

+24
-200
lines changed

12 files changed

+24
-200
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,6 @@ jobs:
265265
- diagnostics
266266
- lint
267267
- test
268-
strategy:
269-
matrix:
270-
# Python runtime versions supported by AWS
271-
python-version:
272-
- "3.7"
273-
- "3.8"
274-
- "3.9"
275268
steps:
276269
- name: Apply standard cisagov job preamble
277270
uses: cisagov/action-job-preamble@v1
@@ -305,16 +298,13 @@ jobs:
305298
echo "GH_SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
306299
- name: Build the base Lambda Docker image
307300
run: |
308-
docker compose build \
309-
--build-arg PY_VERSION=${{ matrix.python-version }} \
310-
build_deployment_package
301+
docker compose build build_deployment_package
311302
- name: Generate the Lambda deployment package
312303
run: docker compose up build_deployment_package
313304
- name: Upload the generated Lambda deployment package as an artifact
314305
uses: actions/upload-artifact@v4
315306
with:
316-
name: ${{ github.event.repository.name }}-py${{
317-
matrix.python-version }}-${{ env.GH_SHORT_SHA }}
307+
name: ${{ github.event.repository.name }}-${{ env.GH_SHORT_SHA }}
318308
path: ${{ env.DEFAULT_ARTIFACT_NAME }}
319309
- name: Setup tmate debug session
320310
uses: mxschmitt/action-tmate@v3

Dockerfile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
ARG PY_VERSION=3.9
2-
3-
FROM amazon/aws-lambda-python:$PY_VERSION AS install-stage
4-
5-
# Declare it a second time so it's brought into this scope.
6-
ARG PY_VERSION=3.9
1+
# The runtime tag must match the version of Python specified in the Pipfile.
2+
FROM amazon/aws-lambda-python:3.9 AS install-stage
73

84
# Install the Python packages necessary to install the Lambda dependencies.
95
RUN python3 -m pip install --no-cache-dir \
@@ -17,15 +13,16 @@ RUN python3 -m pip install --no-cache-dir \
1713
WORKDIR /tmp
1814

1915
# Copy in the dependency files.
20-
COPY src/py$PY_VERSION/ .
16+
COPY build/Pipfile build/Pipfile.lock ./
2117

2218
# Install the Lambda dependencies.
2319
#
2420
# The --extra-pip-args option is used to pass necessary arguments to the
2521
# underlying pip calls.
2622
RUN pipenv sync --system --extra-pip-args="--no-cache-dir --target ${LAMBDA_TASK_ROOT}"
2723

28-
FROM amazon/aws-lambda-python:$PY_VERSION AS build-stage
24+
# The runtime tag must match the version of Python specified in the Pipfile.
25+
FROM amazon/aws-lambda-python:3.9 AS build-stage
2926

3027
###
3128
# For a list of pre-defined annotation keys and value types see:
@@ -40,12 +37,6 @@ FROM amazon/aws-lambda-python:$PY_VERSION AS build-stage
4037
LABEL org.opencontainers.image.authors="[email protected]"
4138
LABEL org.opencontainers.image.vendor="Cybersecurity and Infrastructure Security Agency"
4239

43-
# Declare it a third time so it's brought into this scope.
44-
ARG PY_VERSION=3.9
45-
46-
# This must be present in the image to generate a deployment artifact.
47-
ENV BUILD_PY_VERSION=$PY_VERSION
48-
4940
COPY --from=install-stage ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT}
5041

5142
WORKDIR ${LAMBDA_TASK_ROOT}

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,15 @@ docker compose down
5959

6060
## How to update Python dependencies ##
6161

62-
The Python dependencies are maintained using a
63-
[Pipenv](https://github.com/pypa/pipenv) configuration for each
64-
supported Python version. Changes to requirements should be made to
65-
the respective `src/py<Python version>/Pipfile`. More information
66-
about the `Pipfile` format can be found in the [`pipenv`
67-
documentation](https://pipenv.pypa.io/en/latest/pipfile.html#example-pipfile).
68-
The accompanying `Pipfile.lock` files contain the specific dependency
69-
versions that will be installed. These files can be updated like so
70-
(using the Python 3.9 configuration as an example):
62+
The Lambda's Python dependencies are maintained using a [Pipenv](https://github.com/pypa/pipenv)
63+
configuration. Changes to requirements should be made to the `Pipfile` located at
64+
`build/Pipfile`. More information about the `Pipfile` format can be found in the
65+
[`pipenv` documentation](https://pipenv.pypa.io/en/latest/pipfile.html#example-pipfile).
66+
The accompanying `Pipfile.lock` file contains the specific dependency versions
67+
that will be installed. This file is updated automatically like so:
7168

7269
```console
73-
cd src/py3.9
70+
cd build
7471
pipenv lock
7572
```
7673

src/py3.9/Pipfile renamed to build/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ verify_ssl = true
44
name = "pypi"
55

66
[requires]
7+
# This must match the version of the Python runtime specified in the Dockerfile.
78
python_version = "3.9"
89

910
[packages]
Lines changed: 7 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
# from the invoking environment but falls back to a default value.
1212
- BUILD_FILE_NAME=${BUILD_FILE_NAME:-lambda_build.zip}
1313
volumes:
14-
- ./src/build_artifact.sh:/opt/build_artifact.sh
14+
- ./build/build_artifact.sh:/opt/build_artifact.sh
1515
- .:/var/task/output
1616
run_lambda_locally:
1717
build: .

src/py3.7/Pipfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/py3.7/Pipfile.lock

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/py3.8/Pipfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)