CI: Faster builds with buildx and xcputranslate
This commit is contained in:
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -7,7 +7,7 @@ Contributions are [released](https://help.github.com/articles/github-terms-of-se
|
|||||||
1. [Fork](https://github.com/qdm12/gluetun/fork) and clone the repository
|
1. [Fork](https://github.com/qdm12/gluetun/fork) and clone the repository
|
||||||
1. Create a new branch `git checkout -b my-branch-name`
|
1. Create a new branch `git checkout -b my-branch-name`
|
||||||
1. Modify the code
|
1. Modify the code
|
||||||
1. Ensure the docker build succeeds `docker build .`
|
1. Ensure the docker build succeeds `docker build .` (you might need `export DOCKER_BUILDKIT=1`)
|
||||||
1. Commit your modifications
|
1. Commit your modifications
|
||||||
1. Push to your fork and [submit a pull request](https://github.com/qdm12/gluetun/compare)
|
1. Push to your fork and [submit a pull request](https://github.com/qdm12/gluetun/compare)
|
||||||
|
|
||||||
|
|||||||
14
Dockerfile
14
Dockerfile
@@ -1,7 +1,7 @@
|
|||||||
ARG ALPINE_VERSION=3.12
|
ARG ALPINE_VERSION=3.12
|
||||||
ARG GO_VERSION=1.15
|
ARG GO_VERSION=1.15
|
||||||
|
|
||||||
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
|
||||||
RUN apk --update add git
|
RUN apk --update add git
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
WORKDIR /tmp/gobuild
|
WORKDIR /tmp/gobuild
|
||||||
@@ -10,25 +10,29 @@ RUN go mod download
|
|||||||
COPY cmd/ ./cmd/
|
COPY cmd/ ./cmd/
|
||||||
COPY internal/ ./internal/
|
COPY internal/ ./internal/
|
||||||
|
|
||||||
FROM base AS test
|
FROM --platform=$BUILDPLATFORM base AS test
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
RUN apk --update add g++
|
RUN apk --update add g++
|
||||||
RUN go test -race ./...
|
RUN go test -race ./...
|
||||||
|
|
||||||
FROM base AS lint
|
FROM --platform=$BUILDPLATFORM base AS lint
|
||||||
ARG GOLANGCI_LINT_VERSION=v1.34.1
|
ARG GOLANGCI_LINT_VERSION=v1.34.1
|
||||||
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
|
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
|
||||||
sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}
|
sh -s -- -b /usr/local/bin ${GOLANGCI_LINT_VERSION}
|
||||||
COPY .golangci.yml ./
|
COPY .golangci.yml ./
|
||||||
RUN golangci-lint run --timeout=10m
|
RUN golangci-lint run --timeout=10m
|
||||||
|
|
||||||
FROM base AS build
|
FROM --platform=$BUILDPLATFORM base AS build
|
||||||
|
COPY --from=qmcgaw/xcputranslate /xcputranslate /usr/local/bin/xcputranslate
|
||||||
|
ARG TARGETPLATFORM
|
||||||
ARG VERSION=unknown
|
ARG VERSION=unknown
|
||||||
ARG BUILD_DATE="an unknown date"
|
ARG BUILD_DATE="an unknown date"
|
||||||
ARG COMMIT=unknown
|
ARG COMMIT=unknown
|
||||||
COPY cmd/ ./cmd/
|
COPY cmd/ ./cmd/
|
||||||
COPY internal/ ./internal/
|
COPY internal/ ./internal/
|
||||||
RUN go build -trimpath -ldflags="-s -w \
|
RUN GOARCH="$(echo ${TARGETPLATFORM} | xcputranslate -field arch)" \
|
||||||
|
GOARM="$(echo ${TARGETPLATFORM} | xcputranslate -field arm)" \
|
||||||
|
go build -trimpath -ldflags="-s -w \
|
||||||
-X 'main.version=$VERSION' \
|
-X 'main.version=$VERSION' \
|
||||||
-X 'main.buildDate=$BUILD_DATE' \
|
-X 'main.buildDate=$BUILD_DATE' \
|
||||||
-X 'main.commit=$COMMIT' \
|
-X 'main.commit=$COMMIT' \
|
||||||
|
|||||||
Reference in New Issue
Block a user