Skip to content

Commit

Permalink
Fix build pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Oct 16, 2024
1 parent ce9abd8 commit 3a1f880
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
- if: startsWith(github.ref, 'refs/tags/v')
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
- if: startsWith(github.ref, 'refs/tags/v')
name: Set up QEMU
uses: docker/setup-qemu-action@v2
- if: startsWith(github.ref, 'refs/tags/v')
run: |
export LD_FLAGS="-w -s -X main.Version=$VERSION -X main.BuildDate=$(date "+%F-%T") -X main.Commit=$(git rev-parse --verify HEAD) -X main.Mode=prod"
Expand Down
42 changes: 17 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DOCKER_BUILD_IMAGE=gotify/build
DOCKER_WORKDIR=/proj
DOCKER_RUN=docker run --rm -v "$$PWD/.:${DOCKER_WORKDIR}" -v "`go env GOPATH`/pkg/mod/.:/go/pkg/mod:ro" -w ${DOCKER_WORKDIR}
DOCKER_GO_BUILD=go build -mod=readonly -a -installsuffix cgo -ldflags "$$LD_FLAGS"
DOCKER_TEST_LEVEL ?= 1 # should be unnecessary but good for a last-line of defense
NODE_OPTIONS=$(shell if node --help | grep -q -- "--openssl-legacy-provider"; then echo --openssl-legacy-provider; fi)

test: test-coverage test-js
Expand Down Expand Up @@ -64,7 +65,8 @@ package-zip: extract-licenses
done

build-docker-multiarch: require-version
docker buildx build --sbom=true \
docker buildx build --sbom=true --provenance=true \
--output type=local,dest=container-out \
-t gotify/server:latest \
-t gotify/server:${VERSION} \
-t gotify/server:$(shell echo $(VERSION) | cut -d '.' -f -2) \
Expand All @@ -81,45 +83,35 @@ build-docker-multiarch: require-version
-t ghcr.io/gotify/server-arm64:${VERSION} \
-t ghcr.io/gotify/server-arm64:$(shell echo $(VERSION) | cut -d '.' -f -2) \
-t ghcr.io/gotify/server-arm64:$(shell echo $(VERSION) | cut -d '.' -f -1) \
--build-arg GO_VERSION=$(shell cat GO_VERSION) \
--platform linux/amd64,linux/arm64,linux/386 \
-f docker/Dockerfile .

build-docker-amd64: build-docker-multiarch

build-docker-i386: build-docker-multiarch

build-docker-arm64: build-docker-multiarch

build-docker-arm-7: require-version
cp ${BUILD_DIR}/gotify-linux-arm-7 ./docker/gotify-app
cd ${DOCKER_DIR} && \
docker build -f Dockerfile.armv7 \
-t gotify/server-arm7:latest \
-t gotify/server-arm7:${VERSION} \
-t gotify/server-arm7:$(shell echo $(VERSION) | cut -d '.' -f -2) \
-t gotify/server-arm7:$(shell echo $(VERSION) | cut -d '.' -f -1) \
-t ghcr.io/gotify/server-arm7:latest \
-t ghcr.io/gotify/server-arm7:${VERSION} \
-t ghcr.io/gotify/server-arm7:$(shell echo $(VERSION) | cut -d '.' -f -2) \
-t ghcr.io/gotify/server-arm7:$(shell echo $(VERSION) | cut -d '.' -f -1) .
rm ${DOCKER_DIR}gotify-app

