Skip to content

Commit dde782d

Browse files
committed
build: use a single Dockerfile for all targets
1 parent ceb6279 commit dde782d

File tree

5 files changed

+143
-58
lines changed

5 files changed

+143
-58
lines changed

.github/workflows/release.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,57 @@ jobs:
4343
key: ${{ runner.os }}-buildx-${{ github.sha }}
4444
restore-keys: |
4545
${{ runner.os }}-buildx-
46+
- name: Get version from semantic-release
47+
id: version
48+
run: |
49+
VERSION=$(npx semantic-release --dry-run | grep -oP 'The next release version is \K[0-9]+\.[0-9]+\.[0-9]+')
50+
echo "VERSION=$VERSION" >> $GITHUB_ENV
4651
- name: Build Docker images
4752
run: |
4853
echo "${{ secrets.GHCR_PAT }}" > github_token
4954
export DOCKER_BUILDKIT=1
55+
VERSION=$VERSION
56+
IMAGE=ghcr.io/ql4b/lambda-shell-runtime
5057
5158
docker buildx build --builder shell-runtime-builder --platform linux/arm64 \
52-
--build-arg HTTP_CLI_VERSION=${{ env.HTTP_CLI_VERSION }} \
53-
--output type=docker --progress=plain \
59+
--build-arg HTTP_CLI_VERSION=$VERSION \
60+
--output type=registry --progress=plain \
5461
--secret id=github_token,src=github_token \
5562
--cache-from type=local,src=/tmp/.buildx-cache \
5663
--cache-to type=local,dest=/tmp/.buildx-cache \
57-
-t lambda-shell-runtime:base -f base.Dockerfile .
64+
-t $IMAGE:base-$VERSION \
65+
-t $IMAGE:base-latest \
66+
-f base.Dockerfile .
5867
5968
docker buildx build --builder shell-runtime-builder --platform linux/arm64 \
60-
--build-arg HTTP_CLI_VERSION=${{ env.HTTP_CLI_VERSION }} \
61-
--output type=docker --progress=plain \
69+
--build-arg HTTP_CLI_VERSION=$VERSION \
70+
--output type=registry --progress=plain \
6271
--secret id=github_token,src=github_token \
6372
--cache-from type=local,src=/tmp/.buildx-cache \
6473
--cache-to type=local,dest=/tmp/.buildx-cache \
65-
-t lambda-shell-runtime:tiny -f tiny.Dockerfile .
74+
-t $IMAGE:tiny-$VERSION \
75+
-t $IMAGE:tiny-latest \
76+
-f tiny.Dockerfile .
6677
6778
docker buildx build --builder shell-runtime-builder --platform linux/arm64 \
68-
--build-arg HTTP_CLI_VERSION=${{ env.HTTP_CLI_VERSION }} \
69-
--output type=docker --progress=plain \
79+
--build-arg HTTP_CLI_VERSION=$VERSION \
80+
--output type=registry --progress=plain \
7081
--secret id=github_token,src=github_token \
7182
--cache-from type=local,src=/tmp/.buildx-cache \
7283
--cache-to type=local,dest=/tmp/.buildx-cache \
73-
-t lambda-shell-runtime:micro -f micro.Dockerfile .
84+
-t $IMAGE:micro-$VERSION \
85+
-t $IMAGE:micro-latest \
86+
-f micro.Dockerfile .
7487
7588
docker buildx build --builder shell-runtime-builder --platform linux/arm64 \
76-
--build-arg HTTP_CLI_VERSION=${{ env.HTTP_CLI_VERSION }} \
77-
--output type=docker --progress=plain \
89+
--build-arg HTTP_CLI_VERSION=$VERSION \
90+
--output type=registry --progress=plain \
7891
--secret id=github_token,src=github_token \
7992
--cache-from type=local,src=/tmp/.buildx-cache \
8093
--cache-to type=local,dest=/tmp/.buildx-cache \
81-
-t lambda-shell-runtime:full -f Dockerfile .
94+
-t $IMAGE:full-$VERSION \
95+
-t $IMAGE:full-latest \
96+
-f Dockerfile .
8297
shell: bash
8398
- name: Log in to GHCR
8499
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u skunxicat --password-stdin

