Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: ⎈ Release Version

on:
pull_request:
branches:
- main
push:
tags:
- v**
Expand All @@ -17,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: 📦 Cargo version
id: cargo
Expand Down Expand Up @@ -60,7 +63,12 @@ jobs:
- name: 🏷 Get tag
id: tag
run: |
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
if [ "${{ github.event_name }}" -eq "push" ]
then
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
else
echo "tag=ci-${{ github.run_number }}" >> "$GITHUB_OUTPUT"
fi

- name: 🐳 Login to DockerHub
uses: docker/login-action@v3
Expand All @@ -81,15 +89,16 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
build-args: BASE_IMAGE=platzio/base:v6
push: true
build-args: BASE_IMAGE=platzio/base:v7
push: ${{ github.event_name == 'push' }}
platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_REPO }}:${{ steps.tag.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max

release:
name: 🚀 Create Release
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- image
Expand Down
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
ARG BASE_IMAGE

FROM --platform=$BUILDPLATFORM rust:1 AS build
FROM rust:1-trixie AS builder
RUN apt-get update && \
apt-get install -y \
musl \
musl-dev \
musl-tools

FROM builder AS build
ARG RELEASE_BUILD=1
ARG TARGETARCH
WORKDIR /build
RUN mkdir -p /build/outputs
COPY . /build
RUN --mount=type=cache,id=platz-backend-cargo-target,target=/build/target,sharing=locked \
--mount=type=cache,id=platz-backend-cargo-git,target=/usr/local/cargo/git,sharing=locked \
--mount=type=cache,id=platz-backend-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \
./scripts/container-build.sh "${TARGETARCH}" "${RELEASE_BUILD}" "/build/outputs"
./scripts/container-build.sh "${RELEASE_BUILD}" "/build/outputs"

FROM $BASE_IMAGE

Check warning on line 20 in Dockerfile

View workflow job for this annotation

GitHub Actions / 🐳 Publish Image

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG $BASE_IMAGE results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/
WORKDIR /root/
COPY --from=build /build/outputs/* /root/
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"
services:
db:
image: postgres:15
image: postgres:17-alpine
environment:
POSTGRES_PASSWORD: postgres
ports:
Expand All @@ -16,7 +16,7 @@ services:
build:
context: .
args:
BASE_IMAGE: platzio/base:v6
BASE_IMAGE: platzio/base:v7
RELEASE_BUILD: 0
command:
- /root/platz-api
Expand Down
49 changes: 4 additions & 45 deletions scripts/container-build.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
#!/usr/bin/env bash

set -eu
set -o pipefail
set -euo pipefail

TARGETARCH="$1"
RELEASE_BUILD="$2"
BUILD_DEST="$3"

case "$TARGETARCH" in \
arm64)
LINUX_TARGETARCH="aarch64"
;;
amd64)
LINUX_TARGETARCH="x86_64"
;;
*)
echo "Unknown arch $TARGETARCH"
exit 1
;;
esac

dpkg --add-architecture "${TARGETARCH}"

if [ "${LINUX_TARGETARCH}" != `uname -m` ]
then
apt-get install -y "gcc-`echo ${LINUX_TARGETARCH} | tr '_' '-'`-linux-gnu"
fi

cat >"${CARGO_HOME}/config.toml" <<EOF
[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
EOF

export CC_x86_64_unknown_linux_gnu="x86_64-linux-gnu-gcc"
export CXX_x86_64_unknown_linux_gnu="x86_64-linux-gnu-g++"
export AR_x86_64_unknown_linux_gnu="x86_64-linux-gnu-ar"

export CC_aarch64_unknown_linux_gnu="aarch64-linux-gnu-gcc"
export CXX_aarch64_unknown_linux_gnu="aarch64-linux-gnu-g++"
export AR_aarch64_unknown_linux_gnu="aarch64-linux-gnu-ar"

export LDFLAGS="-L/usr/lib/${LINUX_TARGETARCH}-linux-gnu"
export CARGO_BUILD_TARGET="${LINUX_TARGETARCH}-unknown-linux-gnu"
RELEASE_BUILD="$1"
BUILD_DEST="$2"

export CARGO_BUILD_TARGET="$(arch)-unknown-linux-musl"
rustup target add "${CARGO_BUILD_TARGET}"

if [ "${RELEASE_BUILD}" = "1" ]
Expand All @@ -58,5 +18,4 @@ else
fi

cargo build ${CARGO_FLAGS}

find "${CARGO_TARGET_DIR}" -maxdepth 1 -type f -executable -exec cp -v {} "${BUILD_DEST}/" \;