gitlab.com/picnic-app/backend/role-api@v0.0.0-20230614140944-06a76ff3696d/Makefile (about) 1 export GO111MODULE=on 2 export GOPROXY=https://proxy.golang.org 3 export GOSUMDB=off 4 5 LOCAL_BIN:=$(CURDIR)/bin 6 BUILD_ENVPARMS:=CGO_ENABLED=0 7 8 PLATFORM:=amd64 9 10 GIT_TAG:=$(shell git describe --exact-match --abbrev=0 --tags 2> /dev/null) 11 GIT_HASH:=$(shell git log --format="%h" -n 1 2> /dev/null) 12 GIT_LOG:=$(shell git log --decorate --oneline -n1 2> /dev/null | base64 | tr -d '\n') 13 GIT_BRANCH:=$(shell git branch 2> /dev/null | grep '*' | cut -f2 -d' ') 14 ENV_ID:=$(shell git branch --show-current 2>/dev/null | tr '[:upper:]' '[:lower:]') 15 16 APP_VERSION:=$(if $(GIT_BRANCH),$(GIT_BRANCH),$(GIT_HASH)) 17 18 LDFLAGS:=-X 'platform/core/app.Name=role-api'\ 19 -X 'platform/core/app.Version=$(APP_VERSION)' 20 21 export PATH:=$(LOCAL_BIN):$(PATH) 22 23 MIGRATIONS_DIR:=$(CURDIR)/.db/spanner 24 SPANNER_DATABASE:=user 25 26 GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint 27 GOLANGCI_TAG:=1.50.1 28 29 .PHONY: deps 30 deps: 31 $(info Installing binary dependencies...) 32 GOBIN=$(LOCAL_BIN) go install github.com/incu6us/goimports-reviser/v3@latest 33 GOBIN=$(LOCAL_BIN) go install github.com/fatih/faillint@latest 34 GOBIN=$(LOCAL_BIN) go install github.com/cloudspannerecosystem/wrench@latest 35 GOBIN=$(LOCAL_BIN) go install mvdan.cc/gofumpt@latest 36 npm install cspell --prefix $(LOCAL_BIN) 37 38 .PHONY: clean 39 clean: 40 rm -rf .bin 41 42 .PHONY: spell 43 spell: 44 $(info Spell checking for the source code...) 45 $(LOCAL_BIN)/node_modules/cspell/bin.js "**" --config ./cspell.yml 46 47 .PHONY: build 48 build: 49 $(info Building...) 50 $(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" -o ./bin/grpcapp ./cmd 51 52 .PHONY: run 53 run: 54 $(info Running...) 55 $(BUILD_ENVPARMS) go run -ldflags "$(LDFLAGS)" ./cmd 56 57 .PHONY: migrate-new 58 migrate-new: 59 GOBIN=$(LOCAL_BIN) wrench migrate create --directory $(MIGRATIONS_DIR) 60 61 .PHONY: migrate-up 62 migrate-up: 63 GOBIN=$(LOCAL_BIN) wrench migrate up --directory $(MIGRATIONS_DIR) \ 64 --project $(SPANNER_PROJECT) \ 65 --instance $(SPANNER_INSTANCE) \ 66 --database $(SPANNER_DATABASE) 67 68 .PHONY: migrate-load 69 migrate-load: 70 GOBIN=$(LOCAL_BIN) wrench load --directory $(MIGRATIONS_DIR)/dump \ 71 --project $(SPANNER_PROJECT) \ 72 --instance $(SPANNER_INSTANCE) \ 73 --database $(SPANNER_DATABASE) 74 75 76 .PHONY: format 77 format: 78 goimports-reviser -project-name role-api -company-prefixes gitlab.com/picnic-app ./... 79 GOBIN=$(LOCAL_BIN) gofumpt -l -w -extra . 80 81 .PHONY: lint 82 lint: 83 go clean --cache 84 go mod tidy && go mod vendor 85 docker run --rm -v $(CURDIR):/role-api -w /role-api golangci/golangci-lint:v1.48.0-alpine golangci-lint run --config=.cfg/lint.yaml ./... -v 86 GOBIN=$(LOCAL_BIN) faillint -paths "errors=github.com/pkg/errors" ./... 87 88 .PHONY: docker-image 89 docker-image: 90 $(info Building docker image...) 91 docker build --secret "id=netrc,src=$(HOME)/.netrc" --platform $(PLATFORM) --tag role-api -f Dockerfile . 92 93 .PHONY: docker-run 94 docker-run: 95 $(info Running docker image...) 96 docker run -d -p 8080:8080 -p 8082:8082 -p 8084:8084 role-api 97 98 .PHONY: emulator/create 99 emulator/create: 100 docker run -p 9010:9010 -p 9020:9020 -d --name spanner-dev gcr.io/cloud-spanner-emulator/emulator:1.4.8 101 gcloud config configurations create emulator --activate --quiet 2> /dev/null ; true 102 gcloud config set project dev -q 103 gcloud config set api_endpoint_overrides/spanner http://localhost:9020/ 104 gcloud spanner instances create dev --config=emulator-config --nodes=1 --description="dev instance" 105 gcloud spanner databases create dev --instance=dev 106 SPANNER_EMULATOR_HOST=localhost:9010 $(MAKE) migrate-up SPANNER_PROJECT=dev SPANNER_INSTANCE=dev SPANNER_DATABASE=dev 107 108 .PHONY: emulator/destroy 109 emulator/destroy: 110 docker stop spanner-dev 111 docker rm spanner-dev 112 113 .PHONY: emulator/migrate 114 emulator/migrate: 115 SPANNER_EMULATOR_HOST=localhost:9010 $(MAKE) migrate-up SPANNER_PROJECT=dev SPANNER_INSTANCE=dev SPANNER_DATABASE=dev 116 117 .PHONY: test/unit 118 test/unit: 119 go test -race $(shell go list ./... | grep -v test) 120 121 .PHONY: test/e2e 122 test/e2e: 123 go clean -testcache 124 go test -race -v --tags=integration -race ./cmd/e2etest 125 126 .PHONY: test/all 127 test/all: 128 $(MAKE) test/unit 129 $(MAKE) test/e2e 130 131 .PHONY: devspace-start 132 devspace-start: 133 $(info Starting devspace) 134 DEVSPACE_CONFIG=.cfg/devspace.yaml devspace dev --show-ui -n "$(ENV_ID)" 135 136 .PHONY: devspace-stop 137 devspace-stop: 138 $(info Stopping devspace) 139 DEVSPACE_CONFIG=.cfg/devspace.yaml devspace purge -n "$(ENV_ID)"