-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (84 loc) · 2.94 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
.PHONY: lint install build run-server run-db stop-db reset-db test-db remove-db attach-db codegen
# Lint the code with golangci-lint
lint:
make fmt; \
if ! [ -x "$$(command -v golangci-lint)" ]; then \
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:latest golangci-lint run -v; \
else \
golangci-lint run --config configs/golangci/golangci.yml; \
fi
# Install requirements
install:
go mod download
go mod tidy
# Build the server executable
VERSION=$(shell git describe --tags --always)
LDVERSION=-X 'ctf01d/internal/handler.version=$(VERSION)'
BUILDTIME=$(shell date -R)
LDBUILDTIME=-X 'ctf01d/internal/handler.buildTime=$(BUILDTIME)'
server-build:
go build -ldflags "$(LDVERSION) $(LDBUILDTIME)" -o server ./cmd/main.go
# Run the local development server
server-run:
go run cmd/main.go
# Format go files
fmt:
go fmt ./internal/...; \
go fmt ./cmd/...;
# Run PostgreSQL container for local development
database-run:
@if [ $$(docker ps -a -q -f name=ctf01d-postgres) ]; then \
echo "Container ctf01d-postgres already exists. Restarting..."; \
docker start ctf01d-postgres; \
else \
echo "Creating and starting container ctf01d-postgres..."; \
docker run --rm -d \
-v $(PWD)/docker_tmp/pg_data:/var/lib/postgresql/data/ \
--name ctf01d-postgres \
-e POSTGRES_DB=ctf01d_training_platform \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e PGPORT=4112 \
-p 4112:4112 postgres:16.4; \
fi
# Attach to the running PostgreSQL container
database-attach:
docker exec -it ctf01d-postgres psql -U postgres -d ctf01d_training_platform
# Stop PostgreSQL container
database-stop:
@if [ $$(docker ps -q -f name=ctf01d-postgres) ]; then \
echo "Stopping container ctf01d-postgres..."; \
docker stop ctf01d-postgres; \
else \
echo "Container ctf01d-postgres is not running."; \
fi
# Cleanup db and restart db and rebuild main app
database-reset:
make stop-db; \
sudo rm -rf docker_tmp/pg_data; \
make run-db; \
make build;
# Remove PostgreSQL container
database-remove:
@if [ $$(docker ps -a -q -f name=ctf01d-postgres) ]; then \
echo "Removing container ctf01d-postgres..."; \
docker rm -f ctf01d-postgres; \
else \
echo "Container ctf01d-postgres does not exist."; \
fi
# Setup test database and run tests
test:
# Ensure the PostgreSQL container is running
@if ! [ $$(docker ps -q -f name=ctf01d-postgres) ]; then \
echo "Starting PostgreSQL container..."; \
docker start ctf01d-postgres; \
fi
# Remove test database if it exists
@docker exec -it ctf01d-postgres psql -U postgres -c "DROP DATABASE IF EXISTS ctf01d_training_platform_test;"
# Create a new test database
@docker exec -it ctf01d-postgres psql -U postgres -c "CREATE DATABASE ctf01d_training_platform_test;"
# Run the tests
@go test -v ./test/server_integration_test.go
# Generate Go server boilerplate from OpenAPI 3
codegen:
oapi-codegen -generate models,chi -o internal/httpserver/httpserver.gen.go --package httpserver api/openapi.yaml