git.iko.soy/typeable/oauth2-proxy
on 7b41c8e help sign in
179 lines 9.1 kB history raw
1#!/usr/bin/env bash
3#
4# Makefile with some common workflow for dev, build and test
5#
7##@ General
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.
22.PHONY: help
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)
27GO ?= go
28GOLANGCILINT ?= golangci-lint
30BINARY := oauth2-proxy
31VERSION ?= $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
32# Allow to override image registry.
33REGISTRY ?= quay.io/oauth2-proxy
34REPOSITORY ?= oauth2-proxy
36DATE := $(shell date +"%Y%m%d")
37.NOTPARALLEL:
39GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
40GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
42GO_MOD_VERSION = $(shell sed -En 's/^go ([[:digit:]]\.[[:digit:]]+)\.[[:digit:]]+/\1/p' go.mod)
43MINIMUM_SUPPORTED_GO_MAJOR_VERSION = $(shell echo ${GO_MOD_VERSION} | cut -d' ' -f1 | cut -d'.' -f1)
44MINIMUM_SUPPORTED_GO_MINOR_VERSION = $(shell echo ${GO_MOD_VERSION} | cut -d' ' -f1 | cut -d'.' -f2)
45GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
47ifeq ($(COVER),true)
48TESTCOVER ?= -coverprofile c.out
49endif
51##@ Build
53.PHONY: build
54build: validate-go-version clean $(BINARY) ## Build and create oauth2-proxy binary from current source code
56$(BINARY):
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}-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.21.3
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
75.PHONY: build-docker
76build-docker: build-distroless build-alpine ## Build multi architecture docker images in both flavours (distroless / alpine)
78.PHONY: build-distroless
79build-distroless: ## Build multi architecture distroless based docker image
80 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
82.PHONY: build-alpine
83build-alpine: ## Build multi architecture alpine based docker image
84 $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
86.PHONY: build-docker-all
87build-docker-all: build-docker ## Build docker images for all supported architectures in both flavours (distroless / alpine)
88 $(DOCKER_BUILDX) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
89 $(DOCKER_BUILDX) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
90 $(DOCKER_BUILDX) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
91 $(DOCKER_BUILDX) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
92 $(DOCKER_BUILDX) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
95##@ Publish
97.PHONY: push-docker
98push-docker: push-distroless push-alpine ## Push multi architecture docker images for both flavours (distroless / alpine)
100.PHONY: push-distroless
101push-distroless: ## Push multi architecture distroless based docker image
102 $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
104.PHONY: push-alpine
105push-alpine: ## Push multi architecture alpine based docker image
106 $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
108.PHONY: push-docker-all
109push-docker-all: push-docker ## Push docker images for all supported architectures for both flavours (distroless / alpine)
110 $(DOCKER_BUILDX_PUSH) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
111 $(DOCKER_BUILDX_PUSH) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
112 $(DOCKER_BUILDX_PUSH) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
113 $(DOCKER_BUILDX_PUSH) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
114 $(DOCKER_BUILDX_PUSH) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
117##@ Nightly scheduling
119.PHONY: nightly-build
120nightly-build: ## Nightly build command for docker images in both flavours (distroless / alpine)
121 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
122 $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
124.PHONY: nightly-push
125nightly-push: ## Nightly push command for docker images in both flavours (distroless / alpine)
126 $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
127 $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
130##@ Docs
132.PHONY: generate
133generate: ## Generate alpha config docs from golang structs
134 go generate ./pkg/...
136.PHONY: verify-generate
137verify-generate: generate ## Verify command to check if alpha config docs are in line with golang struct changes
138 git diff --exit-code
140##@ Miscellaneous
142.PHONY: test
143test: lint ## Run all Go tests
144 GO111MODULE=on $(GO) test $(TESTCOVER) -v -race ./...
146.PHONY: release
147release: validate-go-version lint test ## Create a full release for all architectures (binaries and checksums)
148 BINARY=${BINARY} VERSION=${VERSION} ./dist.sh
150.PHONY: clean
151clean: ## Cleanup release and build files
152 -rm -rf release
153 -rm -f $(BINARY)
155.PHONY: lint
156lint: validate-go-version ## Lint all files using golangci-lint
157 GO111MODULE=on $(GOLANGCILINT) run
159.PHONY: validate-go-version
160validate-go-version: ## Validate Go environment requirements
161 @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
162 exit 0 ;\
163 elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
164 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
165 exit 1; \
166 elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
167 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
168 exit 1; \
169 fi
171# local-env can be used to interact with the local development environment
172# eg:
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
177.PHONY: local-env-%
178local-env-%:
179 make -C contrib/local-environment $*