askar-website/Makefile

73 lines
2.1 KiB
Makefile

DOCKER ?= docker
COMPOSE ?= docker compose
PUBLIC_URL ?= https://askar.abbiamoundominio.org
TMPDB_CONN = --host=127.0.0.1 --port=3307 --user=root --password=toor --ssl-verify-server-cert=FALSE
DUMP_CONN = -h 127.0.0.1 -P 3306 --user root --password=toor --ssl-verify-server-cert=FALSE
VERSIONED_DUMP = ./assets/db/dump.sql
TMP_PROD_DUMP = ./out/db.tmp.sql
PROD_DUMP = ./out/dump.sql
dev-run:
$(COMPOSE) up
dev-stop:
$(COMPOSE) down
dev-clean:
$(COMPOSE) down --volumes
dev-dump:
mariadb-dump $(DUMP_CONN) askar > $(VERSIONED_DUMP)
./out:
mkdir ./out
prepare: ./out prepare-image prepare-db
prepare-image:
$(DOCKER) build -t unit/askar-website .
$(DOCKER) image save -o out/image.tar unit/askar-website
tmpdb-start:
$(DOCKER) run -d --rm --name tmpdb \
-p 3307:3306 \
-e MYSQL_DATABASE=askar \
-e MYSQL_USER=askar \
-e MYSQL_PASSWORD=askar \
-e MYSQL_ROOT_PASSWORD=toor \
mysql:8
while ! mariadb-admin ping $(TMPDB_CONN); do sleep 1; done
tmpdb-stop:
$(DOCKER) stop tmpdb
tmpdb-do-dump:
cat $(VERSIONED_DUMP) | sed -e 's;http://localhost:8080;$(PUBLIC_URL);g' > $(TMP_PROD_DUMP)
cat $(TMP_PROD_DUMP) | grep -v -E '^/\*' | (echo "SET sql_mode = '';" && cat) | mariadb $(TMPDB_CONN) askar
mariadb-dump --default-character-set=binary --hex-blob $(TMPDB_CONN) askar | grep -v -E '^/\*' > $(PROD_DUMP)
prepare-db: tmpdb-start tmpdb-do-dump tmpdb-stop
prepare-%:
tar czvf ./out/$*.tar.gz -C ./assets/wordpress/wp-content/$*
prepare-data: prepare-uploads prepare-plugins
prepare-export: prepare-db prepare-data
push-db:
cat $(PROD_DUMP) | ssh $(REMOTE_DB_HOST) mysql --user $(REMOTE_DB_USER) --password $$(age -d ./assets/admin.pass.age) $(REMOTE_DB_DATABASE)
_push-%:
cat ./out/$*.tar.gz | ssh $(REMOTE_WEB_HOST) tar zxvf -C $(REMOTE_WEB_ROOT) -
push-website: _push-uploads _push-plugins
pull-db:
ssh $(REMOTE_DB_HOST) mysqldump --user $(REMOTE_DB_USER) --password $$(age -d ./assets/admin.pass.age) $(REMOTE_DB_DATABASE) > ./out/remote.dump.sql
_pull-%:
ssh $(REMOTE_WEB_HOST) tar czvf - -C $(REMOTE_WEB_ROOT) $* > ./out/remote.$*.tar.gz
pull-website: _pull-uploads _pull-plugins