Enable cross compilation

This commit is contained in:
Ingo Oppermann 2024-04-08 09:37:37 +02:00
parent 7c3bc983a9
commit 29848ab9df
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
3 changed files with 28 additions and 35 deletions

View File

@ -1,19 +1,23 @@
ARG GOLANG_IMAGE=golang:1.20-alpine3.16
ARG GOLANG_IMAGE=golang:1.22-alpine3.19
ARG BUILD_IMAGE=alpine:3.19
ARG BUILD_IMAGE=alpine:3.16
# Cross-Compilation
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
FROM --platform=$BUILDPLATFORM $GOLANG_IMAGE as builder
FROM $GOLANG_IMAGE as builder
ARG TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$TARGETVARIANT
COPY . /dist/core
RUN apk add \
git \
make && \
cd /dist/core && \
go version && \
make release_linux && \
make import_linux && \
make ffmigrate_linux
make
RUN cd /dist/core && \
make release && \
make import && \
make ffmigrate
FROM $BUILD_IMAGE

View File

@ -3,6 +3,7 @@ SHORTCOMMIT := $(shell echo $(COMMIT) | head -c 7)
BRANCH := $(shell if [ -d .git ]; then git rev-parse --abbrev-ref HEAD; else echo "master"; fi)
BUILD := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
BINSUFFIX := $(shell if [ "${GOOS}" -a "${GOARCH}" ]; then echo "-${GOOS}-${GOARCH}"; else echo ""; fi)
GOARM := $(subst v,$e,$(GOARM))
all: build
@ -15,11 +16,7 @@ init:
## build: Build core (default)
build:
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o core${BINSUFFIX} -trimpath
# github workflow workaround
build_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o core -trimpath
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -o core$(BINSUFFIX) -trimpath
## swagger: Update swagger API documentation (requires github.com/swaggo/swag)
swagger:
@ -70,19 +67,11 @@ lint:
## import: Build import binary
import:
cd app/import && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ../../import -trimpath -ldflags="-s -w"
# github workflow workaround
import_linux:
cd app/import && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../import -trimpath -ldflags="-s -w"
cd app/import && CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o ../../import -trimpath -ldflags="-s -w"
## ffmigrate: Build ffmpeg migration binary
ffmigrate:
cd app/ffmigrate && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o ../../ffmigrate -trimpath -ldflags="-s -w"
# github workflow workaround
ffmigrate_linux:
cd app/ffmigrate && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../ffmigrate -trimpath -ldflags="-s -w"
cd app/ffmigrate && CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o ../../ffmigrate -trimpath -ldflags="-s -w"
## coverage: Generate code coverage analysis
coverage:
@ -95,11 +84,7 @@ commit: vet fmt lint test vulncheck build
## release: Build a release binary of core
release:
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o core -trimpath -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
# github workflow workaround
release_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o core -trimpath -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=$(GOARM) go build -o core -trimpath -ldflags="-s -w -X github.com/datarhei/core/v16/app.Commit=$(COMMIT) -X github.com/datarhei/core/v16/app.Branch=$(BRANCH) -X github.com/datarhei/core/v16/app.Build=$(BUILD)"
## docker: Build standard Docker image
docker:

16
run.sh
View File

@ -3,18 +3,22 @@
# First run the import program. It will read the db.dir from the config file in order to
# find an old v1.json. This will be converted to the new db format.
./bin/import
if [ $? -ne 0 ]; then
exit 1
if [ -x ./bin/import ]; then
./bin/import
if [ $? -ne 0 ]; then
exit 1
fi
fi
# Run the FFmpeg migration program. In case a FFmpeg 5 binary is present, it will create a
# backup of the current DB and modify the FFmpeg parameter such that they are compatible
# with FFmpeg 5.
./bin/ffmigrate
if [ $? -ne 0 ]; then
exit 1
if [ -x ./bin/ffmigrate ]; then
./bin/ffmigrate
if [ $? -ne 0 ]; then
exit 1
fi
fi
# Now run the core with the possibly converted configuration.