Skip to content

Commit

Permalink
Merge pull request dexidp#2844 from deckhouse/makefile-refactoring
Browse files Browse the repository at this point in the history
feat: Bump dependencies and Makefile refactoring
  • Loading branch information
sagikazarmark authored Mar 11, 2023
2 parents ab97862 + 7208e28 commit 0c9f980
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 280 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,28 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"

- name: Checkout code
uses: actions/checkout@v3

- name: Download tool dependencies
run: make deps

# Ensure that generated files were committed.
# It can help us determine, that the code is in the intermediate state, which should not be tested.
# Thus, heavy jobs like creating a kind cluster and testing / linting will be skipped.
- name: Verify
run: make verify

- name: Start services
run: docker-compose -f docker-compose.test.yaml up -d

- name: Create kind cluster
uses: helm/[email protected]
with:
version: v0.11.1
node_image: kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729

- name: Download tool dependencies
run: make deps
version: "v0.17.0"
node_image: "kindest/node:v1.25.3@sha256:cd248d1438192f7814fbca8fede13cfe5b9918746dfa12583976158a834fd5c5"

- name: Test
run: make testall
Expand Down Expand Up @@ -123,7 +129,3 @@ jobs:

- name: Lint
run: make lint

# Ensure that generated files were committed.
- name: Verify
run: make verify
12 changes: 8 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run:
timeout: 4m
skip-dirs:
- storage/ent/db # generated ent code

linters-settings:
depguard:
Expand All @@ -18,7 +20,6 @@ linters-settings:
linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- exhaustive
Expand All @@ -38,16 +39,19 @@ linters:
- nolintlint
- prealloc
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tparallel
- unconvert
- unparam
- unused
- whitespace

# Disable temporarily until everything works with Go 1.20
# - bodyclose
# - rowserrcheck
# - tparallel
# - unparam

# Disable temporarily until everything works with Go 1.18
- typecheck

Expand Down
252 changes: 146 additions & 106 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
OS = $(shell uname | tr A-Z a-z)

export PATH := $(abspath bin/protoc/bin/):$(abspath bin/):${PATH}

PROJ=dex
ORG_PATH=github.com/dexidp
REPO_PATH=$(ORG_PATH)/$(PROJ)

VERSION ?= $(shell ./scripts/git-version)

DOCKER_REPO=quay.io/dexidp/dex
DOCKER_IMAGE=$(DOCKER_REPO):$(VERSION)
user=$(shell id -u -n)
group=$(shell id -g -n)

$( shell mkdir -p bin )

user=$(shell id -u -n)
group=$(shell id -g -n)
PROJ = dex
ORG_PATH = github.com/dexidp
REPO_PATH = $(ORG_PATH)/$(PROJ)
VERSION ?= $(shell ./scripts/git-version)

export GOBIN=$(PWD)/bin

export GOBIN=$(PWD)/bin
LD_FLAGS="-w -X main.version=$(VERSION)"

# Dependency versions
GOLANGCI_VERSION = 1.51.2
GOTESTSUM_VERSION ?= 1.7.0

KIND_NODE_IMAGE = "kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729"
KIND_TMP_DIR = "$(PWD)/bin/test/dex-kind-kubeconfig"
PROTOC_VERSION = 3.15.6
PROTOC_GEN_GO_VERSION = 1.26.0
PROTOC_GEN_GO_GRPC_VERSION = 1.1.0

build: bin/dex
KIND_VERSION = 0.17.0
KIND_NODE_IMAGE = "kindest/node:v1.25.3@sha256:cd248d1438192f7814fbca8fede13cfe5b9918746dfa12583976158a834fd5c5"
KIND_TMP_DIR = "$(PWD)/bin/test/dex-kind-kubeconfig"

verify: verify-proto verify-ent

bin/dex:
@mkdir -p bin/
@go install -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex
##@ Build

.PHONY: ent-generate
ent-generate:
@go generate $(REPO_PATH)/storage/ent/
build: bin/dex ## Build Dex binaries.

.PHONY: verify-ent
verify-ent: ent-generate
@./scripts/git-diff
examples: bin/grpc-client bin/example-app ## Build example app.

examples: bin/grpc-client bin/example-app
.PHONY: release-binary
release-binary: LD_FLAGS = "-w -X main.version=$(VERSION) -extldflags \"-static\""
release-binary: ## Build release binaries (used to build a final container image).
@go build -o /go/bin/dex -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex
@go build -o /go/bin/docker-entrypoint -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/docker-entrypoint

