Skip to content

Commit

Permalink
feat: Add support for building and deploying on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jun 7, 2024
1 parent c71925a commit da17cd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ env:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build Dockerfile
run: docker build . --file Dockerfile --tag image
run: docker build . --file Dockerfile --tag image --platform linux/amd64,linux/arm64

- run: |
docker run --rm -t -v $PWD:/volume image cp /app/$HANDLER_NAME /volume/handler
Expand Down
9 changes: 9 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[target.aarch64-unknown-linux-gnu]
pre-build = [
"apt update && apt install -y protobuf-compiler"
]

[target.x86_64-unknown-linux-gnu]
pre-build = [
"apt update && apt install -y protobuf-compiler"
]
21 changes: 7 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
FROM clux/muslrust:stable as builder

ARG PROTOC_VERSION=3.20.2

RUN apt-get update && apt-get install -y openssl unzip

# Install protoc
RUN curl -sSL -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip" && unzip /tmp/protoc.zip -d /usr/local && rm /tmp/protoc.zip
RUN apt-get update && apt-get install -y openssl unzip protobuf-compiler

WORKDIR /src

# Pre-build all dependencies
RUN USER=root cargo init --bin --name bender
COPY ./Cargo.lock .
COPY ./Cargo.toml .
RUN cargo build --release --locked && rm -rf target/x86_64-unknown-linux-musl/release/deps/bender*
RUN cargo build --release --locked && rm -rf target/*/release/deps/bender*
RUN rm src/*.rs

# Add the source code
COPY . .

# Run the test suite
RUN cargo test --release && rm -rf target/x86_64-unknown-linux-musl/release/deps/bender*
RUN cargo test --release && rm -rf target/*/release/deps/bender*

# Build the final executable of the project
RUN cargo build --release --bin bender --locked

# Ensure that the binary is at a known location for the next stage
RUN mkdir /out && \
rm /src/target/x86_64-unknown-linux-musl/release/deps/bender*.d && \
cp /src/target/x86_64-unknown-linux-musl/release/deps/bender* /out/bender

FROM alpine:latest
rm /src/target/*/release/deps/bender*.d && \
cp /src/target/*/release/deps/bender* /out/bender

RUN apk --no-cache add ca-certificates
FROM cgr.dev/chainguard/static:latest

COPY --from=builder /out/bender /app/bender
ADD ./quotes.json /app/quotes.json

WORKDIR /app
CMD [ "/app/bender" ]
ENTRYPOINT [ "/app/bender" ]

0 comments on commit da17cd2

Please sign in to comment.