Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: switch to go cross compilation #586

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
ARG DOCKER_GEN_VERSION=main

# Build docker-gen from scratch
FROM golang:1.20.12-alpine as go-builder
FROM --platform=$BUILDPLATFORM golang:1.20.12-alpine as go-builder

ENV CGO_ENABLED=0

ARG DOCKER_GEN_VERSION TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH VARIANT=$TARGETVARIANT

ARG DOCKER_GEN_VERSION
WORKDIR /build

# Install the dependencies
COPY . .
RUN go mod download

# Build the docker-gen executable
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" -o docker-gen ./cmd/docker-gen

FROM alpine:3.19.0
RUN set -eux; \
case "$GOARCH" in \
arm) export GOARM="${VARIANT#v}" ;; \
amd64) export GOAMD64="$VARIANT" ;; \
*) [ -z "$VARIANT" ] ;; \
esac; \
go env | grep -E 'OS=|ARCH=|ARM=|AMD64='; \
go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" -o docker-gen ./cmd/docker-gen

FROM --platform=$TARGETPLATFORM alpine:3.19.0

ARG DOCKER_GEN_VERSION
ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} \
Expand Down
22 changes: 16 additions & 6 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ARG DOCKER_GEN_VERSION=main

# Build docker-gen from scratch
FROM golang:1.20.12 as go-builder
FROM --platform=$BUILDPLATFORM golang:1.20.12 as go-builder

ARG DOCKER_GEN_VERSION
ENV CGO_ENABLED=0

ARG DOCKER_GEN_VERSION TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH VARIANT=$TARGETVARIANT

WORKDIR /build

Expand All @@ -12,12 +15,19 @@ COPY . .
RUN go mod download

# Build the docker-gen executable
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" -o docker-gen ./cmd/docker-gen
RUN set -eux; \
case "$GOARCH" in \
arm) export GOARM="${VARIANT#v}" ;; \
amd64) export GOAMD64="$VARIANT" ;; \
*) [ -z "$VARIANT" ] ;; \
esac; \
go env | grep -E 'OS=|ARCH=|ARM=|AMD64='; \
go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" -o docker-gen ./cmd/docker-gen

FROM debian:12.4-slim
FROM --platform=$TARGETPLATFORM debian:12.4-slim

ARG VERSION
ENV DOCKER_GEN_VERSION=${VERSION} \
ARG DOCKER_GEN_VERSION
ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} \
DOCKER_HOST=unix:///tmp/docker.sock

# Install packages required by the image
Expand Down