bin/dex:
@mkdir -p bin/
@go install -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex

bin/grpc-client:
@mkdir -p bin/
Expand All @@ -51,95 +52,29 @@ bin/example-app:
@mkdir -p bin/
@cd examples/ && go install -v -ldflags $(LD_FLAGS) $(REPO_PATH)/examples/example-app

.PHONY: release-binary
release-binary: LD_FLAGS = "-w -X main.version=$(VERSION) -extldflags \"-static\""
release-binary:
@go build -o /go/bin/dex -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex
@go build -o /go/bin/docker-entrypoint -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/docker-entrypoint

docker-compose.override.yaml:
cp docker-compose.override.yaml.dist docker-compose.override.yaml

.PHONY: up
up: docker-compose.override.yaml ## Launch the development environment
@ if [ docker-compose.override.yaml -ot docker-compose.override.yaml.dist ]; then diff -u docker-compose.override.yaml docker-compose.override.yaml.dist || (echo "!!! The distributed docker-compose.override.yaml example changed. Please update your file accordingly (or at least touch it). !!!" && false); fi
docker-compose up -d

.PHONY: down
down: clear ## Destroy the development environment
docker-compose down --volumes --remove-orphans --rmi local

test:
@go test -v ./...

testrace:
@go test -v --race ./...
##@ Generate

.PHONY: kind-up kind-down kind-tests
kind-up:
@mkdir -p bin/test
@kind create cluster --image ${KIND_NODE_IMAGE} --kubeconfig ${KIND_TMP_DIR}

kind-down:
@kind delete cluster
rm ${KIND_TMP_DIR}

kind-tests: export DEX_KUBERNETES_CONFIG_PATH=${KIND_TMP_DIR}
kind-tests: testall

.PHONY: lint lint-fix
lint: ## Run linter
golangci-lint run
.PHONY: generate
generate: go-mod-tidy generate-proto generate-proto-internal generate-ent ## Run all generators.

.PHONY: fix
fix: ## Fix lint violations
golangci-lint run --fix

.PHONY: docker-image
docker-image:
@sudo docker build -t $(DOCKER_IMAGE) .

.PHONY: verify-proto
verify-proto: proto
@./scripts/git-diff

clean:
@rm -rf bin/

testall: testrace

FORCE:

.PHONY: test testrace testall
.PHONY: generate-ent
generate-ent: ## Generate code for database ORM.
@go generate $(REPO_PATH)/storage/ent/

