askar-website/Makefile

94 lines
2.6 KiB
Makefile
Raw Normal View History

2024-07-17 22:49:32 +02:00
DOCKER ?= docker
COMPOSE ?= docker compose
2024-07-31 23:30:29 +02:00
PUBLIC_URL ?= https://askar-association-ps.org
2024-07-19 23:59:23 +02:00
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
2024-07-31 00:34:55 +02:00
REMOTE_DB_DUMP = ./out/remote.dump.sql
WWW_USER ?= 33
WWW_GROUP ?= 33
2024-07-17 22:49:32 +02:00
dev-run:
$(COMPOSE) up
2024-07-31 00:34:55 +02:00
dev-run-db:
$(COMPOSE) run --rm db
2024-07-17 22:49:32 +02:00
dev-stop:
$(COMPOSE) down
dev-clean:
$(COMPOSE) down --volumes
2024-07-17 22:58:28 +02:00
dev-dump:
2024-07-19 23:59:23 +02:00
mariadb-dump $(DUMP_CONN) askar > $(VERSIONED_DUMP)
2024-07-17 22:58:28 +02:00
2024-07-31 00:34:55 +02:00
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/
2024-07-17 22:58:28 +02:00
./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
2024-07-19 23:59:23 +02:00
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
2024-07-20 00:17:18 +02:00
2024-07-31 23:30:29 +02:00
_prepare-%:
tar -C ./assets/wordpress/wp-content/ ./$* -czvf ./out/$*.tar.gz
2024-07-20 00:17:18 +02:00
2024-07-31 23:30:29 +02:00
prepare-data: _prepare-uploads _prepare-plugins
2024-07-20 00:17:18 +02:00
prepare-export: prepare-db prepare-data
push-db:
2024-07-31 23:30:29 +02:00
cat $(PROD_DUMP) | ssh $(REMOTE_DB_HOST) mysql --user=$(REMOTE_DB_USER) --password=\'$$(age -d ./assets/db.prod.pass.age)\' $(REMOTE_DB_DATABASE)
2024-07-20 00:17:18 +02:00
_push-%:
2024-07-31 23:30:29 +02:00
cat ./out/$*.tar.gz | ssh $(REMOTE_WEB_HOST) tar -C $(REMOTE_WEB_ROOT) -zxvf -
2024-07-20 00:17:18 +02:00
push-website: _push-uploads _push-plugins
pull-db:
2024-07-31 00:34:55 +02:00
ssh $(REMOTE_DB_HOST) mysqldump $(REMOTE_DB_DATABASE) > $(REMOTE_DB_DUMP)
2024-07-20 00:17:18 +02:00
_pull-%:
ssh $(REMOTE_WEB_HOST) tar czvf - -C $(REMOTE_WEB_ROOT) $* > ./out/remote.$*.tar.gz
pull-website: _pull-uploads _pull-plugins
2024-07-31 00:34:55 +02:00
clean:
rm ./out/*