4# Makefile with some common workflow for dev, build and test
9# The help target prints out all targets with their descriptions organized
10# beneath their categories. The categories are represented by '##@' and the
11# target descriptions by '##'. The awk command is responsible for reading the
12# entire set of makefiles included in this invocation, looking for lines of the
13# file as xyz: ## something, and then pretty-format the target and help. Then,
14# if there's a line with ##@ something, that gets pretty-printed as a category.
15# More info on the usage of ANSI control characters for terminal formatting:
16# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
17# More info on the awk command:
18# http://linuxcommand.org/lc3_adv_awk.php
20# The following help command is Licensed under the Apache License, Version 2.0 (the "License")
21# Copyright 2023 The Kubernetes Authors.
23help: ## Display this help
24 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
28# renovate: datasource=github-tags depName=golangci/golangci-lint
29GOLANGCILINT_VERSION ?= v2.11.4
32VERSION ?= $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
33# Allow to override image registry.
34REGISTRY ?= quay.io/oauth2-proxy
35REPOSITORY ?= oauth2-proxy
37DATE := $(shell date +"%Y%m%d")
40# The go version in go.mod used for the Docker build toolchain, without the patch
41GO_MOD_VERSION_MINOR := $(shell $(GO) list -f '{{printf "%.4s" .Module.GoVersion}}' )
43# From go1.21 go will transparently download the toolchain declared in go.mod. https://go.dev/doc/toolchain
44# We don't need to keep this message updated: the important info is in go.mod.
45GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least go1.21
48TESTCOVER ?= -coverprofile c.out
54build: validate-go-version clean $(BINARY) ## Build and create oauth2-proxy binary from current source code
57 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
59DOCKER_BUILDX_COMMON_ARGS ?= --build-arg BUILD_IMAGE=docker.io/library/golang:$(GO_MOD_VERSION_MINOR)-bookworm --build-arg VERSION=$(VERSION)
61DOCKER_BUILD_PLATFORM ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v7,linux/s390x
62DOCKER_BUILD_RUNTIME_IMAGE ?= gcr.io/distroless/static:nonroot
63DOCKER_BUILDX_ARGS ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE} ${DOCKER_BUILDX_COMMON_ARGS}
64DOCKER_BUILDX := docker buildx build ${DOCKER_BUILDX_ARGS} --pull
65DOCKER_BUILDX_X_PLATFORM := $(DOCKER_BUILDX) --platform ${DOCKER_BUILD_PLATFORM}
66DOCKER_BUILDX_PUSH := $(DOCKER_BUILDX) --push
67DOCKER_BUILDX_PUSH_X_PLATFORM := $(DOCKER_BUILDX_PUSH) --platform ${DOCKER_BUILD_PLATFORM}
69DOCKER_BUILD_PLATFORM_ALPINE ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v6,linux/arm/v7,linux/s390x
70DOCKER_BUILD_RUNTIME_IMAGE_ALPINE ?= alpine:3.24.1
71DOCKER_BUILDX_ARGS_ALPINE ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD_RUNTIME_IMAGE_ALPINE} ${DOCKER_BUILDX_COMMON_ARGS}
72DOCKER_BUILDX_X_PLATFORM_ALPINE := docker buildx build ${DOCKER_BUILDX_ARGS_ALPINE} --platform ${DOCKER_BUILD_PLATFORM_ALPINE}
73DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE := $(DOCKER_BUILDX_X_PLATFORM_ALPINE) --push
76build-docker: build-distroless build-alpine ## Build multi architecture docker images in both flavours (distroless / alpine)
78.PHONY: build-docker-local
79build-docker-local: ## Build distroless docker image and locally load into docker images
80 $(DOCKER_BUILDX) --load -t $(REGISTRY)/$(REPOSITORY):${VERSION}-local .
82.PHONY: build-distroless
83build-distroless: ## Build multi architecture distroless based docker image
84 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
87build-alpine: ## Build multi architecture alpine based docker image
88 $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
90.PHONY: build-docker-all
91build-docker-all: build-docker ## Build docker images for all supported architectures in both flavours (distroless / alpine)
92 $(DOCKER_BUILDX) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
93 $(DOCKER_BUILDX) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
94 $(DOCKER_BUILDX) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
95 $(DOCKER_BUILDX) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
96 $(DOCKER_BUILDX) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
102push-docker: push-distroless push-alpine ## Push multi architecture docker images for both flavours (distroless / alpine)
104.PHONY: push-distroless
105push-distroless: ## Push multi architecture distroless based docker image
106 $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
109push-alpine: ## Push multi architecture alpine based docker image
110 $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
112.PHONY: push-docker-all
113push-docker-all: push-docker ## Push docker images for all supported architectures for both flavours (distroless / alpine)
114 $(DOCKER_BUILDX_PUSH) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
115 $(DOCKER_BUILDX_PUSH) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
116 $(DOCKER_BUILDX_PUSH) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
117 $(DOCKER_BUILDX_PUSH) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
118 $(DOCKER_BUILDX_PUSH) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
121##@ Nightly scheduling
124nightly-build: ## Nightly build command for docker images in both flavours (distroless / alpine)
125 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
126 $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
129nightly-push: ## Nightly push command for docker images in both flavours (distroless / alpine)
130 $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
131 $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
137generate: ## Generate alpha config docs from golang structs
138 go generate ./pkg/...
140.PHONY: verify-generate
141verify-generate: generate ## Verify command to check if alpha config docs are in line with golang struct changes
147test: ## Run all Go tests
148 GO111MODULE=on $(GO) test $(TESTCOVER) -v -race ./...
151release: validate-go-version ## Create a full release for all architectures (binaries and checksums)
152 BINARY=${BINARY} VERSION=${VERSION} ./dist.sh
155clean: ## Cleanup release and build files
160lint: validate-go-version ## Lint all files using golangci-lint
161 GO111MODULE=on $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCILINT_VERSION) run --timeout 10m
164lint-fix: validate-go-version ## Lint all files and apply fixes using golangci-lint
165 GO111MODULE=on $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCILINT_VERSION) run --timeout 10m --fix
167.PHONY: validate-go-version
168validate-go-version: ## Validate Go environment requirements
169 @$(GO) list . >/dev/null || { echo '$(GO_VERSION_VALIDATION_ERR_MSG)'; exit 1; }
171# local-env can be used to interact with the local development environment
173# make local-env-up # Bring up a basic test environment
174# make local-env-down # Tear down the basic test environment
175# make local-env-nginx-up # Bring up an nginx based test environment
176# make local-env-nginx-down # Tead down the nginx based test environment
179 make -C contrib/local-environment $*
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list