chore(tooling): make sure git-crypt is unlocked before building or deploying

This commit is contained in:
Julien Dessaux 2024-09-21 16:02:04 +02:00
parent 3bcdaf541f
commit bd33088807
Signed by: adyxax
GPG key ID: F92E51B86E07177E

View file

@ -10,11 +10,21 @@ OUTDIR := "."
CONTAINER_REGISTRY ?= localhost CONTAINER_REGISTRY ?= localhost
CONTAINER_TAG ?= latest CONTAINER_TAG ?= latest
DEPS := Dockerfile GNUmakefile go.mod go.sum index.html main.go ods.txt
##### Utils #################################################################### ##### Utils ####################################################################
.PHONY: confirm .PHONY: confirm
confirm: confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ] @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
.PHONY: git-crypt-unlocked
git-crypt-unlocked:
@git config --local --get filter.git-crypt.smudge >/dev/null || FAIL=1
if [[ "$${FAIL:-0}" -gt 0 ]]; then
echo "Please unlock git-crypt before continuing!"
exit 1
fi
.PHONY: help .PHONY: help
help: help:
@grep -E '^[a-zA-Z\/_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ @grep -E '^[a-zA-Z\/_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
@ -38,25 +48,23 @@ tidy: ## tidy up the code
##### Development ############################################################## ##### Development ##############################################################
.PHONY: build .PHONY: build
build: ## build the code build: ods ## build the code
CGO_ENABLED=0 go build -o $(OUTDIR)/ods ./
.PHONY: clean .PHONY: clean
clean: ## clean the code clean: ## clean the code
rm -f $(OUTDIR)/ods rm -f $(OUTDIR)/ods
.PHONY: run ods: git-crypt-unlocked $(DEPS)
CGO_ENABLED=0 go build -o $(OUTDIR)/ods ./
.PHONY: git-crypt-unlocked ## run
run: ## run the code run: ## run the code
go run ./ go run ./
.PHONY: unlock
unlock ## run git-crypt unlock
git-crypt unlock
##### Containers ############################################################### ##### Containers ###############################################################
.PHONY: container-build .PHONY: container-build
container-build: ## build the container image container-build: git-crypt-unlocked ## build the container image
printf "Dockerfile GNUmakefile go.mod go.sum index.html main.go ods.txt" | xargs shasum >checksums @printf $(DEPS) | xargs shasum >checksums
podman build \ podman build \
-v $$PWD:/usr/src/app \ -v $$PWD:/usr/src/app \
-t $(CONTAINER_REGISTRY)/ods:$(CONTAINER_TAG) \ -t $(CONTAINER_REGISTRY)/ods:$(CONTAINER_TAG) \
@ -79,6 +87,6 @@ push: tidy no-dirty check ## push changes to git remote
git push git master git push git master
.PHONY: deploy .PHONY: deploy
deploy: ## deploy changes to the production server deploy: ods ## deploy changes to the production server
rsync $(OUTDIR)/ods root@ods.adyxax.org:/srv/ods/ rsync $(OUTDIR)/ods root@ods.adyxax.org:/srv/ods/
ssh root@ods.adyxax.org "systemctl restart ods" ssh root@ods.adyxax.org "systemctl restart ods"