Skip to content

Commit 5948cf2

Browse files
authored
feat(build): build Docker images instead of zip archive (#21)
1 parent 13b264f commit 5948cf2

16 files changed

Lines changed: 535 additions & 276 deletions

.github/workflows/pull-request-code.yml

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

.github/workflows/pull-request-format.yml

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

.github/workflows/pull-request.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- master
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
- edited
13+
14+
jobs:
15+
pr-code-checks:
16+
name: Code
17+
runs-on: ubuntu-latest
18+
if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.action == 'reopened'
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v5
22+
with:
23+
ref: ${{ github.head_ref || github.ref }}
24+
# Need full history and tags to find the last release.
25+
fetch-depth: 0
26+
fetch-tags: true
27+
28+
# Work around occasional fetch-tags quirks.
29+
- run: git fetch --tags --force
30+
31+
- name: Install Python
32+
uses: actions/setup-python@v5
33+
34+
- name: Install uv
35+
uses: astral-sh/setup-uv@v6.4.3
36+
with:
37+
version: latest
38+
39+
- name: Setup
40+
run: uv run task setup
41+
42+
- name: Lint
43+
run: uv run task lint
44+
45+
- name: Unit Test
46+
run: uv run task unit-test
47+
48+
- name: Build
49+
run: uv run task build
50+
51+
- name: Integration Test
52+
run: uv run task integration-test-no-build
53+
54+
pr-content-checks:
55+
name: Content
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v5
60+
61+
- name: Validate PR title
62+
run: ./scripts/conventional-commit.sh "${{ github.event.pull_request.title }}"

Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
########################################################
2+
# Stage 1: Install dependencies with uv and copy to /opt/python
3+
########################################################
4+
FROM python:3.12-slim AS deps
5+
6+
# Avoid prompts & keep images small
7+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
8+
PIP_NO_CACHE_DIR=1
9+
10+
ARG APP_ROOT="/app"
11+
WORKDIR ${APP_ROOT}
12+
13+
# Bring in lockfiles first for better caching
14+
COPY pyproject.toml ${APP_ROOT}/
15+
COPY uv.lock ${APP_ROOT}/
16+
17+
# Install uv and create a local venv, then sync (no dev deps)
18+
RUN pip install --no-cache-dir uv
19+
RUN uv sync --no-group dev --frozen
20+
21+
# Materialize a Lambda-style "layer" dir with only runtime packages
22+
# (Lambda adds /opt/python to sys.path automatically)
23+
RUN mkdir -p /opt/python
24+
RUN cp -a ${APP_ROOT}/.venv/lib/python3.12/site-packages/. /opt/python/
25+
26+
27+
########################################################
28+
# Stage 2: Create final AWS Lambda image
29+
########################################################
30+
#FROM public.ecr.aws/lambda/python:3.12-arm64
31+
FROM public.ecr.aws/lambda/python:3.12
32+
33+
ARG APP_NAME
34+
ARG APP_VERSION
35+
ARG COMMIT_SHA
36+
ARG BRANCH
37+
ARG BUILD_DATE
38+
39+
ENV APP_NAME="${APP_NAME}"
40+
ENV APP_VERSION="${APP_VERSION}"
41+
ENV COMMIT_SHA="${COMMIT_SHA}"
42+
ENV BRANCH="${BRANCH}"
43+
ENV BUILD_DATE="${BUILD_DATE}"
44+
45+
LABEL org.opencontainers.image.name="${APP_NAME}" \
46+
org.opencontainers.image.version="${APP_VERSION}" \
47+
org.opencontainers.image.revision="${COMMIT_SHA}" \
48+
org.opencontainers.image.ref.branch="${BRANCH}" \
49+
org.opencontainers.image.created="${BUILD_DATE}"
50+
51+
# This image automatically adds packages in /opt/python to sys.path
52+
COPY --from=deps /opt/python /opt/python
53+
COPY src/ ${LAMBDA_TASK_ROOT}/
54+
55+
ENV _HANDLER="main.handler"
56+
CMD ["main.handler"]

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# lambda-application
2-
Lambda app code and release, decoupled from Terraformed infrastructure
1+
# Demo Lambda Application
2+
3+
Lambda app code and release, decoupled from Terraformed infrastructure.

Taskfile.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
version: "3"
44

5+
vars:
6+
DOCKER_IMAGE_NAME: lambda-application
7+
DOCKER_IMAGE_TAG:
8+
sh: ./scripts/get-version.sh
9+
DOCKER_IMAGE: "{{.DOCKER_IMAGE_NAME}}:{{.DOCKER_IMAGE_TAG}}"
10+
511
tasks:
612
default:
713
cmds:
@@ -18,6 +24,11 @@ tasks:
1824
cmds:
1925
- ./scripts/setup.sh
2026

27+
get-version:
28+
run: once
29+
cmds:
30+
- ./scripts/get-version.sh
31+
2132
format:
2233
run: once
2334
cmds:
@@ -31,28 +42,37 @@ tasks:
3142
build:
3243
run: once
3344
cmds:
34-
- ./scripts/build.sh
45+
- ./scripts/build-image.sh
3546

3647
unit-test:
3748
run: once
3849
cmds:
3950
- ./scripts/unit-test.sh
4051

52+
integration-test-no-build:
53+
run: once
54+
cmds:
55+
- task: start-local-instance
56+
- defer: { task: stop-local-instance }
57+
- ./scripts/integration-test.sh
58+
4159
integration-test:
4260
run: once
4361
deps:
4462
- build
4563
cmds:
4664
- task: start-local-instance
65+
- defer: { task: stop-local-instance }
4766
- ./scripts/integration-test.sh
48-
- task: stop-local-instance
4967

5068
start-local-instance:
69+
desc: Start a local Lambda instance for testing
5170
run: once
5271
cmds:
53-
- ./scripts/local-instance.sh start
72+
- ./scripts/local-instance.sh start {{.DOCKER_IMAGE}}
5473

5574
stop-local-instance:
75+
desc: Stop the local Lambda instance
5676
run: once
5777
cmds:
58-
- ./scripts/local-instance.sh stop
78+
- ./scripts/local-instance.sh stop {{.DOCKER_IMAGE}}

0 commit comments

Comments
 (0)