Skip to content

Commit 6443990

Browse files
committed
add instructions for ARM support
1 parent ec47179 commit 6443990

File tree

7 files changed

+52
-25
lines changed

7 files changed

+52
-25
lines changed

.cargo/config

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[target.x86_64-unknown-linux-musl]
22
linker = "x86_64-unknown-linux-musl-gcc"
3+
4+
[target.aarch64-unknown-linux-musl]
5+
linker = "aarch64-unknown-linux-musl-gcc"

.github/workflows/pipeline.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ jobs:
3131
- name: Linting
3232
run: cargo fmt -- --check && cargo clippy -- -Dwarnings
3333

34-
- name: Build
35-
run: DOCKER_BUILDKIT=1 docker build -f Dockerfile.x86 -t aws-lambda-adapter:latest .
34+
- name: Build x86_64
35+
run: docker build -f Dockerfile --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest-x86_64 .
36+
37+
- name: Build arm64
38+
run: docker build -f Dockerfile --build-arg ARCH=aarch64 -t aws-lambda-adapter:latest-aarch64 .

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM public.ecr.aws/amazonlinux/amazonlinux:2 as build-stage
2+
ARG ARCH=x86_64
3+
RUN rpm --rebuilddb && yum install -y yum-plugin-ovl openssl-devel
4+
RUN yum groupinstall -y "Development tools"
5+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6+
RUN source $HOME/.cargo/env && rustup target add ${ARCH}-unknown-linux-musl
7+
RUN curl -k -o /${ARCH}-linux-musl-cross.tgz https://musl.cc/${ARCH}-linux-musl-cross.tgz \
8+
&& tar zxf /${ARCH}-linux-musl-cross.tgz \
9+
&& ln -s /${ARCH}-linux-musl-cross/bin/${ARCH}-linux-musl-gcc /usr/local/bin/${ARCH}-unknown-linux-musl-gcc
10+
WORKDIR /app
11+
ADD . /app
12+
RUN source $HOME/.cargo/env && CC=${ARCH}-unknown-linux-musl-gcc cargo build --release --target=${ARCH}-unknown-linux-musl --features vendored
13+
14+
FROM scratch AS package-stage
15+
ARG ARCH=x86_64
16+
COPY --from=build-stage /app/target/${ARCH}-unknown-linux-musl/release/bootstrap /opt/bootstrap

Dockerfile.mac

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
FROM scratch
2-
COPY target/x86_64-unknown-linux-musl/release/bootstrap /opt/bootstrap
2+
ARG ARCH=x86_64
3+
COPY target/${ARCH}-unknown-linux-musl/release/bootstrap /opt/bootstrap

Dockerfile.x86

-14
This file was deleted.

Makefile

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
clean:
22
rm -rf target
33

4-
build:
4+
build-x86:
55
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
6-
DOCKER_BUILDKIT=1 docker build -f Dockerfile.x86 -t aws-lambda-adapter:latest .
6+
docker build --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest-x86_64 .
7+
8+
build-arm:
9+
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
10+
docker build --build-arg ARCH=aarch64 -t aws-lambda-adapter:latest-aarch64 .
11+
12+
build: build-x86 build-arm
13+
docker tag aws-lambda-adapter:latest-x86_64 aws-lambda-adapter:latest
714

815
build-mac:
916
CC=x86_64-unknown-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl --features vendored
1017
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
11-
DOCKER_BUILDKIT=1 docker build -f Dockerfile.mac -t aws-lambda-adapter:latest .
18+
docker build -f Dockerfile.mac --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest .

README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ $ cd aws-lambda-adapter
3232

3333
### Compiling with Docker
3434
On x86_64 Windows, Linux and macOS, you can run one command to compile Lambda Adapter with docker.
35-
The Dockerfile is [here](Dockerfile.x86). [AWS CLI](https://aws.amazon.com/cli/) should have been installed and configured.
35+
The Dockerfile is [here](Dockerfile.x86). [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) should have been installed and configured.
3636

3737
```shell
3838
$ make build
3939
```
4040

41-
Once the build completes, it creates a docker image called "aws-lambda-adapter:latest". AWS Lambda Adapter binary is packaged as '/opt/bootstrap' inside the docker image.
41+
Once the build completes, it creates two docker images:
42+
- "aws-lambda-adapter:latest-x86_64" for x86_64.
43+
- "aws-lambda-adapter:latest-aarch64" for arm64.
44+
AWS Lambda Adapter binary is packaged as '/opt/bootstrap' inside each docker image. "aws-lambda-adapter:latest" is tagged to the same image as "aws-lambda-adapter:latest-x86_64".
4245

4346
### Compiling on macOS
4447

@@ -54,6 +57,7 @@ And we have to install macOS cross-compiler toolchains. `messense/homebrew-macos
5457
```shell
5558
$ brew tap messense/macos-cross-toolchains
5659
$ brew install x86_64-unknown-linux-musl
60+
$ brew install aarch64-unknown-linux-musl
5761
```
5862

5963
And we need to inform Cargo that our project uses the newly-installed linker when building for the `x86_64-unknown-linux-musl` platform.
@@ -62,22 +66,29 @@ Create a new directory called `.cargo` in your project folder and a new file cal
6266
```shell
6367
$ mkdir .cargo
6468
$ echo '[target.x86_64-unknown-linux-musl]
65-
linker = "x86_64-unknown-linux-musl-gcc"' > .cargo/config
69+
linker = "x86_64-unknown-linux-musl-gcc"
70+
71+
[target.aarch64-unknown-linux-musl]
72+
linker = "aarch64-unknown-linux-musl-gcc"'> .cargo/config
6673
```
6774

6875
Now we can cross compile AWS Lambda Adapter.
6976

7077
```shell
7178
$ CC=x86_64-unknown-linux-musl-gcc cargo build --release --target=x86_64-unknown-linux-musl --features vendored
79+
$ CC=aarch64-unknown-linux-musl-gcc cargo build --release --target=aarch64-unknown-linux-musl --features vendored
7280
```
7381

74-
Lambda Adapter binary will be placed at `target/x86_64-unknown-linux-musl/release/bootstrap`.
82+
Lambda Adapter binary for x86_64 will be placed at `target/x86_64-unknown-linux-musl/release/bootstrap`.
83+
Lambda Adapter binary for arm64 will be placed at `target/aarch64-unknown-linux-musl/release/bootstrap`.
7584

7685
Finally, run the following command to package lambda adapter into a docker image named "aws-lambda-adapter:latest".
7786

7887
```shell
7988
$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
80-
$ DOCKER_BUILDKIT=1 docker build -f Dockerfile.mac -t aws-lambda-adapter:latest .
89+
$ docker build -f Dockerfile.mac --build-arg ARCH=x86_64 -t aws-lambda-adapter:latest-x86_64 .
90+
$ docker build -f Dockerfile.mac --build-arg ARCH=aarch64 -t aws-lambda-adapter:latest-aarch64 .
91+
$ docker tag aws-lambda-adapter:latest-x86_64 aws-lambda-adapter:latest
8192
```
8293

8394
## How to use it?

0 commit comments

Comments
 (0)