forked from code-golf/code-golf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (115 loc) · 3.96 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
GOFILES := $(shell find . -name '*.go' ! -path './.go*')
POSTGRES := postgres:13.3-alpine
SHELL := /bin/bash
export COMPOSE_PATH_SEPARATOR=:
export COMPOSE_FILE=docker/core.yml:docker/dev.yml
define STUB
package routes
import "net/http"
const holeJsPath = ""
func Asset(w http.ResponseWriter, r *http.Request) {}
endef
bench:
# FIXME Stub out assets if it doesn't yet exist.
ifeq ($(wildcard routes/assets.go),)
$(file > routes/assets.go, $(STUB))
endif
@go test -bench B -benchmem ./...
bump:
@go get -u
@go mod tidy
@npm upgrade
cert:
@mkcert -install localhost
@chmod +r localhost-key.pem
.PHONY: db
db:
@ssh -t rancher@code.golf docker run -it --rm \
--env-file /etc/code-golf.env $(POSTGRES) psql
db-admin:
@ssh -t rancher@code.golf docker run -it --rm \
--env-file /etc/code-golf.env $(POSTGRES) psql -WU doadmin
db-dev:
@docker-compose exec db psql -U postgres code-golf
db-diff:
@diff --color --label live --label dev --strip-trailing-cr -su \
<(ssh rancher@code.golf "docker run --rm \
--env-file /etc/code-golf.env $(POSTGRES) pg_dump -Os") \
<(docker-compose exec db pg_dump -OsU postgres code-golf)
db-dump:
@rm -f db/*.gz
@ssh rancher@code.golf "docker run --env-file /etc/code-golf.env \
--rm $(POSTGRES) sh -c 'pg_dump -a | gzip -9'" \
> db/code-golf-`date +%Y-%m-%d`.sql.gz
@cp db/*.gz ~/Dropbox/code-golf/
deps:
@yay -S mkcert python-brotli python-fonttools
dev:
@touch docker/.env
@docker-compose rm -f
@docker-compose up --build
# e2e-iterate is useful when you have made a small change to test code only and want to re-run.
# Note that logs are not automatically shown when tests fail, because they make it harder to see
# test results and this target isn't used by CI.
e2e-iterate: export COMPOSE_FILE = docker/core.yml:docker/e2e.yml
e2e-iterate: export COMPOSE_PROJECT_NAME = code-golf-e2e
e2e-iterate:
@docker-compose run e2e
e2e: export COMPOSE_FILE = docker/core.yml:docker/e2e.yml
e2e: export COMPOSE_PROJECT_NAME = code-golf-e2e
e2e:
# TODO Pass arguments to run specific tests.
@./esbuild
@./build-assets --force
@touch docker/.env
@docker-compose rm -fsv &>/dev/null
@docker-compose pull -q
@docker-compose build -q
@docker-compose run e2e || (docker-compose logs; false)
@docker-compose rm -fsv &>/dev/null
fmt:
@gofmt -s -w $(GOFILES)
@goimports -w $(GOFILES)
font:
@docker build -t code-golf-font -f docker/font.Dockerfile docker
@id=`docker create code-golf-font`; \
docker cp "$$id:twemoji-colr/build/Twemoji Mozilla.woff2" fonts/twemoji.woff2; \
docker rm $$id
lint:
# FIXME Stub out assets if it doesn't yet exist.
ifeq ($(wildcard routes/assets.go),)
$(file > routes/assets.go, $(STUB))
endif
@docker run --rm -v $(CURDIR):/app -w /app \
golangci/golangci-lint:v1.41.1 golangci-lint run
live:
@./build-assets
@docker build --pull -f docker/live.Dockerfile -t codegolf/code-golf .
@docker push codegolf/code-golf
@ssh rancher@code.golf " \
docker pull codegolf/code-golf && \
docker stop code-golf; \
docker rm code-golf; \
docker run \
--detach \
--env-file /etc/code-golf.env \
--init \
--name code-golf \
--pids-limit 1024 \
--privileged \
--publish 80:1080 \
--publish 443:1443 \
--read-only \
--restart always \
--ulimit core=-1 \
--volume certs:/certs \
codegolf/code-golf && \
docker system prune -f"
logs:
@ssh rancher@code.golf docker logs --tail 5 -f code-golf
test:
# FIXME Stub out assets if it doesn't yet exist.
ifeq ($(wildcard routes/assets.go),)
$(file > routes/assets.go, $(STUB))
endif
@go test ./...