build-docker-riscv64: require-version
cp ${BUILD_DIR}/gotify-linux-riscv64 ./docker/gotify-app
cd ${DOCKER_DIR} && \
docker build -f Dockerfile.riscv64 \
-t ghcr.io/gotify/server-arm7:$(shell echo $(VERSION) | cut -d '.' -f -1) \
-t gotify/server-riscv64:latest \
-t gotify/server-riscv64:${VERSION} \
-t gotify/server-riscv64:$(shell echo $(VERSION) | cut -d '.' -f -2) \
-t gotify/server-riscv64:$(shell echo $(VERSION) | cut -d '.' -f -1) \
-t ghcr.io/gotify/server-riscv64:latest \
-t ghcr.io/gotify/server-riscv64:${VERSION} \
-t ghcr.io/gotify/server-riscv64:$(shell echo $(VERSION) | cut -d '.' -f -2) \
-t ghcr.io/gotify/server-riscv64:$(shell echo $(VERSION) | cut -d '.' -f -1) .
rm ${DOCKER_DIR}gotify-app
-t ghcr.io/gotify/server-riscv64:$(shell echo $(VERSION) | cut -d '.' -f -1) \
--build-arg RUN_TESTS=$(DOCKER_TEST_LEVEL) \
--build-arg GO_VERSION=$(shell cat GO_VERSION) \
--platform linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/riscv64 \
-f docker/Dockerfile .

# Backwards compatibility
build-docker-amd64: build-docker-multiarch
build-docker-i386: build-docker-multiarch
build-docker-arm64: build-docker-multiarch
build-docker-arm-7: build-docker-multiarch
build-docker-riscv64: build-docker-multiarch

build-docker: build-docker-multiarch build-docker-arm-7 build-docker-riscv64
build-docker: build-docker-multiarch

build-js:
(cd ui && NODE_OPTIONS="${NODE_OPTIONS}" yarn build)
Expand Down
25 changes: 20 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
ARG DEBIAN=stable-slim
# supprress warnung about invalid variable expansion
ARG BUILDKIT_SBOM_SCAN_CONTEXT=true
ARG DEBIAN_STABLE_ARCH=stable-slim
ARG DEBIAN_EXPERIMENTAL_ARCH=sid-slim
# suppress warnung about invalid variable expansion
ARG GO_VERSION=PLEASE_PROVIDE_GO_VERSION

# Hack to normalize platform to match the chosed build image
# Get the gotify/build image tag
ARG __TARGETPLATFORM_DASHES=${TARGETPLATFORM/\//-}
ARG __TARGETPLATFORM_GO_NOTATION=${__TARGETPLATFORM_DASHES/arm\/v7/arm-7}
# Set the unstable tag if the target platform is not stable
ARG __TARGETPLATFORM_IS_STABLE=${TARGETPLATFORM/linux\/riscv64/}
ARG __DEBIAN_HAS_STABLE_TAG=${__TARGETPLATFORM_IS_STABLE/?*/${DEBIAN}} # if the last variable is not empty, set it to the debian stable tag
ARG DEBIAN=${__DEBIAN_HAS_STABLE_TAG:-${DEBIAN_EXPERIMENTAL_ARCH}} # else set it to the debian experimental tag

# --- JS Builder ---

FROM --platform=${BUILDPLATFORM} debian:${DEBIAN} AS js-builder
Expand Down Expand Up @@ -37,10 +48,12 @@ RUN if [ "$BUILD_JS" = "1" ]; then \

# --- Go Builder ---

FROM --platform=${BUILDPLATFORM} gotify/build:${GO_VERSION}-${TARGETPLATFORM/\//-} AS builder
FROM --platform=${BUILDPLATFORM} gotify/build:${GO_VERSION}-${__TARGETPLATFORM_GO_NOTATION} AS builder

ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG BUILD_JS=0
ARG RUN_TESTS=0
ARG RUN_TESTS=0 # 0=never, 1=native only
ARG GO_BUILD_FLAGS=-mod=readonly -a -installsuffix cgo
ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -57,7 +70,9 @@ RUN if [ "$BUILD_JS" = "1" ]; then \

RUN cd /src/gotify && \
mkdir -p /target/app && \
[ "$RUN_TESTS" = "1" ] && go test -v ./... || true && \
if [ "$RUN_TESTS" = "1" ] && [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then \
go test -v ./...; \
fi && \
go build ${GO_BUILD_FLAGS} -o /target/app/gotify-app

FROM debian:${DEBIAN}
Expand Down

0 comments on commit 3a1f880

Please sign in to comment.