|
| 1 | +FROM public.ecr.aws/lambda/provided:al2023-arm64 |
| 2 | +# We need nightly to be able to use build-std. Alternatively, use 1.72.0. |
| 3 | +ARG RUST_VERSION=nightly-2023-11-12 |
| 4 | +ARG TARGET=aarch64-unknown-linux-gnu |
| 5 | + |
| 6 | +RUN dnf install -y jq openssl-devel gcc gcc-c++ wget tar gzip unzip |
| 7 | + |
| 8 | +# Install a recent cmake. |
| 9 | +RUN wget https://github.com/Kitware/CMake/releases/download/v3.5.1/cmake-3.5.1.tar.gz \ |
| 10 | + && tar -xvf cmake-3.5.1.tar.gz \ |
| 11 | + && cd cmake-3.5.1 \ |
| 12 | + && ./bootstrap \ |
| 13 | + && make \ |
| 14 | + && make install |
| 15 | + |
| 16 | +# Install profobuf (used by apollo-router). |
| 17 | +RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protoc-3.15.8-linux-aarch_64.zip \ |
| 18 | + && unzip protoc-3.15.8-linux-aarch_64.zip -d .\ |
| 19 | + # Protobuf expects its "include" directory to be in the same directory as the binary. |
| 20 | + && mv bin/protoc /usr/local/bin/protoc \ |
| 21 | + && mv include /usr/local/bin/include |
| 22 | + |
| 23 | +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ |
| 24 | + | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION; \ |
| 25 | + export PATH="$HOME/.cargo/bin:$PATH"; rustup component add rust-src --toolchain $RUST_VERSION |
| 26 | + |
| 27 | +# Fetch the cargo-lambda binary. |
| 28 | +RUN curl -LO https://github.com/cargo-lambda/cargo-lambda/releases/download/v0.22.0/cargo-lambda-v0.22.0.aarch64-unknown-linux-musl.tar.gz \ |
| 29 | + && tar -xvf cargo-lambda-v0.22.0.aarch64-unknown-linux-musl.tar.gz \ |
| 30 | + && chmod +x cargo-lambda \ |
| 31 | + && mv cargo-lambda $HOME/.cargo/bin/cargo-lambda |
| 32 | + |
| 33 | +WORKDIR /dist/apollo-router-lambda |
| 34 | + |
| 35 | +# Build all of our dependencies. |
| 36 | +COPY Cargo.toml /dist/apollo-router-lambda/Cargo.toml |
| 37 | +COPY Cargo.lock /dist/apollo-router-lambda/Cargo.lock |
| 38 | +COPY scaffold.rs /dist/apollo-router-lambda/src/main.rs |
| 39 | +RUN export PATH="$HOME/.cargo/bin:$PATH"; \ |
| 40 | + export AWS_LAMBDA_FUNCTION_NAME="_"; \ |
| 41 | + export AWS_LAMBDA_FUNCTION_VERSION=1; \ |
| 42 | + export AWS_LAMBDA_FUNCTION_MEMORY_SIZE=1024; \ |
| 43 | + export AWS_LAMBDA_RUNTIME_API=http://[::]:9000/.rt; \ |
| 44 | + cargo lambda build --compiler cargo -Z build-std=std,panic_abort --target $TARGET --profile release-size; \ |
| 45 | + rm -r src; \ |
| 46 | + # Delete the previously generated build artifacts. |
| 47 | + rm -r target/$TARGET/release/deps/apollo_router_lambda*; \ |
| 48 | + rm -r target/$TARGET/release-size/deps/apollo_router_lambda*; \ |
| 49 | + rm target/lambda/apollo-router-lambda/bootstrap |
| 50 | + |
| 51 | +# Copy our actual application code and build this. |
| 52 | +COPY src/main.rs /dist/apollo-router-lambda/src/main.rs |
| 53 | + |
| 54 | +# Build our lambda bootstrap binary. The release artifact can be found at: |
| 55 | +# /dist/apollo-router-lambda/target/lambda/apollo-router-lambda/bootstrap |
| 56 | +RUN export PATH="$HOME/.cargo/bin:$PATH"; \ |
| 57 | + cargo lambda build --compiler cargo -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target $TARGET --profile release-size |
0 commit comments