-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
157 lines (128 loc) · 3.45 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
.DEFAULT_GOAL := run
HOME_DIR := $(shell echo $$HOME)
DB_PATH := $(HOME_DIR)/.n8n-shortlink/n8n-shortlink.sqlite
help:
@echo "Commands:"
@sed -n 's/^##//p' $(MAKEFILE_LIST)
# ------------
# develop
# ------------
## run: Build and run binary
run:
go run cmd/server/main.go
.PHONY: run
## live: Run binary with live reload
live:
air
.PHONY: live
lint:
golangci-lint run
lintfix:
golangci-lint run --fix
# ------------
# audit
# ------------
## audit: Run `go mod tidy`, `go fmt`, `golint`, `go test`, and `go vet`
audit:
echo 'Tidying...'
go mod tidy
echo 'Formatting...'
go fmt ./...
echo 'Linting...'
golint ./...
echo 'Testing...'
go test -v ./...
echo 'Vetting...'
go vet ./...
.PHONY: audit
## test: Run tests
test:
gotestsum --format testname
.PHONY: test
## test/watch: Run tests in watch mode
test/watch:
gotestsum --format testname --watch
.PHONY: test
# ------------
# build
# ------------
CURRENT_TIME = $(shell date +"%Y-%m-%dT%H:%M:%S%z")
GIT_DESCRIPTION = $(shell git describe --always --dirty)
LINKER_FLAGS = '-s -X main.commitSha=${GIT_DESCRIPTION} -X main.buildTime=${CURRENT_TIME}'
## build: Build binary, burning in commit SHA and build time
build:
go build -ldflags=${LINKER_FLAGS} -o bin cmd/server/main.go
.PHONY:build
## build/meta: Display commit SHA and build time burned into binary
build/meta:
./bin/main -metadata-mode
.PHONY: build/meta
# ------------
# db
# ------------
## db/create: Create new database and apply up migrations
db/create:
@if [ -f ${DB_PATH} ]; then \
echo "\033[0;33mWarning:\033[0m This will overwrite the existing database.\nAre you sure? (y/n)"; \
read confirm && if [ "$$confirm" = "y" ]; then \
rm -f ${DB_PATH}; \
sqlite3 ${DB_PATH} ""; \
make db/mig/up; \
echo "\033[0;34mOK Created new empty database\033[0m"; \
else \
echo "\033[0;31mAborted database creation\033[0m"; \
fi \
else \
sqlite3 ${DB_PATH} ""; \
make db/mig/up; \
echo "\033[0;34mOK Created new empty database\033[0m"; \
fi
.PHONY: db/create
## db/connect: Connect to database
db/connect:
sqlite3 ${DB_PATH}
.PHONY: db/connect
## db/mig/new name=$1: Create new migration, e.g. `db/mig/new name=create_users_table`
db/mig/new:
migrate create -seq -ext=.sql -dir=./internal/db/migrations ${name}
echo "\033[0;34mOK Created migration files\033[0m"
.PHONY: db/mig/new
## db/mig/up: Apply up migrations
db/mig/up:
migrate -path="./internal/db/migrations" -database "sqlite3://$(DB_PATH)" up
@echo "\033[0;34mOK Applied up migrations\033[0m"
.PHONY: db/mig/up
# ------------
# docker
# ------------
## docker/build: Build Docker image `n8n-shortlink:local`
docker/build:
docker build --tag n8n-shortlink:local .
.PHONY: docker/build
## docker/run: Run Docker container off image `n8n-shortlink:local`
docker/run:
docker compose --file deploy/docker-compose.yml --profile local up
.PHONY: docker/run
## docker/stop: Stop Docker container
docker/stop:
docker stop n8n-shortlink
.PHONY: docker/run
## docker/connect: Connect to running Docker container `n8n-shortlink`
docker/connect:
docker exec -it n8n-shortlink sh
.PHONY: docker/connect
# ------------
# vps
# ------------
## vps/login: Log in to VPS
vps/login:
ssh n8n-shortlink-infra
.PHONY: vps/login
## vps/caddy/logs: Tail Caddy logs
vps/caddy/logs:
ssh n8n-shortlink-infra 'journalctl -u caddy -f'
.PHONY: vps/caddy/logs
## vps/logs/app: Tail app container logs
vps/app/logs:
ssh n8n-shortlink-infra 'docker logs -f n8n-shortlink'
.PHONY: vps/app/logs