Skip to content

Commit

Permalink
multiplatform docker builds (FuelLabs#1233)
Browse files Browse the repository at this point in the history
Enables the arm64 platform in our docker image builds. This should help
with running fuel-core docker images on M1 silicon.
  • Loading branch information
Voxelot authored Jul 4, 2023
1 parent 45982da commit 8fff229
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ xtask = "run --package xtask --"

[registries.crates-io]
protocol = "sparse"

# This is needed to enable cross-platform docker builds, as cargo doesn't use the correct linker sometimes:
# https://github.com/rust-lang/cargo/issues/4133
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@ jobs:
password: ${{ secrets.DOCKER_IO_READ_ONLY_TOKEN }}

- name: Build and push the image to ghcr.io
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
file: deployment/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
21 changes: 17 additions & 4 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# Stage 1: Build
FROM rust:1.68.1 AS chef
FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM rust:1.69.0 AS chef

ARG TARGETPLATFORM
RUN cargo install cargo-chef
WORKDIR /build/

COPY --from=xx / /

# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends \
lld \
clang \
libclang-dev \
protobuf-compiler \
&& xx-apt-get update \
&& xx-apt-get install -y libc6-dev g++ binutils \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*


FROM chef as planner
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
COPY . .
Expand All @@ -20,15 +29,19 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
COPY --from=planner /build/recipe.json recipe.json

# Build our project dependecies, not our application!
RUN cargo chef cook --release --no-default-features --features "production" -p fuel-core-bin --recipe-path recipe.json
RUN xx-cargo chef cook --release --no-default-features --features "production" -p fuel-core-bin --recipe-path recipe.json
# Up to this point, if our dependency tree stays the same,
# all layers should be cached.
COPY . .
RUN cargo build --release --no-default-features --features "production" -p fuel-core-bin
RUN xx-cargo build --release --no-default-features --features "production" -p fuel-core-bin \
&& xx-verify ./target/$(xx-cargo --print-target-triple)/release/fuel-core \
&& mv ./target/$(xx-cargo --print-target-triple)/release/fuel-core ./target/release/fuel-core \
&& mv ./target/$(xx-cargo --print-target-triple)/release/fuel-core.d ./target/release/fuel-core.d

# Stage 2: Run
FROM ubuntu:22.04 as run
FROM --platform=$BUILDPLATFORM ubuntu:22.04 as run

ARG IP=0.0.0.0
ARG PORT=4000
Expand Down

0 comments on commit 8fff229

Please sign in to comment.