Eric Bower
·
11 Nov 24
Makefile
1PGDATABASE?="pico"
2PGHOST?="db"
3PGUSER?="postgres"
4PORT?="5432"
5DB_CONTAINER?=pico-postgres-1
6DOCKER_TAG?=$(shell git log --format="%H" -n 1)
7DOCKER_PLATFORM?=linux/amd64,linux/arm64
8DOCKER_CMD?=docker
9DOCKER_BUILDX_BUILD?=$(DOCKER_CMD) buildx build --push --platform $(DOCKER_PLATFORM)
10WRITE?=0
11
12smol:
13 curl https://pico.sh/smol.css -o ./prose/public/smol-v2.css
14 cat ./prose/artifacts/main.css >> ./prose/public/smol-v2.css
15 curl https://pico.sh/smol.css -o ./pastes/public/smol.css
16.PHONY: smol
17
18css:
19 cp ./syntax.css pastes/public/syntax.css
20 cp ./syntax.css prose/public/syntax.css
21.PHONY: css
22
23lint:
24 golangci-lint run -E goimports -E godot --timeout 10m
25.PHONY: lint
26
27test:
28 go test ./...
29.PHONY: test
30
31bp-setup:
32 $(DOCKER_CMD) buildx ls | grep pico || $(DOCKER_CMD) buildx create --name pico
33 $(DOCKER_CMD) buildx use pico
34.PHONY: bp-setup
35
36bp-caddy: bp-setup
37 $(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/caddy:$(DOCKER_TAG) ./caddy
38.PHONY: bp-caddy
39
40bp-auth: bp-setup
41 $(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/auth-web:$(DOCKER_TAG) --build-arg APP=auth --target release-web .
42.PHONY: bp-auth
43
44bp-pico: bp-setup
45 $(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/pico-ssh:$(DOCKER_TAG) --build-arg APP=pico --target release-ssh .
46.PHONY: bp-auth
47
48bp-bouncer: bp-setup
49 $(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/bouncer:$(DOCKER_TAG) ./bouncer
50.PHONY: bp-bouncer
51
52bp-ssh-%: bp-setup
53 $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "ghcr.io/picosh/pico/$*-ssh:$(DOCKER_TAG)" --target release-ssh .
54.PHONY: pgs-ssh
55
56bp-%: bp-setup
57 $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "ghcr.io/picosh/pico/$*-ssh:$(DOCKER_TAG)" --target release-ssh .
58 $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "ghcr.io/picosh/pico/$*-web:$(DOCKER_TAG)" --target release-web .
59.PHONY: bp-%
60
61bp-all: bp-prose bp-pastes bp-imgs bp-feeds bp-pgs bp-auth bp-bouncer bp-pipe
62.PHONY: bp-all
63
64build-auth:
65 go build -o "build/auth" "./cmd/auth/web"
66.PHONY: build-auth
67
68build-pico:
69 go build -o "build/pico-ssh" "./cmd/pico/ssh"
70.PHONY: build-auth
71
72build-%:
73 go build -o "build/$*-web" "./cmd/$*/web"
74 go build -o "build/$*-ssh" "./cmd/$*/ssh"
75.PHONY: build-%
76
77build: build-prose build-pastes build-imgs build-feeds build-pgs build-auth build-pico build-pipe
78.PHONY: build
79
80store-clean:
81 WRITE=$(WRITE) go run ./cmd/scripts/clean-object-store/clean.go
82.PHONY: store-clean
83
84pico-plus:
85 # USER=picouser PTYPE=stripe TXID=pi_xxx make pico-plus
86 # USER=picouser PTYPE=snail make pico-plus
87 # USER=picouser make pico-plus
88 go run ./cmd/scripts/pico-plus/main.go $(USER) $(PTYPE) $(TXID)
89.PHONY: pico-plus
90
91scripts:
92 # might need to set MINIO_URL
93 docker run --rm -it --env-file .env -v $(shell pwd):/app -w /app golang:1.23 /bin/bash
94.PHONY: scripts
95
96fmt:
97 go fmt ./...
98.PHONY: format
99
100create:
101 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) < ./sql/setup.sql
102.PHONY: create
103
104teardown:
105 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/teardown.sql
106.PHONY: teardown
107
108migrate:
109 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220310_init.sql
110 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220422_add_desc_to_user_and_post.sql
111 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220426_add_index_for_filename.sql
112 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220427_username_to_lower.sql
113 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220523_timestamp_with_tz.sql
114 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220721_analytics.sql
115 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220722_post_hidden.sql
116 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220727_post_change_post_contraints.sql
117 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220730_post_change_filename_to_slug.sql
118 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220801_add_post_tags.sql
119 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220811_add_data_to_post.sql
120 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20220811_add_feature.sql
121 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20221108_add_expires_at_to_posts.sql
122 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20221112_add_feeds_space.sql
123 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20230310_add_aliases_table.sql
124 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20230326_add_feed_items.sql
125 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20230707_add_projects_table.sql
126 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20230921_add_tokens_table.sql
127 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240120_add_payment_history.sql
128 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240221_add_project_acl.sql
129 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240311_add_public_key_name.sql
130 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
131 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
132 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20241028_add_analytics_indexes.sql
133 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20241114_add_namespace_to_analytics.sql
134.PHONY: migrate
135
136latest:
137 $(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20241114_add_namespace_to_analytics.sql
138.PHONY: latest
139
140psql:
141 $(DOCKER_CMD) exec -it $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE)
142.PHONY: psql
143
144dump:
145 $(DOCKER_CMD) exec -it $(DB_CONTAINER) pg_dump -U $(PGUSER) $(PGDATABASE) > ./backup.sql
146.PHONY: dump
147
148restore:
149 $(DOCKER_CMD) cp ./backup.sql $(DB_CONTAINER):/backup.sql
150 $(DOCKER_CMD) exec -it $(DB_CONTAINER) /bin/bash
151 # psql postgres -U postgres -d pico < /backup.sql
152.PHONY: restore
153
154registry-clean:
155 # https://github.com/distribution/distribution/issues/3200#issuecomment-671062638
156 # NOTICE: if using s3 you need an empty file inside:
157 # - `imgs/docker/registry/v2/repositories` and
158 # - `imgs/docker/registry/v2/blobs`
159 docker compose exec registry bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged
160.PHONY: registry-clean