Dockerfile

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,108 @@
1-
FROM lamda-shell-runtime:tiny
1+
FROM public.ecr.aws/lambda/provided:al2023 AS builder
2+
3+
ARG HTTP_CLI_VERSION=v1.0.1
4+
5+
RUN dnf install -y unzip && \
6+
dnf clean all
7+
8+
# Download http-cli
9+
RUN --mount=type=secret,id=github_token \
10+
curl -H "Authorization: token $(cat /run/secrets/github_token)" \
11+
-L "https://github.com/ql4b/http-cli/archive/refs/tags/${HTTP_CLI_VERSION}.zip" \
12+
-o http-cli.zip && \
13+
unzip http-cli.zip && \
14+
mkdir -p /http-cli-bin && \
15+
mv http-cli-${HTTP_CLI_VERSION#v}/http-cli /http-cli-bin/ && \
16+
chmod +x /http-cli-bin/http-cli && \
17+
rm -rf http-cli.zip http-cli-${HTTP_CLI_VERSION#v}
18+
19+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
20+
21+
# base: minimal runtime setup with jq
22+
FROM public.ecr.aws/lambda/provided:al2023 AS base
23+
24+
ARG VERSION=develop
25+
ARG HTTP_CLI_VERSION
26+
27+
# Install only runtime dependencies
28+
RUN dnf install -y jq && \
29+
dnf clean all && \
30+
rm -rf /var/cache/dnf
31+
32+
# Copy http-cli
33+
COPY --from=builder /http-cli-bin/http-cli /var/task/bin/http-cli
34+
ENV PATH="/var/task/bin:${PATH}"
35+
36+
COPY runtime/bootstrap /var/runtime/bootstrap
37+
RUN chmod +x /var/runtime/bootstrap
38+
39+
WORKDIR /var/task
40+
41+
COPY task/handler.sh handler.sh
42+
43+
LABEL org.opencontainers.image.source="https://github.com/ql4b/lambda-shell-runtime"
44+
LABEL org.opencontainers.image.version="${VERSION}"
45+
46+
# tiny: add lamnda helper functions
47+
FROM base AS tiny
48+
49+
ARG VERSION
50+
ARG HTTP_CLI_VERSION
51+
52+
COPY task/helpers.sh helpers.sh
53+
54+
LABEL org.opencontainers.image.title="lambda-shell-runtime:tiny"
55+
LABEL org.opencontainers.image.version="${VERSION}"
56+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
57+
58+
FROM public.ecr.aws/lambda/provided:al2023 AS awscurl-installer
59+
60+
RUN dnf install -y unzip python3-pip findutils && \
61+
dnf clean all
62+
63+
RUN pip3 install --no-cache-dir --target /tmp/awscurl awscurl && \
64+
find /tmp/awscurl -type d -name '__pycache__' -exec rm -rf {} + && \
65+
find /tmp/awscurl -type f -name '*.pyc' -delete && \
66+
find /tmp/awscurl -type d -name '*.dist-info' -exec rm -rf {} +
67+
68+
# micro: inclues awscurl
69+
FROM tiny AS micro
70+
71+
ARG VERSION
72+
ARG HTTP_CLI_VERSION
73+
74+
RUN dnf install -y python3 && \
75+
dnf clean all && \
76+
rm -rf /var/cache/dnf
77+
78+
COPY --from=awscurl-installer /tmp/awscurl /var/task/aws
79+
# Clean up Python cache and metadata
80+
RUN rm -rf \
81+
/var/task/aws/__pycache__ \
82+
/var/task/aws/*.dist-info \
83+
/var/task/aws/**/__pycache__
84+
85+
ENV PYTHONPATH="/var/task/aws"
86+
87+
RUN mkdir -p /var/task/bin && \
88+
printf '#!/bin/sh\nexport PYTHONPATH=/var/task/aws\nexec python3 -m awscurl.awscurl "$@"\n' > /var/task/bin/awscurl && \
89+
chmod +x /var/task/bin/awscurl
90+
91+
LABEL org.opencontainers.image.title="lambda-shell-runtime:micro"
92+
LABEL org.opencontainers.image.version="${VERSION}"
93+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
94+
95+
# full: includes aws-cli for complete AWS functionality
96+
FROM tiny AS full
97+
98+
ARG VERSION
99+
ARG HTTP_CLI_VERSION
2100

3101
RUN dnf install -y \
4-
jq \
5102
aws-cli && \
6103
dnf clean all && \
7-
rm -rf /var/cache/dnf
104+
rm -rf /var/cache/dnf
105+
106+
LABEL org.opencontainers.image.title="lambda-shell-runtime:full"
107+
LABEL org.opencontainers.image.version="${VERSION}"
108+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"

build

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#!/bin/sh
32

43
set -ex
@@ -7,6 +6,7 @@ set -ex
76
PLATFORM="linux/arm64"
87
MODE="--load"
98
TAG="lambda-shell-runtime"
9+
VERSION="${VERSION:-dev}"
1010
VARIANTS="base tiny micro full"
1111

1212
# Parse arguments
@@ -40,17 +40,24 @@ while [ $# -gt 0 ]; do
4040
done
4141

4242
for VARIANT in $VARIANTS; do
43-
DOCKERFILE="./${VARIANT}.Dockerfile"
44-
[ "$VARIANT" = "full" ] && DOCKERFILE="./Dockerfile"
43+
DOCKERFILE="./Dockerfile"
44+
TARGET="$VARIANT"
4545

46-
[ "$VARIANT" = "base" ] && MODE="--load"
46+
[ "$VARIANT" = "base" ] && TARGET=""
4747

4848
echo "Building $VARIANT ($DOCKERFILE) with platform $PLATFORM..."
4949
docker buildx build \
5050
--platform "$PLATFORM" \
5151
--secret id=github_token,env=GITHUB_TOKEN \
5252
--tag $TAG:$VARIANT \
5353
--file "$DOCKERFILE" \
54+
${TARGET:+--target "$TARGET"} \
5455
$MODE \
5556
.
56-
done
57+
58+
if [ -n "$VERSION" ]; then
59+
echo "Tagging $TAG:$VARIANT-$VERSION"
60+
docker tag $TAG:$VARIANT $TAG:$VARIANT-$VERSION
61+
fi
62+
done
63+

micro.Dockerfile

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

tiny.Dockerfile

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

0 commit comments

Comments
 (0)