mirror of
https://github.com/datarhei/core.git
synced 2025-09-27 04:16:25 +08:00
Fix cross-compile build
This commit is contained in:
20
Dockerfile
20
Dockerfile
@@ -1,23 +1,23 @@
|
|||||||
ARG GOLANG_IMAGE=golang:1.20-alpine3.16
|
ARG GOLANG_IMAGE=golang:1.22-alpine3.19
|
||||||
ARG BUILD_IMAGE=alpine:3.16
|
ARG BUILD_IMAGE=alpine:3.19
|
||||||
|
|
||||||
# Cross-Compilation
|
# Cross-Compilation
|
||||||
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
|
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
|
||||||
FROM --platform=$BUILDPLATFORM $GOLANG_IMAGE as builder
|
FROM --platform=$BUILDPLATFORM $GOLANG_IMAGE as builder
|
||||||
|
|
||||||
ARG TARGETOS TARGETARCH
|
ARG TARGETOS TARGETARCH TARGETVARIANT
|
||||||
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH
|
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$TARGETVARIANT
|
||||||
|
|
||||||
COPY . /dist/core
|
COPY . /dist/core
|
||||||
|
|
||||||
RUN apk add \
|
RUN apk add \
|
||||||
git \
|
git \
|
||||||
make && \
|
make
|
||||||
cd /dist/core && \
|
|
||||||
go version && \
|
RUN cd /dist/core && \
|
||||||
make release_linux && \
|
make release && \
|
||||||
make import_linux && \
|
make import && \
|
||||||
make ffmigrate_linux
|
make ffmigrate
|
||||||
|
|
||||||
FROM $BUILD_IMAGE
|
FROM $BUILD_IMAGE
|
||||||
|
|
||||||
|
26
Makefile
26
Makefile
@@ -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)
|
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")
|
BUILD := $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
|
||||||
BINSUFFIX := $(shell if [ "${GOOS}" -a "${GOARCH}" ]; then echo "-${GOOS}-${GOARCH}"; else echo ""; fi)
|
BINSUFFIX := $(shell if [ "${GOOS}" -a "${GOARCH}" ]; then echo "-${GOOS}-${GOARCH}"; else echo ""; fi)
|
||||||
|
GOARM := $(subst v,$e,$(GOARM))
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
@@ -15,11 +16,7 @@ init:
|
|||||||
|
|
||||||
## build: Build core (default)
|
## build: Build core (default)
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} go build -o core${BINSUFFIX} -trimpath
|
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -o core$(BINSUFFIX) -trimpath
|
||||||
|
|
||||||
# github workflow workaround
|
|
||||||
build_linux:
|
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o core -trimpath
|
|
||||||
|
|
||||||
## swagger: Update swagger API documentation (requires github.com/swaggo/swag)
|
## swagger: Update swagger API documentation (requires github.com/swaggo/swag)
|
||||||
swagger:
|
swagger:
|
||||||
@@ -69,19 +66,11 @@ lint:
|
|||||||
|
|
||||||
## import: Build import binary
|
## import: Build import binary
|
||||||
import:
|
import:
|
||||||
cd app/import && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} 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"
|
||||||
|
|
||||||
# github workflow workaround
|
|
||||||
import_linux:
|
|
||||||
cd app/import && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../import -trimpath -ldflags="-s -w"
|
|
||||||
|
|
||||||
## ffmigrate: Build ffmpeg migration binary
|
## ffmigrate: Build ffmpeg migration binary
|
||||||
ffmigrate:
|
ffmigrate:
|
||||||
cd app/ffmigrate && CGO_ENABLED=${CGO_ENABLED} GOOS=${GOOS} GOARCH=${GOARCH} 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"
|
||||||
|
|
||||||
# github workflow workaround
|
|
||||||
ffmigrate_linux:
|
|
||||||
cd app/ffmigrate && CGO_ENABLED=0 GOOS=linux GOARCH=${OSARCH} go build -o ../../ffmigrate -trimpath -ldflags="-s -w"
|
|
||||||
|
|
||||||
## coverage: Generate code coverage analysis
|
## coverage: Generate code coverage analysis
|
||||||
coverage:
|
coverage:
|
||||||
@@ -94,11 +83,10 @@ commit: vet fmt lint test build
|
|||||||
|
|
||||||
## release: Build a release binary of core
|
## release: Build a release binary of core
|
||||||
release:
|
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)"
|
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)"
|
||||||
|
|
||||||
# github workflow workaround
|
release2:
|
||||||
release_linux:
|
@echo "Hallo"
|
||||||
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)"
|
|
||||||
|
|
||||||
## docker: Build standard Docker image
|
## docker: Build standard Docker image
|
||||||
docker:
|
docker:
|
||||||
|
Reference in New Issue
Block a user