Files
abuse-registration-api-golang/Taskfile.yml
T
2026-06-29 23:29:33 +01:00

102 lines
3.9 KiB
YAML

version: '3'
vars:
SERVER: bl@flo-homeserver
REMOTE_MACHINE: bl@flo-homeserver
PKG: main
BINARY_DIR: ./bin
DEV_BINARY_DIR: ./local
SHORT_SHA:
sh: git rev-parse --short HEAD 2>/dev/null || echo nogit
BRANCH:
sh: git rev-parse --abbrev-ref HEAD 2>/dev/null || echo local
DIRTY:
sh: if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then if git diff --quiet && git diff --cached --quiet; then echo clean; else echo dirty; fi; else echo clean; fi
RANDOM_WORDS:
sh: if [ -f build/words.txt ]; then awk 'BEGIN{srand()} /^[[:lower:]]+$/ && length($0) >= 4 && length($0) <= 10 { words[++n]=$0 } END { if (n < 1) { print "word-list"; exit } print words[int(rand()*n)+1] "-" words[int(rand()*n)+1] }' build/words.txt; else echo word-list; fi
VERSION_STR: "version [{{.SHORT_SHA}}-{{.BRANCH}}/{{.RANDOM_WORDS}}]. git is [{{.DIRTY}}]."
LD_FLAGS: "-X '{{.PKG}}.Version={{.VERSION_STR}}'"
BINARY_API: "{{.BINARY_DIR}}/go-api"
DEV_BINARY_API: "{{.DEV_BINARY_DIR}}/go-api/"
tasks:
# ── Build ──────────────────────────────────────────────────────────────────
build:
desc: runs vet, fmt, and build api
deps: [vet, fmt, build-api]
build-api:
desc: clean, then build api bin
cmds:
- go tool task clean-api
- mkdir -p {{.BINARY_DIR}}
- echo "building {{.BINARY_API}} with version {{.VERSION_STR}}"
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "{{.LD_FLAGS}}" -o {{.BINARY_API}} ./cmd/api
# ── DEV Build ──────────────────────────────────────────────────────────────
dev-build:
desc: runs DEV for vet, fmt, and build DEV api
deps: [vet, fmt, dev-build-api]
dev-build-api:
desc: clean, then build DEV api bin
cmds:
- go tool task dev-clean-api
- mkdir -p {{.DEV_BINARY_API}}
- echo "building DEV {{.DEV_BINARY_API}} with version {{.VERSION_STR}}"
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "{{.LD_FLAGS}}" -o {{.DEV_BINARY_API}}/go-api ./cmd/api
# ── Deploy individual ──────────────────────────────────────────────────────
deploy-api:
desc: build api, stage files, and deploy api to remote server
deps: [build-api]
cmds:
- ssh {{.REMOTE_MACHINE}} "rm -rf /tmp/go-api-deploy && mkdir -p /tmp/go-api-deploy"
- rsync -avz --delete {{.BINARY_API}} {{.REMOTE_MACHINE}}:/tmp/go-api-deploy/
- ssh -t {{.REMOTE_MACHINE}} "sudo rsync -a --delete --exclude='.env' --exclude='config.json' --exclude='data/' --chown=go-api:go-api /tmp/go-api-deploy/ /opt/go-api/ && sudo systemctl restart go-api"
- ssh {{.REMOTE_MACHINE}} "rm -rf /tmp/go-api-deploy"
# ── DEV START individual ──────────────────────────────────────────────────
dev-start-api:
desc: build api, create dirs, and start DEV api binary
dir: "{{ .DEV_BINARY_API }}"
cmds:
- "rm -rf *"
- go tool task dev-build-api
- "./go-api"
run:
desc: run the POC API locally on :8080 by default
cmds:
- go run ./cmd/api
# ── Helpers ────────────────────────────────────────────────────────────────
vet:
cmds:
- go vet ./...
fmt:
cmds:
- go fmt ./...
test:
cmds:
- go test ./...
clean:
deps: [clean-api]
clean-api:
cmds:
- rm -f {{.BINARY_API}}
dev-clean-api:
cmds:
- rm -f {{.DEV_BINARY_API}}/go-api