From 3062f58bd20d89d689de7d5aaa721f9560b391a2 Mon Sep 17 00:00:00 2001 From: Veirt Date: Mon, 5 Aug 2024 15:28:16 +0800 Subject: [PATCH] ci: dockerfile with conditional --- .github/workflows/build.yml | 18 +++--------------- Dockerfile.aarch64 => Dockerfile | 22 ++++++++++++---------- Dockerfile.x86_64 | 28 ---------------------------- docker/installer/linux/arm64.sh | 9 +++++++++ docker/installer/linux/x86_64.sh | 7 +++++++ 5 files changed, 31 insertions(+), 53 deletions(-) rename Dockerfile.aarch64 => Dockerfile (62%) delete mode 100644 Dockerfile.x86_64 create mode 100755 docker/installer/linux/arm64.sh create mode 100755 docker/installer/linux/x86_64.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58bf1c0..cd2b977 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,26 +46,14 @@ jobs: type=semver,pattern={{major}}.{{minor}} type=sha - - name: Build and push x86_64 + - name: Build and push uses: docker/build-push-action@v6 with: context: . - file: Dockerfile.x86_64 + file: Dockerfile push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} - platforms: linux/amd64 - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build and push aarch64 - uses: docker/build-push-action@v6 - with: - context: . - file: Dockerfile.aarch64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - platforms: linux/arm64 + platforms: linux/amd64,linux/arm64 labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile.aarch64 b/Dockerfile similarity index 62% rename from Dockerfile.aarch64 rename to Dockerfile index 5cca25a..fcd608f 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile @@ -2,35 +2,37 @@ FROM --platform=$BUILDPLATFORM oven/bun:1-alpine AS css-builder WORKDIR /temp COPY package.json bun.lockb ./ RUN bun install --frozen-lockfile - COPY gridPlugin.js tailwind.config.js ./ COPY src ./src RUN bunx tailwindcss -i ./src/style.css -o ./out.css --minify FROM --platform=$BUILDPLATFORM rust:1.80 AS build -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install --no-install-recommends -y \ musl-tools \ - gcc-aarch64-linux-gnu \ && rm -rf /var/lib/apt/lists/* -RUN rustup target add aarch64-unknown-linux-musl - -ENV CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc \ - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc +RUN rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl +RUN apt-get update && apt-get install --no-install-recommends -y \ + gcc-aarch64-linux-gnu \ + && rm -rf /var/lib/apt/lists/* +# Set up the build environment WORKDIR /usr/src RUN USER=root cargo new --bin vesta WORKDIR /usr/src/vesta COPY Cargo.toml Cargo.lock ./ COPY src ./src -RUN cargo build --release --target=aarch64-unknown-linux-musl -FROM scratch +COPY docker/installer/linux . +RUN "./$TARGETPLATFORM.sh" +FROM scratch WORKDIR /app COPY ./static static COPY --from=css-builder /temp/out.css ./static/style.css -COPY --from=build /usr/src/vesta/target/aarch64-unknown-linux-musl/release/vesta /app/vesta + +COPY --from=build /usr/src/vesta/vesta /app/vesta + CMD ["/app/vesta"] diff --git a/Dockerfile.x86_64 b/Dockerfile.x86_64 deleted file mode 100644 index d8d33f0..0000000 --- a/Dockerfile.x86_64 +++ /dev/null @@ -1,28 +0,0 @@ -FROM oven/bun:1-alpine AS css-builder -WORKDIR /temp -COPY package.json bun.lockb ./ -RUN bun install --frozen-lockfile - -COPY gridPlugin.js tailwind.config.js ./ -COPY src ./src -RUN bunx tailwindcss -i ./src/style.css -o ./out.css --minify - -FROM rust:1.80-alpine AS build - -RUN apk add --no-cache musl-dev - -WORKDIR /usr/src -RUN USER=root cargo new --bin vesta -WORKDIR /usr/src/vesta -COPY Cargo.toml Cargo.lock ./ -COPY src ./src -RUN cargo build --release - -FROM scratch - -WORKDIR /app -COPY ./static static -COPY --from=css-builder /temp/out.css ./static/style.css -COPY --from=build /usr/src/vesta/target/release/vesta /app/vesta - -CMD ["/app/vesta"] diff --git a/docker/installer/linux/arm64.sh b/docker/installer/linux/arm64.sh new file mode 100755 index 0000000..128b336 --- /dev/null +++ b/docker/installer/linux/arm64.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +set -eu + +export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc +export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc +cargo build --release --target=aarch64-unknown-linux-musl + +cp target/aarch64-unknown-linux-musl/release/vesta . diff --git a/docker/installer/linux/x86_64.sh b/docker/installer/linux/x86_64.sh new file mode 100755 index 0000000..88abe88 --- /dev/null +++ b/docker/installer/linux/x86_64.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +set -eu + +cargo build --release --target=x86_64-unknown-linux-musl + +cp target/x86_64-unknown-linux-musl/release/vesta .