fork/chhoto-url
git clone https://git.julia.blue/fork/chhoto-url
0815641
unicode
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 : 12rustup target add x86_64-unknown-linux-musl 13podman buildx inspect--bootstrap 14 15merge : 16git switch main 17git merge dev 18git switch dev 19 20short_sha := $( shell git rev-parse--short HEAD) 21build : 22CARGO_GIT_COMMIT =${ short_sha } cargo build--locked --manifest-path=backend/Cargo.toml \ 23--target x86_64-unknown-linux-musl 24build-release : 25CARGO_GIT_COMMIT =${ short_sha } cargo build--release --locked --manifest-path=backend/Cargo.toml \ 26--target x86_64-unknown-linux-musl 27test : 28cargo audit--file backend/Cargo.lock ||true 29CARGO_GIT_COMMIT =${ short_sha } cargo test--locked --manifest-path=backend/Cargo.toml \ 30--target x86_64-unknown-linux-musl 31 32podman-clean : 33podman image prune-f 34podman-build : build 35podman build--tag chhoto-url:debug-f deploy/Containerfile.debug . 36podman-build-release : build-release 37podman build--tag chhoto-url:release--build-arg TARGETARCH=amd64-f deploy/Containerfile.alpine . 38 39podman-stop : 40podman ps-q --filter "name=chhoto-url" | xargs -r podman stop 41podman ps-aq --filter "name=chhoto-url" | xargs -r podman rm 42 43podman-run : podman-stop 44podman 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 46podman logs chhoto-url-f 47podman-run-release : podman-stop 48podman 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 50podman logs chhoto-url-f 51 52reset-db : podman-stop 53rm -f testing-data/urls.sqlite-shm testing-data/urls.sqlite-wal 54cp 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 : 59cargo upgrade--manifest-path=backend/Cargo.toml --verbose 60cargo update--manifest-path=backend/Cargo.toml --verbose 61git add backend/Cargo.{toml,lock} 62git 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 : 70cargo update--manifest-path=backend/Cargo.toml -p chhoto-url--verbose 71git add backend/Cargo.{toml,lock} 72git commit-m "build: Bumped version to ${ conf_tag } " 73 74tag : 75ifeq (${ bumped } , 1) 76ifneq (${ uncommitted } , 0) 77false ; 78endif 79ifneq (${ conf_tag } ,${ last_tag } ) 80git tag${ conf_tag } -m "Version ${ conf_tag } " 81endif 82else 83false ; 84endif 85 86clean : podman-stop 87@ echo "Cleaning up..." 88cargo clean--manifest-path=backend/Cargo.toml 89 90minify : 91rm -rf "/tmp/chhoto-url-site/" 92@ echo "Minifying resources..." 93minify -rs "./site/" -o "/tmp/chhoto-url-site/" 94find /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..." 98rsync -aAXhP --delete "/tmp/chhoto-url-site/" "vps-rsync:/home/admin/podman/chhoto-url/landing/" 99 100purge-cache : 101@ set -e ; \ 102token =" $ $(cat " $ $HOME/.config/cloudflare_cache_purge_token")" ; \ 103zone_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')" ; \ 107if [ -z" $ $zone_id" ] || [" $ $zone_id" ="null" ];then \ 108echo "Failed to find Cloudflare zone for chhoto.link" >&2; \ 109exit 1; \ 110fi ; \ 111response =" $ $(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"]}')" ; \ 117if !printf '%s\n' " $ $response" | jq -e '.success == true' > /dev/null;then \ 118echo "Cloudflare cache purge failed:" >&2; \ 119printf '%s\n' " $ $response" | jq . >&2; \ 120exit 1; \ 121fi ; \ 122echo "Cloudflare cache purged for chhoto.link" 123 124publish : deploy purge-cache 125rm -rf "/tmp/chhoto-url-site/" 126@ echo "Done!" 127