]> Untitled Git - lemmy.git/commitdiff
Use Dockerfile.multiarch as Dockerfile (#2818)
author6543 <6543@obermui.de>
Tue, 18 Apr 2023 20:21:31 +0000 (22:21 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Apr 2023 20:21:31 +0000 (22:21 +0200)
* use Dockerfile.multiarch and delete old Dockerfile

* Dockerfile.multiarch -> Dockerfile

* nit

.woodpecker.yml
CONTRIBUTING.md
docker/Dockerfile
docker/Dockerfile.multiarch [deleted file]

index 740614094c1a96761a8f01f7adc98ec4905cd9d0..e98659e37cbe4af8c00d17b5f709c8a54a342e85 100644 (file)
@@ -146,7 +146,7 @@ pipeline:
     image: woodpeckerci/plugin-docker-buildx
     settings:
       repo: dessalines/lemmy
-      dockerfile: docker/Dockerfile.multiarch
+      dockerfile: docker/Dockerfile
       platforms: linux/amd64
       build_args: RUST_RELEASE_MODE=release
       username:
@@ -164,7 +164,7 @@ pipeline:
     image: woodpeckerci/plugin-docker-buildx
     settings:
       repo: dessalines/lemmy
-      dockerfile: docker/Dockerfile.multiarch
+      dockerfile: docker/Dockerfile
       platforms: linux/amd64
       build_args: RUST_RELEASE_MODE=release
       username:
@@ -182,7 +182,7 @@ pipeline:
     image: woodpeckerci/plugin-docker-buildx
     settings:
       repo: dessalines/lemmy
-      dockerfile: docker/Dockerfile.multiarch
+      dockerfile: docker/Dockerfile
       platforms: linux/arm64
       build_args: RUST_RELEASE_MODE=release
       username:
index ef0ce6b46ff0cb6e873bb84f8592dee091114cd1..d13668bfa1b72354b78da59e5aebc4a265ea941e 100644 (file)
@@ -1,4 +1,3 @@
 # Contributing
 
 See [here](https://join-lemmy.org/docs/en/contributing/contributing.html) for contributing Instructions.
-
index c6df9f1c1892ee29f5ee8a8cda73ce6369de1215..6f793d4215326b72fbbe54b763dc80b32b3e4f8c 100644 (file)
@@ -1,3 +1,4 @@
+# FIXME: use "--platform=$BUILDPLATFORM" and solve openssl cross-compile issue
 FROM rust:1.67.0-alpine as builder
 
 # Install build dependencies
@@ -7,26 +8,38 @@ RUN apk add --no-cache git openssl-dev libpq-dev musl-dev
 WORKDIR /app
 COPY . .
 
-# Set cargo build target (can be changed using --build-arg)
-ARG CARGO_BUILD_TARGET="x86_64-unknown-linux-musl"
-# Set the release mode (can be changed using --build-arg)
+# 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
 ARG RUST_RELEASE_MODE="debug"
 
+# Prepare toolchain
+# Docker and Rust use different architecture naming schemas, so we have to convert them
+RUN case $TARGETARCH in \
+      arm64) RUSTARCH=aarch64 ;; \
+      amd64) RUSTARCH=x86_64 ;; \
+      *) echo "unsupported architecture: $TARGETARCH"; exit 3 ;; \
+    esac \
+ && echo "RUSTARCH=$RUSTARCH" >> .buildenv
+
 # Debug mode build
 RUN --mount=type=cache,target=/app/target \
     if [ "$RUST_RELEASE_MODE" = "debug" ]; then \
-      echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
-      && rustup target add ${CARGO_BUILD_TARGET} \
-      && cargo build --target ${CARGO_BUILD_TARGET} \
-      && cp ./target/${CARGO_BUILD_TARGET}/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
+      source .buildenv \
+      && echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
+      && rustup target add ${RUSTARCH}-unknown-linux-musl \
+      && cargo build --target ${RUSTARCH}-unknown-linux-musl \
+      && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
     fi
 
 # Release mode build
 RUN \
     if [ "$RUST_RELEASE_MODE" = "release" ]; then \
-      rustup target add ${CARGO_BUILD_TARGET} \
-      && cargo build --target ${CARGO_BUILD_TARGET} --release \
-      && cp ./target/${CARGO_BUILD_TARGET}/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
+      source .buildenv \
+      && rustup target add ${RUSTARCH}-unknown-linux-musl \
+      && cargo build --target ${RUSTARCH}-unknown-linux-musl --release \
+      && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
     fi
 
 # The Alpine runner
diff --git a/docker/Dockerfile.multiarch b/docker/Dockerfile.multiarch
deleted file mode 100644 (file)
index 6f793d4..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-# FIXME: use "--platform=$BUILDPLATFORM" and solve openssl cross-compile issue
-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
-COPY . .
-
-# 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
-ARG RUST_RELEASE_MODE="debug"
-
-# Prepare toolchain
-# Docker and Rust use different architecture naming schemas, so we have to convert them
-RUN case $TARGETARCH in \
-      arm64) RUSTARCH=aarch64 ;; \
-      amd64) RUSTARCH=x86_64 ;; \
-      *) echo "unsupported architecture: $TARGETARCH"; exit 3 ;; \
-    esac \
- && echo "RUSTARCH=$RUSTARCH" >> .buildenv
-
-# Debug mode build
-RUN --mount=type=cache,target=/app/target \
-    if [ "$RUST_RELEASE_MODE" = "debug" ]; then \
-      source .buildenv \
-      && echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs" \
-      && rustup target add ${RUSTARCH}-unknown-linux-musl \
-      && cargo build --target ${RUSTARCH}-unknown-linux-musl \
-      && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
-    fi
-
-# Release mode build
-RUN \
-    if [ "$RUST_RELEASE_MODE" = "release" ]; then \
-      source .buildenv \
-      && rustup target add ${RUSTARCH}-unknown-linux-musl \
-      && cargo build --target ${RUSTARCH}-unknown-linux-musl --release \
-      && cp ./target/${RUSTARCH}-unknown-linux-musl/${RUST_RELEASE_MODE}/lemmy_server /app/lemmy_server; \
-    fi
-
-# The Alpine runner
-FROM alpine:3 as lemmy
-
-# Install libpq for Postgres
-RUN apk add --no-cache ca-certificates libpq
-
-# Copy resources
-COPY --from=builder /app/lemmy_server /app/lemmy
-
-EXPOSE 8536
-CMD ["/app/lemmy"]