multiarch

This commit is contained in:
Kwitsch 2022-09-14 20:58:17 +02:00
parent b3d9d661dc
commit e634a1c6fc
3 changed files with 12 additions and 34 deletions

View File

@ -58,28 +58,6 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Prepare project
shell: bash
run: |
go mod tidy
go mod download
go generate ./...
go mod vendor -v
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

View File

@ -1,5 +1,10 @@
# prepare build environment
FROM golang:1-alpine AS build-env
FROM --platform=$BUILDPLATFORM golang:1-alpine AS build-env
ARG VERSION
ARG BUILD_TIME
ARG TARGETOS
ARG TARGETARCH
# add blocky user
RUN adduser -S -D -H -h /app -s /sbin/nologin blocky
@ -21,11 +26,6 @@ RUN apk add --no-cache \
ca-certificates \
libcap
# build blocky
FROM build-env AS build
ARG VERSION
ARG BUILD_TIME
# setup environment
ENV CGO_ENABLED=0
@ -34,12 +34,15 @@ WORKDIR /go/src
# add source
ADD . .
RUN go generate ./...
# build binary
RUN --mount=type=cache,target=/root/.cache/go-build,sharing=locked \
GOCACHE=/root/.cache/go-build/${BUILDPLATFORM} \
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=$TARGETOS \
GOARCH=$TARGETARCH \
go build \
-mod=vendor \
-tags static \
-v \
-ldflags="-linkmode external -extldflags -static -X github.com/0xERR0R/blocky/util.Version=${VERSION} -X github.com/0xERR0R/blocky/util.BuildTime=${BUILD_TIME}" \

View File

@ -45,10 +45,7 @@ fmt: ## gofmt and goimports all go files
find . -name '*.go' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done
docker-build: ## Build docker image
go generate ./...
go mod vendor -v
docker buildx build -o type=docker --build-arg VERSION=${VERSION} --build-arg BUILD_TIME=${BUILD_TIME} --network=host -t ${DOCKER_IMAGE_NAME} .
rm -R vendor
help: ## Shows help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'