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