-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (63 loc) · 2.18 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
AWS_REGION?=us-east-1
AWS_ACCOUNT_ID?=000000000000
AWS_REGISTRY_URL?=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com
AWS_PROFILE?=golang
IMAGE_VERSION=$(shell date +"%Y%m%dT%H%M%S")
IMAGE_URL?=${AWS_REGISTRY_URL}/golang-api
DB_PORT?=5432
DB_USERNAME?=root
DB_PASSWORD?=root
DB_HOST?=host.docker.internal
DB_NAME?=development
DB_ENABLED_SSL?=false
DB_SCHEMA?=public
ifeq ($(DB_ENABLED_SSL),false)
DB_SSL?=disable
else
DB_SSL?=require
endif
DB_URL?=postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL}&search_path=${DB_SCHEMA}
define run_migration_docker
docker run --rm -v $(shell pwd)/migrations:/migrations migrate/migrate -path /migrations/ -database "${DB_URL}" $(1)
endef
run:
go run -race ./cmd/api/main.go
start_docker:
docker compose -f docker-compose.yml down --remove-orphans
docker compose -f docker-compose.yml up --build -d
docker logs go-rest-api.api -f
start_local: check_build
APP_ENV=local ~/go/bin/air -c .air.toml
start_production: check_build
APP_ENV=production ~/go/bin/air -c .air.toml
start_staging: check_build
APP_ENV=staging ~/go/bin/air -c .air.toml
docker_build_local:
docker build --rm --no-cache -f ./Dockerfile.production -t ${IMAGE_URL}.${IMAGE_VERSION} .
docker_build_aws:
docker build --rm --no-cache --platform linux/amd64 -f ./Dockerfile.production -t ${IMAGE_URL}-${IMAGE_VERSION} .
aws --profile ${AWS_PROFILE} ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_REGISTRY_URL}
docker push ${IMAGE_URL}.${IMAGE_VERSION}
check_build:
go mod tidy
go build -v ./...
create_migration:
./create-migration-file.sh "$(name)"
migration_up:
$(call run_migration_docker,up)
migration_down:
$(call run_migration_docker,down -all)
generate_linux_bin:
rm -rf ./bin && mkdir -p ./bin
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o ./bin/api ./cmd/api/main.go
generate_local_bin:
rm -rf ./bin && mkdir -p ./bin
CGO_ENABLED=0 go build -ldflags="-s -w" -o ./bin/api ./cmd/api/main.go
update_modules:
go get -u ./...
go mod tidy
make check_build
test: check_build
APP_ENV=test go test -v ./...
test_race: check_build
APP_ENV=test go test -v --race ./...