2020-05-09 17:07:46 +02:00
GO ?= go
GOLANGCILINT ?= golangci-lint
2020-03-29 15:54:36 +02:00
BINARY := oauth2-proxy
2020-07-07 10:53:32 +02:00
VERSION ?= $( shell git describe --always --dirty --tags 2>/dev/null || echo "undefined" )
2019-10-07 22:53:46 +02:00
# Allow to override image registry.
2024-01-20 20:48:04 +02:00
REGISTRY ?= quay.io/oauth2-proxy
REPOSITORY ?= oauth2-proxy
2023-11-18 15:56:29 +02:00
DATE := $( shell date +"%Y%m%d" )
2019-01-07 18:41:11 +02:00
.NOTPARALLEL :
2019-01-04 12:58:30 +02:00
2020-05-09 17:07:46 +02:00
GO_MAJOR_VERSION = $( shell $( GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $( shell $( GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
2024-01-22 15:39:53 +02:00
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 20
2020-05-09 17:07:46 +02:00
GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) .$( MINIMUM_SUPPORTED_GO_MINOR_VERSION)
2020-05-10 08:29:37 +02:00
i f e q ( $( COVER ) , t r u e )
TESTCOVER ?= -coverprofile c.out
e n d i f
2019-01-04 12:58:30 +02:00
.PHONY : all
2019-07-13 22:24:40 +02:00
all : lint $( BINARY )
2019-01-04 12:58:30 +02:00
.PHONY : clean
clean :
2021-10-05 17:58:54 +02:00
-rm -rf release
-rm -f $( BINARY)
2019-01-04 12:58:30 +02:00
.PHONY : distclean
distclean : clean
rm -rf vendor
.PHONY : lint
2020-05-09 17:07:46 +02:00
lint : validate -go -version
2019-07-13 22:24:40 +02:00
GO111MODULE = on $( GOLANGCILINT) run
2019-01-04 12:58:30 +02:00
.PHONY : build
2020-05-09 17:07:46 +02:00
build : validate -go -version clean $( BINARY )
2019-01-04 12:58:30 +02:00
$(BINARY) :
2021-10-05 17:58:54 +02:00
CGO_ENABLED = 0 $( GO) build -a -installsuffix cgo -ldflags= " -X main.VERSION= ${ VERSION } " -o $@ github.com/oauth2-proxy/oauth2-proxy/v7
2019-01-04 12:58:30 +02:00
2024-01-20 20:48:04 +02:00
DOCKER_BUILD_PLATFORM ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v7
DOCKER_BUILD_RUNTIME_IMAGE ?= gcr.io/distroless/static:nonroot
DOCKER_BUILDX_ARGS ?= --build-arg RUNTIME_IMAGE = ${ DOCKER_BUILD_RUNTIME_IMAGE } --build-arg VERSION = ${ VERSION }
DOCKER_BUILDX := docker buildx build ${ DOCKER_BUILDX_ARGS } --pull
2023-09-08 18:18:20 +02:00
DOCKER_BUILDX_X_PLATFORM := $( DOCKER_BUILDX) --platform ${ DOCKER_BUILD_PLATFORM }
DOCKER_BUILDX_PUSH := $( DOCKER_BUILDX) --push
2021-11-14 19:50:12 +02:00
DOCKER_BUILDX_PUSH_X_PLATFORM := $( DOCKER_BUILDX_PUSH) --platform ${ DOCKER_BUILD_PLATFORM }
2021-09-21 15:17:59 +02:00
2024-01-20 20:48:04 +02:00
DOCKER_BUILD_PLATFORM_ALPINE ?= linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v6,linux/arm/v7
2024-02-14 11:07:08 +02:00
DOCKER_BUILD_RUNTIME_IMAGE_ALPINE ?= alpine:3.19.1
2024-01-20 20:48:04 +02:00
DOCKER_BUILDX_ARGS_ALPINE ?= --build-arg RUNTIME_IMAGE = ${ DOCKER_BUILD_RUNTIME_IMAGE_ALPINE } --build-arg VERSION = ${ VERSION }
DOCKER_BUILDX_X_PLATFORM_ALPINE := docker buildx build ${ DOCKER_BUILDX_ARGS_ALPINE } --platform ${ DOCKER_BUILD_PLATFORM_ALPINE }
DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE := $( DOCKER_BUILDX_X_PLATFORM_ALPINE) --push
2019-02-02 01:08:19 +02:00
.PHONY : docker
docker :
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX_X_PLATFORM) -t $( REGISTRY) /$( REPOSITORY) :latest -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } .
$( DOCKER_BUILDX_X_PLATFORM_ALPINE) -t $( REGISTRY) /$( REPOSITORY) :latest-alpine -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -alpine .
2019-02-02 01:08:19 +02:00
2023-11-18 15:56:29 +02:00
.PHONY : docker -push
docker-push :
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX_PUSH_X_PLATFORM) -t $( REGISTRY) /$( REPOSITORY) :latest -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } .
$( DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t $( REGISTRY) /$( REPOSITORY) :latest-alpine -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -alpine .
2023-11-18 15:56:29 +02:00
2019-02-02 01:08:19 +02:00
.PHONY : docker -all
2019-02-02 03:20:20 +02:00
docker-all : docker
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX) --platform linux/amd64 -t $( REGISTRY) /$( REPOSITORY) :latest-amd64 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -amd64 .
$( DOCKER_BUILDX) --platform linux/arm64 -t $( REGISTRY) /$( REPOSITORY) :latest-arm64 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -arm64 .
$( DOCKER_BUILDX) --platform linux/ppc64le -t $( REGISTRY) /$( REPOSITORY) :latest-ppc64le -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -ppc64le .
$( DOCKER_BUILDX) --platform linux/arm/v6 -t $( REGISTRY) /$( REPOSITORY) :latest-armv6 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -armv6 .
$( DOCKER_BUILDX) --platform linux/arm/v7 -t $( REGISTRY) /$( REPOSITORY) :latest-armv7 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -armv7 .
2019-02-08 12:05:57 +02:00
.PHONY : docker -push -all
docker-push-all : docker -push
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX_PUSH) --platform linux/amd64 -t $( REGISTRY) /$( REPOSITORY) :latest-amd64 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -amd64 .
$( DOCKER_BUILDX_PUSH) --platform linux/arm64 -t $( REGISTRY) /$( REPOSITORY) :latest-arm64 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -arm64 .
$( DOCKER_BUILDX_PUSH) --platform linux/ppc64le -t $( REGISTRY) /$( REPOSITORY) :latest-ppc64le -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -ppc64le .
$( DOCKER_BUILDX_PUSH) --platform linux/arm/v6 -t $( REGISTRY) /$( REPOSITORY) :latest-armv6 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -armv6 .
$( DOCKER_BUILDX_PUSH) --platform linux/arm/v7 -t $( REGISTRY) /$( REPOSITORY) :latest-armv7 -t $( REGISTRY) /$( REPOSITORY) :${ VERSION } -armv7 .
2019-02-02 01:08:19 +02:00
2023-11-18 15:56:29 +02:00
.PHONY : docker -nightly -build
docker-nightly-build :
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX_X_PLATFORM) -t $( REGISTRY) /$( REPOSITORY) -nightly:latest -t $( REGISTRY) /$( REPOSITORY) -nightly:${ DATE } .
$( DOCKER_BUILDX_X_PLATFORM_ALPINE) -t ${ REGISTRY } /$( REPOSITORY) -nightly:latest-alpine -t $( REGISTRY) /$( REPOSITORY) -nightly:${ DATE } -alpine .
2023-11-18 15:56:29 +02:00
.PHONY : docker -nightly -push
docker-nightly-push :
2024-01-20 20:48:04 +02:00
$( DOCKER_BUILDX_PUSH_X_PLATFORM) -t $( REGISTRY) /$( REPOSITORY) -nightly:latest -t $( REGISTRY) /$( REPOSITORY) -nightly:${ DATE } .
$( DOCKER_BUILDX_PUSH_X_PLATFORM_ALPINE) -t ${ REGISTRY } /$( REPOSITORY) -nightly:latest-alpine -t $( REGISTRY) /$( REPOSITORY) -nightly:${ DATE } -alpine .
2023-11-18 15:56:29 +02:00
2020-11-07 18:31:31 +02:00
.PHONY : generate
generate :
go generate ./pkg/...
.PHONY : verify -generate
verify-generate : generate
git diff --exit-code
2019-01-04 12:58:30 +02:00
.PHONY : test
2019-07-13 22:24:40 +02:00
test : lint
2020-05-10 08:29:37 +02:00
GO111MODULE = on $( GO) test $( TESTCOVER) -v -race ./...
2019-01-04 12:58:30 +02:00
.PHONY : release
2021-02-07 01:19:33 +02:00
release : validate -go -version lint test
2019-10-29 19:27:08 +02:00
BINARY = ${ BINARY } VERSION = ${ VERSION } ./dist.sh
2020-05-09 17:07:46 +02:00
.PHONY : validate -go -version
2020-05-03 22:05:40 +02:00
validate-go-version :
2020-05-09 17:07:46 +02:00
@if [ $( GO_MAJOR_VERSION) -gt $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ] ; then \
exit 0 ; \
elif [ $( GO_MAJOR_VERSION) -lt $( MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)' ; \
exit 1; \
elif [ $( GO_MINOR_VERSION) -lt $( MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)' ; \
exit 1; \
fi
2020-05-03 22:05:40 +02:00
# local-env can be used to interact with the local development environment
2020-05-07 23:59:43 +02:00
# eg:
2023-11-18 15:56:29 +02:00
# make local-env-up # Bring up a basic test environment
# make local-env-down # Tear down the basic test environment
# make local-env-nginx-up # Bring up an nginx based test environment
# make local-env-nginx-down # Tead down the nginx based test environment
2020-05-03 22:05:40 +02:00
.PHONY : local -env -%
local-env-% :
make -C contrib/local-environment $*