.PHONY: proto
proto:
.PHONY: generate-proto
generate-proto: ## Generate the Dex client's protobuf code.
@protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. api/v2/*.proto
@protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. api/*.proto
#@cp api/v2/*.proto api/

.PHONY: proto-internal
proto-internal:
.PHONY: generate-proto-internal
generate-proto-internal: ## Generate protobuf code for token encoding.
@protoc --go_out=paths=source_relative:. server/internal/*.proto

# Dependency versions
GOLANGCI_VERSION = 1.50.1
GOTESTSUM_VERSION ?= 1.7.0
PROTOC_VERSION = 3.15.6
PROTOC_GEN_GO_VERSION = 1.26.0
PROTOC_GEN_GO_GRPC_VERSION = 1.1.0
KIND_VERSION = 0.11.1

deps: bin/gotestsum bin/golangci-lint bin/protoc bin/protoc-gen-go bin/protoc-gen-go-grpc bin/kind

bin/gotestsum:
@mkdir -p bin
curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_$(shell uname | tr A-Z a-z)_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum
@chmod +x ./bin/gotestsum

bin/golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
go-mod-tidy: ## Run go mod tidy for all targets.
@go mod tidy
@cd examples/ && go mod tidy
@cd api/v2/ && go mod tidy

bin/protoc:
@mkdir -p bin/protoc
Expand All @@ -162,7 +97,112 @@ bin/protoc-gen-go-grpc:
curl -L https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v${PROTOC_GEN_GO_GRPC_VERSION}/protoc-gen-go-grpc.v${PROTOC_GEN_GO_GRPC_VERSION}.$(shell uname | tr A-Z a-z).amd64.tar.gz | tar -zOxf - ./protoc-gen-go-grpc > ./bin/protoc-gen-go-grpc
@chmod +x ./bin/protoc-gen-go-grpc

##@ Verify

verify: generate ## Verify that all the code was generated and committed to repository.
@./scripts/git-diff

.PHONY: verify-proto
verify-proto: generate-proto ## Verify that the Dex client's protobuf code was generated.
@./scripts/git-diff

.PHONY: verify-proto
verify-proto-internal: generate-proto-internal ## Verify internal protobuf code for token encoding was generated.
@./scripts/git-diff

.PHONY: verify-ent
verify-ent: generate-ent ## Verify code for database ORM was generated.
@./scripts/git-diff

.PHONY: verify-go-mod
verify-go-mod: go-mod-tidy ## Check that go.mod and go.sum formatted according to the changes.
@./scripts/git-diff

##@ Test and Lint

deps: bin/gotestsum bin/golangci-lint bin/protoc bin/protoc-gen-go bin/protoc-gen-go-grpc bin/kind ## Install dev dependencies.

.PHONY: test testrace testall
test: ## Test go code.
@go test -v ./...

testrace: ## Test go code and check for possible race conditions.
@go test -v --race ./...

testall: testrace ## Run all tests for go code.

.PHONY: lint lint-fix
lint: ## Run linter.
@golangci-lint version
@golangci-lint run

.PHONY: fix
fix: ## Fix lint violations.
@golangci-lint version
@golangci-lint run --fix

docker-compose.override.yaml:
cp docker-compose.override.yaml.dist docker-compose.override.yaml

.PHONY: up
up: docker-compose.override.yaml ## Launch the development environment.
@ if [ docker-compose.override.yaml -ot docker-compose.override.yaml.dist ]; then diff -u docker-compose.override.yaml docker-compose.override.yaml.dist || (echo "!!! The distributed docker-compose.override.yaml example changed. Please update your file accordingly (or at least touch it). !!!" && false); fi
docker-compose up -d

.PHONY: down
down: clear ## Destroy the development environment.
docker-compose down --volumes --remove-orphans --rmi local

.PHONY: kind-up kind-down kind-tests
kind-up: ## Create a kind cluster.
@mkdir -p bin/test
@kind create cluster --image ${KIND_NODE_IMAGE} --kubeconfig ${KIND_TMP_DIR} --name dex-tests

kind-tests: export DEX_KUBERNETES_CONFIG_PATH=${KIND_TMP_DIR}
kind-tests: testall ## Run test on kind cluster (kind cluster must be created).

kind-down: ## Delete the kind cluster.
@kind delete cluster --name dex-tests
rm ${KIND_TMP_DIR}

bin/golangci-lint:
@mkdir -p bin
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}

bin/gotestsum:
@mkdir -p bin
curl -L https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_$(shell uname | tr A-Z a-z)_amd64.tar.gz | tar -zOxf - gotestsum > ./bin/gotestsum
@chmod +x ./bin/gotestsum

bin/kind:
@mkdir -p bin
curl -L https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-$(shell uname | tr A-Z a-z)-amd64 > ./bin/kind
@chmod +x ./bin/kind

##@ Clean
clean: ## Delete all builds and downloaded dependencies.
@rm -rf bin/


FORMATTING_BEGIN_YELLOW = \033[0;33m
FORMATTING_BEGIN_BLUE = \033[36m
FORMATTING_END = \033[0m

.PHONY: help
help:
@printf -- "${FORMATTING_BEGIN_BLUE}%s${FORMATTING_END}\n" \
"" \
" ___ " \
" / _ \_____ __ " \
" / // / -_) \ / " \
" /____/\__/_\_\ " \
"" \
"-----------------------" \
""
@awk 'BEGIN {\
FS = ":.*##"; \
printf "Usage: ${FORMATTING_BEGIN_BLUE}OPTION${FORMATTING_END}=<value> make ${FORMATTING_BEGIN_YELLOW}<target>${FORMATTING_END}\n"\
} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " ${FORMATTING_BEGIN_BLUE}%-46s${FORMATTING_END} %s\n", $$1, $$2 } \
/^.?.?##~/ { printf " %-46s${FORMATTING_BEGIN_YELLOW}%-46s${FORMATTING_END}\n", "", substr($$1, 6) } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
Loading

0 comments on commit 0c9f980

Please sign in to comment.