From 28d225952a3fffaaeaddb56cef2e45b522970b40 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Sat, 26 Aug 2023 15:34:25 +0100 Subject: [PATCH] chore: add separate debug Docker build script --- Cargo.toml | 3 -- Dockerfile.useCurrentArch | 28 ++++++++++++++++++ scripts/build-image-layer.sh | 52 ++++++++++++++++++++++------------ scripts/publish-debug-image.sh | 19 +++++++++++++ 4 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 Dockerfile.useCurrentArch create mode 100644 scripts/publish-debug-image.sh diff --git a/Cargo.toml b/Cargo.toml index 36f24bb1..43356e46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,3 @@ members = ["crates/delta", "crates/bonfire", "crates/quark", "crates/core/*"] # mobc-redis = { git = "https://github.com/insertish/mobc", rev = "8b880bb59f2ba80b4c7bc40c649c113d8857a186" } redis22 = { package = "redis", version = "0.22.3", git = "https://github.com/revoltchat/redis-rs", rev = "1a41faf356fd21aebba71cea7eb7eb2653e5f0ef" } redis23 = { package = "redis", version = "0.23.1", git = "https://github.com/revoltchat/redis-rs", rev = "f8ca28ab85da59d2ccde526b4d2fb390eff5a5f9" } - -[profile.release] -debug = true diff --git a/Dockerfile.useCurrentArch b/Dockerfile.useCurrentArch new file mode 100644 index 00000000..4f903dd7 --- /dev/null +++ b/Dockerfile.useCurrentArch @@ -0,0 +1,28 @@ +# Build Stage +FROM rust:1.70.0-slim +USER 0:0 +WORKDIR /home/rust/src + +# Install build requirements +RUN apt-get update && \ + apt-get install -y \ + make \ + pkg-config \ + libssl-dev +COPY scripts/build-image-layer.sh /tmp/ + +# Build all dependencies +COPY Cargo.toml Cargo.lock ./ +COPY crates/bonfire/Cargo.toml ./crates/bonfire/ +COPY crates/delta/Cargo.toml ./crates/delta/ +COPY crates/quark/Cargo.toml ./crates/quark/ +COPY crates/core/database/Cargo.toml ./crates/core/database/ +COPY crates/core/models/Cargo.toml ./crates/core/models/ +COPY crates/core/permissions/Cargo.toml ./crates/core/permissions/ +COPY crates/core/presence/Cargo.toml ./crates/core/presence/ +COPY crates/core/result/Cargo.toml ./crates/core/result/ +RUN sh /tmp/build-image-layer.sh deps + +# Build all apps +COPY crates ./crates +RUN sh /tmp/build-image-layer.sh apps diff --git a/scripts/build-image-layer.sh b/scripts/build-image-layer.sh index bc59adbd..84e6c284 100644 --- a/scripts/build-image-layer.sh +++ b/scripts/build-image-layer.sh @@ -1,17 +1,19 @@ #!/bin/sh -set -eu - -case "${TARGETARCH}" in - "amd64") - LINKER_NAME="x86_64-linux-gnu-gcc" - LINKER_PACKAGE="gcc-x86-64-linux-gnu" - BUILD_TARGET="x86_64-unknown-linux-gnu" ;; - "arm64") - LINKER_NAME="aarch64-linux-gnu-gcc" - LINKER_PACKAGE="gcc-aarch64-linux-gnu" - BUILD_TARGET="aarch64-unknown-linux-gnu" ;; -esac +if [ -z "$TARGETARCH" ]; then + : +else + case "${TARGETARCH}" in + "amd64") + LINKER_NAME="x86_64-linux-gnu-gcc" + LINKER_PACKAGE="gcc-x86-64-linux-gnu" + BUILD_TARGET="x86_64-unknown-linux-gnu" ;; + "arm64") + LINKER_NAME="aarch64-linux-gnu-gcc" + LINKER_PACKAGE="gcc-aarch64-linux-gnu" + BUILD_TARGET="aarch64-unknown-linux-gnu" ;; + esac +fi tools() { apt-get install -y "${LINKER_PACKAGE}" @@ -38,7 +40,12 @@ deps() { tee crates/core/permissions/src/lib.rs | tee crates/core/presence/src/lib.rs | tee crates/core/result/src/lib.rs - cargo build --locked --release --target "${BUILD_TARGET}" + + if [ -z "$TARGETARCH" ]; then + cargo build --locked --release + else + cargo build --locked --release --target "${BUILD_TARGET}" + fi } apps() { @@ -51,12 +58,21 @@ apps() { crates/core/permissions/src/lib.rs \ crates/core/presence/src/lib.rs \ crates/core/result/src/lib.rs - cargo build --locked --release --target "${BUILD_TARGET}" - mv target _target && mv _target/"${BUILD_TARGET}" target + + if [ -z "$TARGETARCH" ]; then + cargo build --locked --release + else + cargo build --locked --release --target "${BUILD_TARGET}" + mv target _target && mv _target/"${BUILD_TARGET}" target + fi } -export RUSTFLAGS="-C linker=${LINKER_NAME}" -export PKG_CONFIG_ALLOW_CROSS="1" -export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig" +if [ -z "$TARGETARCH" ]; then + : +else + export RUSTFLAGS="-C linker=${LINKER_NAME}" + export PKG_CONFIG_ALLOW_CROSS="1" + export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig" +fi "$@" diff --git a/scripts/publish-debug-image.sh b/scripts/publish-debug-image.sh new file mode 100644 index 00000000..9c361f50 --- /dev/null +++ b/scripts/publish-debug-image.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Check if an argument was provided +if [ "$#" -eq 0 ]; then + echo "No arguments provided" + echo "Usage: scripts/build-current-arch.sh 20230826-1" + exit 1 +fi + +echo "[profile.release]" >> Cargo.toml +echo "debug = true" >> Cargo.toml + +TAG=$1-debug +echo "Building images, will tag for ghcr.io with $TAG-debug!" +docker build -t ghcr.io/revoltchat/base:latest -f Dockerfile.useCurrentArch . +docker build -t ghcr.io/revoltchat/server:$TAG - < crates/delta/Dockerfile +docker build -t ghcr.io/revoltchat/bonfire:$TAG - < crates/bonfire/Dockerfile + +git restore Cargo.toml