askar-website/Makefile

94 lines
2.5 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
REMOTE_DB_DUMP = ./out/remote.dump.sql
WWW_USER ?= 33
WWW_GROUP ?= 33
dev-run:
$(COMPOSE) up
dev-run-db:
$(COMPOSE) run --rm db
dev-stop:
$(COMPOSE) down
dev-clean:
$(COMPOSE) down --volumes
dev-dump:
mariadb-dump $(DUMP_CONN) askar > $(VERSIONED_DUMP)
dev-import-db:
cat $(REMOTE_DB_DUMP) |\
sed -e 's;$(PUBLIC_URL);http://localhost:8080;g' |\
grep -v -E '^/\*' |\
(echo "SET sql_mode = '';" && cat) > ./assets/db/dump.sql
dev-import-website:
sudo tar zxvf ./out/remote.uploads.tar.gz -C ./assets/wordpress/wp-content/
sudo tar zxvf ./out/remote.plugins.tar.gz -C ./assets/wordpress/wp-content/
sudo chown $(WWW_USER):$(WWW_GROUP) -R ./assets/wordpress/wp-content/
./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 $(REMOTE_DB_DATABASE) > $(REMOTE_DB_DUMP)
_pull-%:
ssh $(REMOTE_WEB_HOST) tar czvf - -C $(REMOTE_WEB_ROOT) $* > ./out/remote.$*.tar.gz
pull-website: _pull-uploads _pull-plugins
clean:
rm ./out/*