Reverting to older non-multi-arch dockerfile. Fixes #2832 (#2833)

This commit is contained in:
Dessalines 2023-04-25 16:40:58 -04:00 committed by GitHub
parent a25faf3e97
commit 17527d0e7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,52 +1,34 @@
# FIXME: use "--platform=$BUILDPLATFORM" and solve openssl cross-compile issue FROM clux/muslrust:1.67.0 as builder
FROM rust:1.67.0-alpine as builder
# Install build dependencies
RUN apk add --no-cache git openssl-dev libpq-dev musl-dev
# Set the working directory to /app and copy the source code
WORKDIR /app WORKDIR /app
COPY . . ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
# Set the target architecture (can be set using --build-arg), buildx set it automatically
ARG TARGETARCH
# This can be set to release using --build-arg # This can be set to release using --build-arg
ARG RUST_RELEASE_MODE="debug" ARG RUST_RELEASE_MODE="debug"
# Prepare toolchain COPY . .
# Docker and Rust use different architecture naming schemas, so we have to convert them
RUN case $TARGETARCH in \ # Build the project
arm64) RUSTARCH=aarch64 ;; \
amd64) RUSTARCH=x86_64 ;; \
*) echo "unsupported architecture: $TARGETARCH"; exit 3 ;; \
esac \
&& echo "RUSTARCH=$RUSTARCH" >> .buildenv
# Debug mode build # Debug mode build
RUN --mount=type=cache,target=/app/target \ RUN --mount=type=cache,target=/app/target \
if [ "$RUST_RELEASE_MODE" = "debug" ]; then \ if [ "$RUST_RELEASE_MODE" = "debug" ] ; then \
source .buildenv \ echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
&& echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \ && cargo build --target ${CARGO_BUILD_TARGET} \
&& rustup target add ${RUSTARCH}-unknown-linux-musl \ && cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
&& cargo build --target ${RUSTARCH}-unknown-linux-musl \
&& cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
fi fi
# Release mode build # Release mode build
RUN \ RUN \
if [ "$RUST_RELEASE_MODE" = "release" ]; then \ if [ "$RUST_RELEASE_MODE" = "release" ] ; then \
source .buildenv \ cargo build --target ${CARGO_BUILD_TARGET} --release \
&& rustup target add ${RUSTARCH}-unknown-linux-musl \ && cp ./target/$CARGO_BUILD_TARGET/$RUST_RELEASE_MODE/lemmy_server /app/lemmy_server; \
&& cargo build --target ${RUSTARCH}-unknown-linux-musl --release \
&& cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
fi fi
# The Alpine runner # The alpine runner
FROM alpine:3 as lemmy FROM alpine:3 as lemmy
# Install libpq for Postgres # Install libpq for postgres
RUN apk add --no-cache ca-certificates libpq RUN apk add libpq
# Copy resources # Copy resources
COPY --from=builder /app/lemmy_server /app/lemmy COPY --from=builder /app/lemmy_server /app/lemmy