git.iko.soy/typeable/oauth2-proxy
on master help sign in
chore(build): retrieve go version from go.mod as single point of truth
commit58527ec6c96bd99673cc8ddb6b1a4909df637b6c authorJan Larwig <jan@larwig.com> dateFri 17 Jan 2025, 17:56 (2 years ago) parent4c823a6
6 files changed+25−21
.github/workflows/ci.yaml → .github/workflows/ci.yml+1−2 .github/workflows/codeql.yml−9 .github/workflows/docs.yaml → .github/workflows/docs.yml .github/workflows/labeler.yaml → .github/workflows/labeler.yml Dockerfile+16−6 Makefile+8−4
.github/workflows/ci.yaml → .github/workflows/ci.ymlrenamed+1−2
@@ -19,8 +19,7 @@ jobs:
1919 - name: Set up Go
2020 uses: actions/setup-go@v5
2121 with:
22− # renovate: datasource=golang-version depName=golang
23− go-version: 1.23.4
22+ go-version-file: go.mod
2423 id: go
2524
2625 - name: Get dependencies
.github/workflows/codeql.yml−9
@@ -33,15 +33,6 @@ jobs:
3333 steps:
3434 - name: Checkout repository
3535 uses: actions/checkout@v4
36− with:
37− # We must fetch at least the immediate parents so that if this is
38− # a pull request then we can checkout the head.
39− fetch-depth: 2
40−
41− # If this run was triggered by a pull request event, then checkout
42− # the head of the pull request instead of the merge commit.
43− - run: git checkout HEAD^2
44− if: ${{ github.event_name == 'pull_request' }}
4536
4637 # Initializes the CodeQL tools for scanning.
4738 - name: Initialize CodeQL
.github/workflows/docs.yaml → .github/workflows/docs.ymlrenamed

The content is the same.

.github/workflows/labeler.yaml → .github/workflows/labeler.ymlrenamed

The content is the same.

Dockerfile+16−6
@@ -1,13 +1,18 @@
1−# This ARG has to be at the top, otherwise the docker daemon does not known what to do with FROM ${RUNTIME_IMAGE}
2−ARG RUNTIME_IMAGE=gcr.io/distroless/static:nonroot
3−# version is shared between mutiple buildstages
1+# The image ARGs have to be at the top, otherwise the docker daemon cannot validate
2+# the FROM statements and overall Dockerfile
3+#
4+# Argument for setting the build image
5+ARG BUILD_IMAGE=placeholder
6+# Argument for setting the runtime image
7+ARG RUNTIME_IMAGE=placeholder
8+# Argument for setting the oauth2-proxy build version
49ARG VERSION
510
611# All builds should be done using the platform native to the build node to allow
712# cache sharing of the go mod download step.
813# Go cross compilation is also faster than emulation the go compilation across
914# multiple platforms.
10−FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.22-bookworm AS builder
15+FROM --platform=${BUILDPLATFORM} ${BUILD_IMAGE} AS builder
1116
1217# Copy sources
1318WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
@@ -19,10 +24,12 @@ RUN go mod download
1924# Now pull in our code
2025COPY . .
2126
22−# Arguments go here so that the previous steps can be cached if no external
23−# sources have changed.
27+# Arguments go here so that the previous steps can be cached if no external sources
28+# have changed. These arguments are automatically set by the docker engine.
2429ARG TARGETPLATFORM
2530ARG BUILDPLATFORM
31+
32+# Reload version argument
2633ARG VERSION
2734
2835# Build binary and make sure there is at least an empty key file.
@@ -46,8 +53,11 @@ RUN case ${TARGETPLATFORM} in \
4653 printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
4754 GOARCH=${GOARCH} VERSION=${VERSION} make build && touch jwt_signing_key.pem
4855
56+# Reload runtime image
57+ARG RUNTIME_IMAGE
4958# Copy binary to runtime image
5059FROM ${RUNTIME_IMAGE}
60+# Reload version
5161ARG VERSION
5262
5363COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/oauth2-proxy /bin/oauth2-proxy
Makefile+8−4
@@ -12,8 +12,10 @@ DATE := $(shell date +"%Y%m%d")
1212
1313GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
1414GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
15−MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
16−MINIMUM_SUPPORTED_GO_MINOR_VERSION = 20
15+
16+GO_MOD_VERSION = $(shell sed -En 's/^go ([[:digit:]]\.[[:digit:]]+)\.[[:digit:]]+/\1/p' go.mod)
17+MINIMUM_SUPPORTED_GO_MAJOR_VERSION = $(shell echo ${GO_MOD_VERSION} | cut -d' ' -f1 | cut -d'.' -f1)
18+MINIMUM_SUPPORTED_GO_MINOR_VERSION = $(shell echo ${GO_MOD_VERSION} | cut -d' ' -f1 | cut -d'.' -f2)
1719GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
1820
1921ifeq ($(COVER),true)
@@ -42,9 +44,11 @@ build: validate-go-version clean $(BINARY)
4244$(BINARY):
4345 CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X github.com/oauth2-proxy/oauth2-proxy/v7/pkg/version.VERSION=${VERSION}" -o $@ github.com/oauth2-proxy/oauth2-proxy/v7
4446
47+DOCKER_BUILDX_COMMON_ARGS ?= --build-arg BUILD_IMAGE=docker.io/library/golang:${GO_MOD_VERSION}-bookworm --build-arg VERSION=${VERSION}
48+
4549DOCKER_BUILD_PLATFORM ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v7,linux/s390x
4650DOCKER_BUILD_RUNTIME_IMAGE ?= gcr.io/distroless/static:nonroot
47−DOCKER_BUILDX_ARGS ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE} --build-arg VERSION=${VERSION}
51+DOCKER_BUILDX_ARGS ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE} ${DOCKER_BUILDX_COMMON_ARGS}
4852DOCKER_BUILDX := docker buildx build ${DOCKER_BUILDX_ARGS} --pull
4953DOCKER_BUILDX_X_PLATFORM := $(DOCKER_BUILDX) --platform ${DOCKER_BUILD_PLATFORM}
5054DOCKER_BUILDX_PUSH := $(DOCKER_BUILDX) --push
@@ -52,7 +56,7 @@ DOCKER_BUILDX_PUSH_X_PLATFORM := $(DOCKER_BUILDX_PUSH) --platform ${DOCKER_BUILD
5256
5357DOCKER_BUILD_PLATFORM_ALPINE ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v6,linux/arm/v7,linux/s390x
5458DOCKER_BUILD_RUNTIME_IMAGE_ALPINE ?= alpine:3.21.2
55−DOCKER_BUILDX_ARGS_ALPINE ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE_ALPINE} --build-arg VERSION=${VERSION}
59+DOCKER_BUILDX_ARGS_ALPINE ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE_ALPINE} ${DOCKER_BUILDX_COMMON_ARGS}
5660DOCKER_BUILDX_X_PLATFORM_ALPINE := docker buildx build ${DOCKER_BUILDX_ARGS_ALPINE} --platform ${DOCKER_BUILD_PLATFORM_ALPINE}
5761DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE := $(DOCKER_BUILDX_X_PLATFORM_ALPINE) --push
5862