Skip to content

Commit

Permalink
fix: properly docker build on amd64 and arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
GiyoMoon committed Aug 13, 2024
1 parent 95b87ef commit 8a029cd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/.env
28 changes: 20 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
JAVA_URL=https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u372-b07/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u372b07.tar.gz
JAVA_JDK=jdk8u372-b07
JAVA_URL_amd64=https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u422-b05/OpenJDK8U-jdk_x64_alpine-linux_hotspot_8u422b05.tar.gz
JAVA_URL_arm64=https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u422-b05/OpenJDK8U-jdk_aarch64_linux_hotspot_8u422b05.tar.gz
JAVA_JDK=jdk8u422-b05
cache-from: type=gha
cache-to: type=gha,mode=max

build-java11:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -87,8 +90,11 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
JAVA_URL=https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.19%2B7/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.19_7.tar.gz
JAVA_JDK=jdk-11.0.19+7
JAVA_URL_amd64=https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.24%2B8/OpenJDK11U-jdk_x64_alpine-linux_hotspot_11.0.24_8.tar.gz
JAVA_URL_arm64=https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.24%2B8/OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.24_8.tar.gz
JAVA_JDK=jdk-11.0.24+8
cache-from: type=gha
cache-to: type=gha,mode=max

build-java17:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -129,8 +135,11 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
JAVA_URL=https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/OpenJDK17U-jdk_x64_alpine-linux_hotspot_17.0.7_7.tar.gz
JAVA_JDK=jdk-17.0.7+7
JAVA_URL_amd64=https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_x64_alpine-linux_hotspot_17.0.9_9.tar.gz
JAVA_URL_arm64=https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.9%2B9/OpenJDK17U-jdk_aarch64_linux_hotspot_17.0.9_9.tar.gz
JAVA_JDK=jdk-17.0.9+9
cache-from: type=gha
cache-to: type=gha,mode=max

build-java21:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -171,6 +180,9 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
JAVA_URL=https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.3%2B9/OpenJDK21U-jdk_x64_alpine-linux_hotspot_21.0.3_9.tar.gz
JAVA_JDK=jdk-21.0.3+9
JAVA_URL_amd64=https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4%2B7/OpenJDK21U-jdk_x64_alpine-linux_hotspot_21.0.4_7.tar.gz
JAVA_URL_arm64=https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4%2B7/OpenJDK21U-jdk_aarch64_alpine-linux_hotspot_21.0.4_7.tar.gz
JAVA_JDK=jdk-21.0.4+7
cache-from: type=gha
cache-to: type=gha,mode=max

60 changes: 43 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
FROM messense/rust-musl-cross:x86_64-musl as builder
FROM --platform=$TARGETPLATFORM messense/rust-musl-cross:x86_64-musl AS base-amd64

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java21

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java17

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java8

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java11

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
ARG TARGET="x86_64-unknown-linux-musl"
FROM --platform=$TARGETPLATFORM alpine AS alpine-amd64

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java21

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java17

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java8

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java11

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
ARG TARGET="x86_64-unknown-linux-musl"

WORKDIR /eve
FROM --platform=$TARGETPLATFORM messense/rust-musl-cross:aarch64-musl AS base-arm64

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java21

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java17

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java8

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java11

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
ARG TARGET="aarch64-unknown-linux-musl"
FROM --platform=$TARGETPLATFORM alpine AS alpine-arm64

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java21

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java17

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java8

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java11

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
ARG TARGET="aarch64-unknown-linux-musl"

RUN rustup update nightly
RUN rustup target add --toolchain nightly x86_64-unknown-linux-musl
# ======================== SETUP RUST ========================
FROM base-$TARGETARCH AS base
WORKDIR /eve
RUN rustup update nightly && \
rustup target add --toolchain nightly $TARGET && \
rustup default nightly

# ======================== BUILD DEPS ========================
FROM base AS build-deps
COPY Cargo.lock .
COPY Cargo.toml .
COPY ./src ./src/
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -r ./src

# ======================== BUILD PROJECT ========================
FROM build-deps AS build
COPY src src
RUN touch src/main.rs
RUN cargo build --release && \
musl-strip ./target/$TARGET/release/eve

RUN cargo +nightly -Z sparse-registry build --release
RUN musl-strip ./target/x86_64-unknown-linux-musl/release/eve
# ======================== GET JAVA ========================
FROM alpine-$TARGETARCH as java

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java21

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java17

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java8

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-java11

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

FROM alpine as java
ARG TARGETARCH
ARG JAVA_URL_amd64
ARG JAVA_URL_arm64

ARG JAVA_URL
RUN cd ~/ && wget --no-check-certificate -O java_jdk.tar.gz -c $JAVA_URL
RUN mkdir /usr/lib/jvm
RUN cd /usr/lib/jvm && tar -xvzf ~/java_jdk.tar.gz
RUN if [ "$TARGETARCH" = "amd64" ]; then \
JAVA_URL=$JAVA_URL_amd64; \
elif [ "$TARGETARCH" = "arm64" ]; then \
JAVA_URL=$JAVA_URL_arm64; \
fi && \
cd ~/ && wget --no-check-certificate -O java_jdk.tar.gz -c $JAVA_URL

FROM alpine
RUN mkdir /usr/lib/jvm && \
tar -xvzf ~/java_jdk.tar.gz -C /usr/lib/jvm

# ======================== FINAL ========================
FROM alpine-$TARGETARCH

ENV TZ=Europe/Zurich

ARG JAVA_JDK

# Install java jdk
RUN apk add --no-cache dpkg
COPY --from=java /usr/lib/jvm/ /usr/lib/jvm/
RUN echo "PATH=\"/usr/lib/jvm/$JAVA_JDK/bin\"" > /etc/environment
Expand All @@ -36,9 +64,7 @@ RUN update-alternatives --set java /usr/lib/jvm/$JAVA_JDK/bin/java
RUN update-alternatives --set javac /usr/lib/jvm/$JAVA_JDK/bin/javac

USER 405

WORKDIR /eve

COPY --from=builder /eve/target/x86_64-unknown-linux-musl/release/eve ./
COPY --from=build /eve/target/$TARGET/release/eve ./

CMD ["./eve"]

0 comments on commit 8a029cd

Please sign in to comment.