mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 14:42:30 +00:00
Another attempt for cross-platform Docker images
This commit is contained in:
9
.github/workflows/docker-publish.yml
vendored
9
.github/workflows/docker-publish.yml
vendored
@@ -14,6 +14,13 @@ jobs:
|
|||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -49,7 +56,7 @@ jobs:
|
|||||||
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: ${{ matrix.platform }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ repository.workspace = true
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
debug = 0
|
debug = 0
|
||||||
|
|
||||||
|
|||||||
22
Dockerfile
22
Dockerfile
@@ -1,6 +1,18 @@
|
|||||||
FROM rust:1.84-alpine AS chef
|
FROM --platform=$BUILDPLATFORM rust:1.84-alpine AS chef
|
||||||
RUN apk add --no-cache musl-dev \
|
|
||||||
&& rustup target add x86_64-unknown-linux-musl \
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
|
||||||
|
# Stupid workaound with tempfiles since environment variables
|
||||||
|
# from RUN commands don't persist across stages
|
||||||
|
RUN case $TARGETPLATFORM in \
|
||||||
|
"linux/amd64") echo x86_64-unknown-linux-musl > /tmp/rust_target;; \
|
||||||
|
"linux/arm64") echo aarch64-unknown-linux-musl > /tmp/rust_target;; \
|
||||||
|
*) echo "Unsupported platform ${TARGETPLATFORM}"; exit 1;; \
|
||||||
|
esac
|
||||||
|
|
||||||
|
RUN apk add --no-cache musl-dev gcc \
|
||||||
|
&& rustup target add "$(cat /tmp/rust_target)" \
|
||||||
&& cargo install cargo-chef --locked \
|
&& cargo install cargo-chef --locked \
|
||||||
&& rm -rf "$CARGO_HOME/registry"
|
&& rm -rf "$CARGO_HOME/registry"
|
||||||
|
|
||||||
@@ -16,10 +28,10 @@ FROM chef AS builder
|
|||||||
# x86_64-unknown-linux-musl does static linking by default
|
# x86_64-unknown-linux-musl does static linking by default
|
||||||
WORKDIR /rustical
|
WORKDIR /rustical
|
||||||
COPY --from=planner /rustical/recipe.json recipe.json
|
COPY --from=planner /rustical/recipe.json recipe.json
|
||||||
RUN cargo chef cook --release --target x86_64-unknown-linux-musl
|
RUN cargo chef cook --release --target "$(cat /tmp/rust_target)"
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN --mount=type=cache,target=target cargo install --target x86_64-unknown-linux-musl --path .
|
RUN --mount=type=cache,target=target cargo install --target $TARGET --path .
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical
|
COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical
|
||||||
|
|||||||
Reference in New Issue
Block a user