diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f83806 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/target +/.env diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index edf897e..9687900 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index b4f7d0e..3256785 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 +ARG TARGET="x86_64-unknown-linux-musl" +FROM --platform=$TARGETPLATFORM alpine AS alpine-amd64 +ARG TARGET="x86_64-unknown-linux-musl" -WORKDIR /eve +FROM --platform=$TARGETPLATFORM messense/rust-musl-cross:aarch64-musl AS base-arm64 +ARG TARGET="aarch64-unknown-linux-musl" +FROM --platform=$TARGETPLATFORM alpine AS alpine-arm64 +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 -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 @@ -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"]