Skip to content

Commit 4e87067

Browse files
authored
[Maintenance] Upgrade development container to Debian 12, add Amazon Linux 2023 Support (#55)
* Stabilize and automate the dev container build This commit resolves a series of build and runtime errors to create a stable, portable, and fully automated dev container environment that works on both `arm64` and `x86_64` architectures out-of-the-box. - Stabilize Dockerfile Build: - Upgrades the base image from `bullseye` to `bookworm`. - Consolidates all `apt-get` dependencies into a single, correctly ordered layer, installing necessary tools for cross-compilation (`gcc-x86-64-linux-gnu`, `libc6-dev-amd64-cross`). - Fixes `rustup` permission errors by installing the toolchain as `root` and granting ownership to the `vscode` user. - Adds `--break-system-packages` to the `pip install` command to comply with Debian `bookworm`'s package management policies. - Improve Architecture Portability: - Makes the `bin/build` and `bin/test` scripts architecture-aware, allowing them to run seamlessly on both `arm64` and `x86_64` hosts without manual configuration. - Fixes a bug that caused inconsistent naming of the shared library (`.so`) file between build and test runs. - Fix Container Startup on ARM64: - Centralizes QEMU and `binfmt` setup within the `Dockerfile` build, creating an architecture-aware initialization process. - This allows for the removal of legacy, conflicting setup methods that caused startup failures on `arm64` hosts: - Removes the privileged `docker run` command for `qemu-user-static` from the `postCreate` script. - Disables the redundant QEMU setup in the `docker-in-docker` feature by configuring `install-qemu: false` for the feature. * Refactor to improve portability and robustness This commit implements a small refactor to make the dev container setup more resilient and truly multi-platform. - Installs `aarch64` cross-compilation packages (`gcc-aarch64-linux-gnu`, `libc6-dev-arm64-cross`) in the `Dockerfile` to enable building for ARM64 on x86_64 hosts. - Updates `bin/build-arch` to use the correct `strip` binary (native or cross-compile) by checking both the host and target architectures. - Adds a 30-second timeout to the `postCreate` script to prevent it from hanging if the Docker daemon fails to start. - Adds a comment to `bin/test` clarifying why language runtime tests are now enabled for all architectures. - Merges the `update-alternatives` command into the main `RUN` layer, reducing the total number of image layers. * Update `Test` workflow to use newer ubuntu runner image * Modernize Test workflow and Dockerfile images This commit updates the CI configuration to resolve build failures and align the test environments with modern, supported versions. - Replaces deprecated `ubuntu-20.04` runners with `ubuntu-22.04` in the GitHub Actions workflow, fixing the hanging jobs. - Adds QEMU and Docker Buildx to `arm64` jobs to enable cross-platform image builds. - Upgrades the Debian test environment from a Bullseye-based image to a Bookworm-based one, and updates Node.js from v18 to v22 (LTS). - Updates the Python 2.7 test environment to use an `ubuntu:22.04` base image and installs Python 2.7 via the `deadsnakes` PPA. * Add test environment for Amazon Linux 2023 * Fix permissions/dependencies in tests * Downgrade py27 Ubuntu, fix amzn2023 WORKDIR * Attempt fixes for amzn2023 in Test workflow * Fix py27 in Test workflow * Use absolute path instead of tilde * Set WORKDIR for amzn2023, zip for py27 * Add WORKDIR to amzn2023, util-linux to py27 * Add nodejs to amzn2023, revert py27 for debug * Fix wrapt to v1 for py27 * Use rust:1-1 not rust:2-1
1 parent 1d0afd4 commit 4e87067

File tree

20 files changed

+363
-56
lines changed

20 files changed

+363
-56
lines changed

.devcontainer/Dockerfile

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
1-
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
2-
3-
RUN sudo apt-get update -y \
4-
&& sudo apt-get upgrade -y
5-
6-
RUN sudo apt-get install -y --fix-missing zip
7-
8-
RUN sudo apt-get update -y \
9-
&& sudo apt-get upgrade -y \
10-
&& sudo apt-get install -y zip ltrace
11-
12-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
13-
RUN rustup update \
14-
&& rustup target add aarch64-unknown-linux-gnu
15-
16-
RUN rustup default stable
17-
# x86_64 to arm64 support.
18-
RUN sudo apt-get install -y \
19-
qemu \
1+
FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm
2+
3+
RUN apt-get update -y \
4+
&& apt-get upgrade -y \
5+
&& apt-get install -y --fix-missing --no-install-recommends \
6+
\
7+
# Zip for packaging
8+
zip \
9+
\
10+
# QEMU for multi-architecture support
11+
qemu-system \
2012
binfmt-support \
21-
qemu-user-static
13+
qemu-user-static \
14+
\
15+
# Language runtimes for tests
16+
nodejs \
17+
ruby \
18+
php \
19+
php-common \
20+
python3-pip \
21+
\
22+
# Cross-compilation toolchains
23+
gcc-x86-64-linux-gnu \
24+
libc6-dev-amd64-cross \
25+
gcc-aarch64-linux-gnu \
26+
libc6-dev-arm64-cross \
27+
\
28+
# Clean up, enable QEMU, and set Python alternative in a single layer
29+
&& rm -rf /var/lib/apt/lists/* \
30+
&& update-binfmts --enable qemu-aarch64 \
31+
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
32+
33+
# Switch to root to install rust targets and fix permissions
34+
USER root
35+
36+
# Install rust targets for cross-compilation
37+
RUN rustup update \
38+
&& rustup default stable \
39+
&& rustup target add aarch64-unknown-linux-gnu \
40+
&& rustup target add x86_64-unknown-linux-gnu
2241

23-
# Easy way to install node, ruby, and php
24-
RUN apt-get -y install nodejs ruby php php-common
42+
# Grant vscode user ownership of rustup and cargo directories
43+
RUN chown -R vscode:vscode /usr/local/rustup /usr/local/cargo
2544

26-
# Easy way to install Python.
27-
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
45+
# Switch back to vscode user
46+
USER vscode
2847

2948
# Multi-platform SAM CLI. https://github.com/aws/aws-sam-cli/issues/3908
30-
RUN apt-get install -y pip && pip install aws-sam-cli
49+
RUN pip install aws-sam-cli --break-system-packages

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
},
66
"features": {
77
"ghcr.io/devcontainers/features/aws-cli:latest": {},
8-
"ghcr.io/devcontainers/features/docker-in-docker:latest": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:latest": {
9+
"install-qemu": false
10+
},
911
"ghcr.io/customink/codespaces-features/docker-log-level": {},
1012
"ghcr.io/devcontainers/features/sshd:latest": {}
1113
},

.devcontainer/postCreate

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#!/bin/sh
22
set -e
33

4-
docker run \
5-
--rm \
6-
--privileged \
7-
multiarch/qemu-user-static \
8-
--reset -p yes
4+
# Wait for docker to be ready
5+
TIMEOUT=30
6+
while ! docker info > /dev/null 2>&1; do
7+
echo "Waiting for docker daemon..."
8+
sleep 1
9+
TIMEOUT=$((TIMEOUT - 1))
10+
if [ $TIMEOUT -le 0 ]; then
11+
echo "Docker daemon failed to start"
12+
exit 1
13+
fi
14+
done

.github/workflows/test.yml

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: [push, workflow_dispatch]
33
jobs:
44
image:
55
name: Image
6-
runs-on: ubuntu-20.04
6+
runs-on: ubuntu-22.04
77
steps:
88
- uses: actions/checkout@v4
99
- uses: docker/login-action@v2
@@ -19,7 +19,7 @@ jobs:
1919
runCmd: echo DONE!
2020
debian-x86-64:
2121
name: Debian x86_64
22-
runs-on: ubuntu-20.04
22+
runs-on: ubuntu-22.04
2323
needs: image
2424
steps:
2525
- name: Checkout
@@ -34,11 +34,15 @@ jobs:
3434
./bin/test-local
3535
debian-arm64:
3636
name: Debian arm64
37-
runs-on: ubuntu-20.04
37+
runs-on: ubuntu-22.04
3838
needs: image
3939
steps:
4040
- name: Checkout
4141
uses: actions/checkout@v4
42+
- name: Set up QEMU
43+
uses: docker/setup-qemu-action@v3
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
4246
- name: Test
4347
uses: devcontainers/ci@v0.2
4448
with:
@@ -49,7 +53,7 @@ jobs:
4953
./debian/test-arm64
5054
amazon-x86-64:
5155
name: AmazonLinux2/x86_64
52-
runs-on: ubuntu-20.04
56+
runs-on: ubuntu-22.04
5357
needs: image
5458
steps:
5559
- name: Checkout
@@ -64,11 +68,15 @@ jobs:
6468
./amzn/test
6569
amazon-arm64:
6670
name: AmazonLinux2 arm64
67-
runs-on: ubuntu-20.04
71+
runs-on: ubuntu-22.04
6872
needs: image
6973
steps:
7074
- name: Checkout
7175
uses: actions/checkout@v4
76+
- name: Set up QEMU
77+
uses: docker/setup-qemu-action@v3
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
7280
- name: Test
7381
uses: devcontainers/ci@v0.2
7482
with:
@@ -79,7 +87,7 @@ jobs:
7987
./amzn/test-arm64
8088
ubuntu-py27:
8189
name: Ubuntu x86_64 (Python27)
82-
runs-on: ubuntu-20.04
90+
runs-on: ubuntu-22.04
8391
needs: image
8492
steps:
8593
- name: Checkout
@@ -92,3 +100,37 @@ jobs:
92100
runCmd: |
93101
./py27/setup
94102
./py27/test
103+
amazonlinux2023-x86-64:
104+
name: AmazonLinux2023/x86_64
105+
runs-on: ubuntu-22.04
106+
needs: image
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v4
110+
- name: Test
111+
uses: devcontainers/ci@v0.2
112+
with:
113+
push: never
114+
cacheFrom: ghcr.io/rails-lambda/crypteia-ci
115+
runCmd: |
116+
./amzn2023/setup
117+
./amzn2023/test
118+
amazonlinux2023-arm64:
119+
name: AmazonLinux2023 arm64
120+
runs-on: ubuntu-22.04
121+
needs: image
122+
steps:
123+
- name: Checkout
124+
uses: actions/checkout@v4
125+
- name: Set up QEMU
126+
uses: docker/setup-qemu-action@v3
127+
- name: Set up Docker Buildx
128+
uses: docker/setup-buildx-action@v3
129+
- name: Test
130+
uses: devcontainers/ci@v0.2
131+
with:
132+
push: never
133+
cacheFrom: ghcr.io/rails-lambda/crypteia-ci
134+
runCmd: |
135+
./amzn2023/setup-arm64
136+
./amzn2023/test-arm64

amzn2023/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
2+
3+
# Install required build dependencies and Node.js for testing
4+
RUN dnf install -y gcc openssl-devel python3-pip util-linux nodejs && \
5+
pip3 install setuptools && \
6+
dnf clean all
7+
8+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
9+
ENV PATH="/root/.cargo/bin:${PATH}"
10+
11+
RUN /root/.cargo/bin/rustup update \
12+
&& /root/.cargo/bin/rustup target add aarch64-unknown-linux-gnu \
13+
&& /root/.cargo/bin/rustup default stable
14+
15+
WORKDIR /var/task
16+
17+
ENV CRYPTEIA_BUILD_OS=amzn
18+
ENV CRYPTEIA_BUILD_TARGET=x86_64-unknown-linux-gnu
19+

amzn2023/Dockerfile-arm64

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM public.ecr.aws/amazonlinux/amazonlinux:2023
2+
3+
# Install required build dependencies and Node.js for testing
4+
RUN dnf install -y gcc openssl-devel python3-pip util-linux nodejs && \
5+
pip3 install setuptools && \
6+
dnf clean all
7+
8+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
9+
ENV PATH="/root/.cargo/bin:${PATH}"
10+
11+
RUN /root/.cargo/bin/rustup update \
12+
&& /root/.cargo/bin/rustup target add aarch64-unknown-linux-gnu \
13+
&& /root/.cargo/bin/rustup default stable
14+
15+
WORKDIR /var/task
16+
17+
ENV CRYPTEIA_BUILD_OS=amzn
18+
ENV CRYPTEIA_BUILD_TARGET=aarch64-unknown-linux-gnu

amzn2023/Dockerfile-test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM public.ecr.aws/lambda/nodejs:22
2+
3+
COPY build/crypteia-amzn /opt/extensions/crypteia
4+
COPY build/libcrypteia-amzn.so /opt/lib/libcrypteia.so
5+
6+
WORKDIR /var/task
7+
8+
ENV CRYPTEIA_BUILD_OS=amzn
9+
ENV SKIP_CARGO_TEST=1
10+
11+
ENV EXISTING=existingvalue
12+
ENV LD_PRELOAD=/opt/lib/libcrypteia.so
13+
14+
# For assert.sh support
15+
RUN dnf install -y util-linux && dnf clean all

amzn2023/Dockerfile-test-arm64

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM public.ecr.aws/lambda/nodejs:22-arm64
2+
3+
COPY build/crypteia-amzn-arm64 /opt/extensions/crypteia
4+
COPY build/libcrypteia-amzn-arm64.so /opt/lib/libcrypteia.so
5+
6+
WORKDIR /var/task
7+
8+
ENV CRYPTEIA_BUILD_OS=amzn
9+
ENV SKIP_CARGO_TEST=1
10+
11+
ENV EXISTING=existingvalue
12+
ENV LD_PRELOAD=/opt/lib/libcrypteia.so
13+
14+
# For assert.sh support
15+
RUN dnf install -y util-linux && dnf clean all
16+

amzn2023/setup

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "== [amzn2023/Dockerfile] building... =="
5+
docker build --tag crypteia-lambda-amzn2023 --file amzn2023/Dockerfile .
6+
7+
echo "== [amzn2023/Dockerfile] bin/setup =="
8+
docker run \
9+
--rm \
10+
--user root \
11+
--entrypoint "./bin/setup" \
12+
--volume "${PWD}:/var/task" \
13+
crypteia-lambda-amzn2023
14+

amzn2023/setup-arm64

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "== [amzn2023/Dockerfile-arm64] building... =="
5+
docker build --platform linux/arm64 --tag crypteia-lambda-amzn2023-arm64 --file amzn2023/Dockerfile-arm64 .
6+
7+
echo "== [amzn2023/Dockerfile-arm64] bin/setup =="
8+
docker run \
9+
--platform linux/arm64 \
10+
--rm \
11+
--user root \
12+
--entrypoint "./bin/setup" \
13+
--volume "${PWD}:/var/task" \
14+
crypteia-lambda-amzn2023-arm64

0 commit comments

Comments
 (0)