fork/chhoto-url

git clone https://git.julia.blue/fork/chhoto-url

SinTan1729site: Use /tmp for minification0815641

unicode
4.4 KiB127 linesraw
1# SPDX-FileCopyrightText: 2023-2026 Sayantan Santra <sayantan.santra689@gmail.com>
2# SPDX-License-Identifier: MIT
3
4include .env
5
6.PHONY: clean test setup merge tag reset-db upgrade-deps upgrade-deps-pre podman-stop
7.PHONY: build podman-build podman-run podman-test
8.PHONY: build-release podman-build-release podman-run-release podman-test-release
9.PHONY: minify deploy purge-cache publish
10
11setup:
12	rustup target add x86_64-unknown-linux-musl
13	podman buildx inspect --bootstrap
14
15merge:
16	git switch main
17	git merge dev
18	git switch dev
19
20short_sha := $(shell git rev-parse --short HEAD) 
21build:
22	CARGO_GIT_COMMIT=${short_sha} cargo build --locked --manifest-path=backend/Cargo.toml \
23		--target x86_64-unknown-linux-musl
24build-release:
25	CARGO_GIT_COMMIT=${short_sha} cargo build --release --locked --manifest-path=backend/Cargo.toml \
26		--target x86_64-unknown-linux-musl
27test:
28	cargo audit --file backend/Cargo.lock || true
29	CARGO_GIT_COMMIT=${short_sha} cargo test --locked --manifest-path=backend/Cargo.toml \
30		--target x86_64-unknown-linux-musl
31
32podman-clean:
33	podman image prune -f
34podman-build: build
35	podman build --tag chhoto-url:debug -f deploy/Containerfile.debug .
36podman-build-release: build-release
37	podman build --tag chhoto-url:release --build-arg TARGETARCH=amd64 -f deploy/Containerfile.alpine .
38
39podman-stop:
40	podman ps -q --filter "name=chhoto-url" | xargs -r podman stop
41	podman ps -aq --filter "name=chhoto-url" | xargs -r podman rm
42
43podman-run: podman-stop
44	podman run -t -p ${CHHOTO_LISTEN_PORT}:${CHHOTO_LISTEN_PORT} --name chhoto-url \
45		--cap-drop=ALL --env-file ./.env -v "${DB_DIR}:/data" -v "./frontend:/app/frontend/base" -d chhoto-url:debug
46	podman logs chhoto-url -f 
47podman-run-release: podman-stop
48	podman run -t -p ${CHHOTO_LISTEN_PORT}:${CHHOTO_LISTEN_PORT} --name chhoto-url \
49		--cap-drop=ALL --env-file ./.env -v "${DB_DIR}:/data" -d chhoto-url:release
50	podman logs chhoto-url -f 
51
52reset-db: podman-stop
53	rm -f testing-data/urls.sqlite-shm testing-data/urls.sqlite-wal
54	cp testing-data/urls1.sqlite testing-data/urls.sqlite
55podman-test: test podman-build podman-clean podman-run
56podman-test-release: test podman-build-release podman-clean podman-run-release
57
58upgrade-deps-pre:
59	cargo upgrade --manifest-path=backend/Cargo.toml --verbose
60	cargo update --manifest-path=backend/Cargo.toml --verbose
61	git add backend/Cargo.{toml,lock}
62	git commit -m "chore: Updated deps"
63upgrade-deps: upgrade-deps-pre test
64
65conf_tag := $(shell cat backend/Cargo.toml | sed -rn 's/^version = "(.+)"$$/\1/p')
66last_tag := $(shell git describe --tags --abbrev=0)
67bumped := $(shell git log -1 --pretty=%B | grep "build: Bumped version to " | wc -l)
68uncommitted := $(shell git status --porcelain=v1 2>/dev/null | wc -l)
69upgrade-version:
70	cargo update --manifest-path=backend/Cargo.toml -p chhoto-url --verbose
71	git add backend/Cargo.{toml,lock}
72	git commit -m "build: Bumped version to ${conf_tag}"
73
74tag:
75ifeq (${bumped}, 1)
76ifneq (${uncommitted}, 0)
77	false;
78endif
79ifneq (${conf_tag}, ${last_tag})
80	git tag ${conf_tag} -m "Version ${conf_tag}"
81endif
82else
83	false;
84endif
85
86clean: podman-stop
87	@echo "Cleaning up..."
88	cargo clean --manifest-path=backend/Cargo.toml
89
90minify:
91	rm -rf "/tmp/chhoto-url-site/"
92	@echo "Minifying resources..."
93	minify -rs "./site/" -o "/tmp/chhoto-url-site/"
94	find /tmp/chhoto-url-site/ -type f -regextype egrep -not -regex '.+\.(html|js|css|svg|ico|png|webp)' -delete
95
96deploy: minify
97	@echo "Deploying website for public access..."
98	rsync -aAXhP --delete "/tmp/chhoto-url-site/" "vps-rsync:/home/admin/podman/chhoto-url/landing/"
99
100purge-cache:
101	@set -e; \
102	token="$$(cat "$$HOME/.config/cloudflare_cache_purge_token")"; \
103	zone_id="$$(curl -fsS \
104		"https://api.cloudflare.com/client/v4/zones?name=chhoto.link" \
105		-H "Authorization: Bearer $$token" \
106		| jq -r '.result[0].id')"; \
107	if [ -z "$$zone_id" ] || [ "$$zone_id" = "null" ]; then \
108		echo "Failed to find Cloudflare zone for chhoto.link" >&2; \
109		exit 1; \
110	fi; \
111	response="$$(curl -fsS \
112		-X POST \
113		"https://api.cloudflare.com/client/v4/zones/$$zone_id/purge_cache" \
114		-H "Authorization: Bearer $$token" \
115		-H "Content-Type: application/json" \
116		--data '{"hosts":["chhoto.link"]}')"; \
117	if ! printf '%s\n' "$$response" | jq -e '.success == true' >/dev/null; then \
118		echo "Cloudflare cache purge failed:" >&2; \
119		printf '%s\n' "$$response" | jq . >&2; \
120		exit 1; \
121	fi; \
122	echo "Cloudflare cache purged for chhoto.link"
123
124publish: deploy purge-cache
125	rm -rf "/tmp/chhoto-url-site/"
126	@echo "Done!"
127