repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

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