git.iko.soy/typeable/oauth2-proxy
on master help sign in
chore(build): refactoring makefile for better usability and introducing a default help target (#2930)
commit367183d7b8d82be2fba2722c79e469cafdec1418 authorJan Larwig <jan@larwig.com> dateSun 27 Apr 2025, 20:09 (1 year ago) parent4237358
8 files changed+121−55
.github/workflows/ci.yml+2−2 .github/workflows/nightly.yml+2−2 .github/workflows/publish-release.yml+2−2 Makefile+80−36 README.md+1−1 RELEASE.md+2−2 docs/docs/community/contribution.md+16−5 docs/versioned_docs/version-7.8.x/community/contribution.md+16−5
.github/workflows/ci.yml+2−2
@@ -72,10 +72,10 @@ jobs:
7272 - name: Docker Build
7373 if: (!startsWith(github.head_ref, 'release'))
7474 run: |
75− make docker
75+ make build-docker
7676
7777 # For release testing
7878 - name: Docker Build All
7979 if: github.base_ref == 'master' && startsWith(github.head_ref, 'release')
8080 run: |
81− make docker-all
81+ make build-docker-all
.github/workflows/nightly.yml+2−2
@@ -34,8 +34,8 @@ jobs:
3434
3535 - name: Build images
3636 run: |
37− make docker-nightly-build
37+ make nightly-build
3838
3939 - name: Push images
4040 run: |
41− make docker-nightly-push
41+ make nightly-push
.github/workflows/publish-release.yml+2−2
@@ -122,8 +122,8 @@ jobs:
122122
123123 - name: Build images
124124 run: |
125− make docker-all
125+ make build-docker-all
126126
127127 - name: Push images
128128 run: |
129− make docker-push-all
129+ make push-docker-all
Makefile+80−36
@@ -1,3 +1,29 @@
1+#!/usr/bin/env bash
2+
3+#
4+# Makefile with some common workflow for dev, build and test
5+#
6+
7+##@ General
8+
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
19+
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
23+help: ## 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)
25+
26+
127GO ?= go
228GOLANGCILINT ?= golangci-lint
329
@@ -22,24 +48,10 @@ ifeq ($(COVER),true)
2248TESTCOVER ?= -coverprofile c.out
2349endif
2450
25−.PHONY: all
26−all: lint $(BINARY)
27−
28−.PHONY: clean
29−clean:
30− -rm -rf release
31− -rm -f $(BINARY)
32−
33−.PHONY: distclean
34−distclean: clean
35− rm -rf vendor
36−
37−.PHONY: lint
38−lint: validate-go-version
39− GO111MODULE=on $(GOLANGCILINT) run
51+##@ Build
4052
4153.PHONY: build
42−build: validate-go-version clean $(BINARY)
54+build: validate-go-version clean $(BINARY) ## Build and create oauth2-proxy binary from current source code
4355
4456$(BINARY):
4557 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
@@ -60,60 +72,92 @@ DOCKER_BUILDX_ARGS_ALPINE ?= --build-arg RUNTIME_IMAGE=${DOCKER_BUILD
6072DOCKER_BUILDX_X_PLATFORM_ALPINE := docker buildx build ${DOCKER_BUILDX_ARGS_ALPINE} --platform ${DOCKER_BUILD_PLATFORM_ALPINE}
6173DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE := $(DOCKER_BUILDX_X_PLATFORM_ALPINE) --push
6274
63−.PHONY: docker
64−docker:
75+.PHONY: build-docker
76+build-docker: build-distroless build-alpine ## Build multi architecture docker images in both flavours (distroless / alpine)
77+
78+.PHONY: build-distroless
79+build-distroless: ## Build multi architecture distroless based docker image
6580 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
66− $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
6781
68−.PHONY: docker-push
69−docker-push:
70− $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
71− $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
82+.PHONY: build-alpine
83+build-alpine: ## Build multi architecture alpine based docker image
84+ $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t $(REGISTRY)/$(REPOSITORY):latest-alpine -t $(REGISTRY)/$(REPOSITORY):${VERSION}-alpine .
7285
73−.PHONY: docker-all
74−docker-all: docker
86+.PHONY: build-docker-all
87+build-docker-all: build-docker ## Build docker images for all supported architectures in both flavours (distroless / alpine)
7588 $(DOCKER_BUILDX) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
7689 $(DOCKER_BUILDX) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
7790 $(DOCKER_BUILDX) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
7891 $(DOCKER_BUILDX) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
7992 $(DOCKER_BUILDX) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
8093
81−.PHONY: docker-push-all
82−docker-push-all: docker-push
94+
95+##@ Publish
96+
97+.PHONY: push-docker
98+push-docker: push-distroless push-alpine ## Push multi architecture docker images for both flavours (distroless / alpine)
99+
100+.PHONY: push-distroless
101+push-distroless: ## Push multi architecture distroless based docker image
102+ $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY):latest -t $(REGISTRY)/$(REPOSITORY):${VERSION} .
103+
104+.PHONY: push-alpine
105+push-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 .
107+
108+.PHONY: push-docker-all
109+push-docker-all: push-docker ## Push docker images for all supported architectures for both flavours (distroless / alpine)
83110 $(DOCKER_BUILDX_PUSH) --platform linux/amd64 -t $(REGISTRY)/$(REPOSITORY):latest-amd64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-amd64 .
84111 $(DOCKER_BUILDX_PUSH) --platform linux/arm64 -t $(REGISTRY)/$(REPOSITORY):latest-arm64 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-arm64 .
85112 $(DOCKER_BUILDX_PUSH) --platform linux/ppc64le -t $(REGISTRY)/$(REPOSITORY):latest-ppc64le -t $(REGISTRY)/$(REPOSITORY):${VERSION}-ppc64le .
86113 $(DOCKER_BUILDX_PUSH) --platform linux/arm/v7 -t $(REGISTRY)/$(REPOSITORY):latest-armv7 -t $(REGISTRY)/$(REPOSITORY):${VERSION}-armv7 .
87114 $(DOCKER_BUILDX_PUSH) --platform linux/s390x -t $(REGISTRY)/$(REPOSITORY):latest-s390x -t $(REGISTRY)/$(REPOSITORY):${VERSION}-s390x .
88115
89−.PHONY: docker-nightly-build
90−docker-nightly-build:
116+
117+##@ Nightly scheduling
118+
119+.PHONY: nightly-build
120+nightly-build: ## Nightly build command for docker images in both flavours (distroless / alpine)
91121 $(DOCKER_BUILDX_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
92122 $(DOCKER_BUILDX_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
93123
94−.PHONY: docker-nightly-push
95−docker-nightly-push:
124+.PHONY: nightly-push
125+nightly-push: ## Nightly push command for docker images in both flavours (distroless / alpine)
96126 $(DOCKER_BUILDX_PUSH_X_PLATFORM) -t $(REGISTRY)/$(REPOSITORY)-nightly:latest -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE} .
97127 $(DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t ${REGISTRY}/$(REPOSITORY)-nightly:latest-alpine -t $(REGISTRY)/$(REPOSITORY)-nightly:${DATE}-alpine .
98128
129+
130+##@ Docs
131+
99132.PHONY: generate
100−generate:
133+generate: ## Generate alpha config docs from golang structs
101134 go generate ./pkg/...
102135
103136.PHONY: verify-generate
104−verify-generate: generate
137+verify-generate: generate ## Verify command to check if alpha config docs are in line with golang struct changes
105138 git diff --exit-code
106139
140+##@ Miscellaneous
141+
107142.PHONY: test
108−test: lint
143+test: lint ## Run all Go tests
109144 GO111MODULE=on $(GO) test $(TESTCOVER) -v -race ./...
110145
111146.PHONY: release
112−release: validate-go-version lint test
147+release: validate-go-version lint test ## Create a full release for all architectures (binaries and checksums)
113148 BINARY=${BINARY} VERSION=${VERSION} ./dist.sh
114149
150+.PHONY: clean
151+clean: ## Cleanup release and build files
152+ -rm -rf release
153+ -rm -f $(BINARY)
154+
155+.PHONY: lint
156+lint: validate-go-version ## Lint all files using golangci-lint
157+ GO111MODULE=on $(GOLANGCILINT) run
158+
115159.PHONY: validate-go-version
116−validate-go-version:
160+validate-go-version: ## Validate Go environment requirements
117161 @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
118162 exit 0 ;\
119163 elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
README.md+1−1
@@ -1,4 +1,4 @@
1−[![Continuous Integration](https://github.com/oauth2-proxy/oauth2-proxy/actions/workflows/ci.yaml/badge.svg)](https://github.com/oauth2-proxy/oauth2-proxy/actions/workflows/ci.yaml)
1+[![Continuous Integration](https://github.com/oauth2-proxy/oauth2-proxy/actions/workflows/ci.yml/badge.svg)](https://github.com/oauth2-proxy/oauth2-proxy/actions/workflows/ci.yml)
22[![Go Report Card](https://goreportcard.com/badge/github.com/oauth2-proxy/oauth2-proxy)](https://goreportcard.com/report/github.com/oauth2-proxy/oauth2-proxy)
33[![GoDoc](https://godoc.org/github.com/oauth2-proxy/oauth2-proxy?status.svg)](https://godoc.org/github.com/oauth2-proxy/oauth2-proxy)
44[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
RELEASE.md+2−2
@@ -41,8 +41,8 @@ Note this uses `v4.1.0` as an example release number.
414110. Publish release in Github
424211. Make and push docker images to Quay
4343 ```
44− make docker-all
45− make docker-push-all
44+ make build-docker-all
45+ make push-docker-all
4646 ```
4747 Note: Ensure the docker tags don't include `-dirty`. This means you have uncommitted changes.
4848
docs/docs/community/contribution.md+16−5
@@ -68,11 +68,22 @@ For starting oauth2-proxy locally open the debugging tab and create the `launch.
6868
6969Before you can start your local version of oauth2-proxy, you will have to use the provided docker compose files to start a local upstream service and identity provider. We suggest using [httpbin](https://hub.docker.com/r/kennethreitz/httpbin) as your upstream for testing as it allows for request and response introspection of all things HTTP.
7070
71−Open a terminal and switch to the `contrib/local-environment` directory.
71+Inside the `contrib/local-environment` directory you can use the `Makefile` for
72+starting different example setups:
7273
73−- Dex as your IdP: `docker compose -f docker-compose.yaml up dex etcd httpbin`
74−- Keycloak as your IdP: `docker compose -f docker-compose-keycloak.yaml up keycloak httpbin`
74+- Dex as your IdP: `make up` or `make down`
75+- Dex as your IdP using the alpha-config: `make alpha-config-up`
76+- Keycloak as your IdP: `make keycloak-up`
77+- Dex as your IdP & nginx reverse proxy: `make nginx-up`
78+- and many more...
7579
76−The username for both is `admin@example.com` and password is `password`.
80+Check out the `Makefile` to see what is available.
81+
82+The username and password for all setups is usually `admin@example.com` and `password`.
83+
84+The docker compose setups expose the services with a dynamic reverse DNS resolver: localtest.me
85+
86+- OAuth2-Proxy: http://oauth2-proxy.localtest.me:4180
87+- Upstream: http://httpbin.localtest.me:8080
88+- Dex: http://dex.localtest.me:4190
7789
78−Start oauth2-proxy from the debug tab and open http://oauth2-proxy.localtest.me:4180/ for testing.
docs/versioned_docs/version-7.8.x/community/contribution.md+16−5
@@ -68,11 +68,22 @@ For starting oauth2-proxy locally open the debugging tab and create the `launch.
6868
6969Before you can start your local version of oauth2-proxy, you will have to use the provided docker compose files to start a local upstream service and identity provider. We suggest using [httpbin](https://hub.docker.com/r/kennethreitz/httpbin) as your upstream for testing as it allows for request and response introspection of all things HTTP.
7070
71−Open a terminal and switch to the `contrib/local-environment` directory.
71+Inside the `contrib/local-environment` directory you can use the `Makefile` for
72+starting different example setups:
7273
73−- Dex as your IdP: `docker compose -f docker-compose.yaml up dex etcd httpbin`
74−- Keycloak as your IdP: `docker compose -f docker-compose-keycloak.yaml up keycloak httpbin`
74+- Dex as your IdP: `make up` or `make down`
75+- Dex as your IdP using the alpha-config: `make alpha-config-up`
76+- Keycloak as your IdP: `make keycloak-up`
77+- Dex as your IdP & nginx reverse proxy: `make nginx-up`
78+- and many more...
7579
76−The username for both is `admin@example.com` and password is `password`.
80+Check out the `Makefile` to see what is available.
81+
82+The username and password for all setups is usually `admin@example.com` and `password`.
83+
84+The docker compose setups expose the services with a dynamic reverse DNS resolver: localtest.me
85+
86+- OAuth2-Proxy: http://oauth2-proxy.localtest.me:4180
87+- Upstream: http://httpbin.localtest.me:8080
88+- Dex: http://dex.localtest.me:4190
7789
78−Start oauth2-proxy from the debug tab and open http://oauth2-proxy.localtest.me:4180/ for testing.