|
| 1 | +API_BIN := "./bin/banner" |
| 2 | +DOCKER_IMG="banner:develop" |
| 3 | + |
| 4 | +GIT_HASH := $(shell git log --format="%h" -n 1) |
| 5 | +LDFLAGS := -X main.release="develop" -X main.buildDate=$(shell date -u +%Y-%m-%dT%H:%M:%S) -X main.gitHash=$(GIT_HASH) |
| 6 | + |
| 7 | +install-lint-deps: |
| 8 | + (which golangci-lint > /dev/null) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.55.2 |
| 9 | + |
| 10 | +lint: install-lint-deps |
| 11 | + golangci-lint run ./... |
| 12 | + |
| 13 | +.PHONY: build run build-img run-img version test lint |
| 14 | + |
| 15 | +generate: |
| 16 | + rm -rf internal/server/pb |
| 17 | + mkdir -p internal/server/pb |
| 18 | + |
| 19 | + protoc \ |
| 20 | + --proto_path=./api/ \ |
| 21 | + --go_opt=paths=source_relative \ |
| 22 | + --go-grpc_opt=paths=source_relative \ |
| 23 | + --go_out=./internal/server/pb \ |
| 24 | + --go-grpc_out=./internal/server/pb \ |
| 25 | + api/*.proto |
| 26 | + |
| 27 | +build-img: |
| 28 | + docker build \ |
| 29 | + --build-arg=LDFLAGS="$(LDFLAGS)" \ |
| 30 | + -t $(DOCKER_IMG) \ |
| 31 | + -f build/banner/Dockerfile . |
| 32 | + |
| 33 | +run-img: build-img |
| 34 | + docker run $(DOCKER_IMG) |
| 35 | + |
| 36 | +up: |
| 37 | + docker-compose -f docker-compose.yaml up --build -d ;\ |
| 38 | + docker-compose up -d |
| 39 | + |
| 40 | +down: |
| 41 | + docker-compose down |
| 42 | + |
| 43 | +test: |
| 44 | + go clean -testcache; |
| 45 | + go test -v -race -count 100 ./internal/... |
| 46 | + |
| 47 | +integration-tests: |
| 48 | + set -e ;\ |
| 49 | + docker-compose -f docker-compose.test.yaml up --build -d ;\ |
| 50 | + test_status_code=0 ;\ |
| 51 | + docker-compose -f docker-compose.test.yaml run integration_tests go test ./test/integration_test.go || test_status_code=$$? ;\ |
| 52 | + docker-compose -f docker-compose.test.yaml down ;\ |
| 53 | + echo $$test_status_code ;\ |
| 54 | + exit $$test_status_code ; |
| 55 | + |
| 56 | + |
| 57 | +build: |
| 58 | + go build -v -o $(API_BIN) -ldflags "$(LDFLAGS)" ./cmd/banner |
| 59 | + |
| 60 | +run: build |
| 61 | + $(API_BIN) -config ./configs/banner_config.yaml |
| 62 | + |
| 63 | +build-debug: |
| 64 | + go build -gcflags="all=-N -l" -o $(API_BIN) -ldflags "$(LDFLAGS)" ./cmd/banner |
| 65 | + |
| 66 | +run-debug: build-debug |
| 67 | + $(API_BIN) -config ./configs/banner_config.yaml |
| 68 | + |
| 69 | +run-postgres: |
| 70 | + docker run -d --rm --name composepostgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -v psqldata:/var/lib/postgresql/data -p 5432:5432 postgres:latest |
| 71 | + |
| 72 | +migrate-up: |
| 73 | + goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" up |
| 74 | + |
| 75 | +migrate-down: |
| 76 | + goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" down |
| 77 | + |
| 78 | +migrate-down-to-0001: |
| 79 | + goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" down-to 0001 |
| 80 | + |
| 81 | +migrate-status: |
| 82 | + goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" status |
| 83 | + |
| 84 | +migrate-reset: |
| 85 | + goose -dir migrations postgres "host=localhost user=postgres password=postgres dbname=postgres sslmode=disable" reset |
| 86 | + |
| 87 | +run-rabbitmq: |
| 88 | + docker run -d --rm --name rabbitmq -e RABBITMQ_DEFAULT_USER=guest -e RABBITMQ_DEFAULT_PASS=guest -p 15672:15672 -p 5672:5672 rabbitmq:3-management |
| 89 | + |
| 90 | +stop-rabbitmq: |
| 91 | + docker stop rabbitmq |
0 commit comments