mont58-theme/makefile

192 lines
6.4 KiB
Makefile
Raw Normal View History

2024-05-08 20:03:17 +00:00
include .env
.PHONY: up down stop prune ps shell shell_root wp logs
default: up
#######################################
# Variable admin
#######################################
REQUIRED_BINS := docker
$(foreach bin,$(REQUIRED_BINS),\
$(if $(shell command -v $(bin) 2> /dev/null),$(true),$(error Please install `$(bin)`)))
ifeq ($(SITE_URL),)
$(error SITE_URL is not set)
endif
ABRA ?= abra
DOCKER_COMPOSE ?= docker-compose
ifeq ($(DOCKER_SUDO), 1)
DOCKER = sudo docker
_DOCKER_COMPOSE = sudo $(DOCKER_COMPOSE)
else
DOCKER = docker
_DOCKER_COMPOSE = $(DOCKER_COMPOSE)
endif
#######################################
# Core commands
#######################################
## Start up containers.
up:
@echo "Starting up containers for $(PROJECT_NAME)..."
$(_DOCKER_COMPOSE) pull
$(_DOCKER_COMPOSE) up -d --remove-orphans
## Stop containers.
down: stop
## Start containers without updating.
start:
@echo "Starting containers for $(PROJECT_NAME) from where you left off..."
@$(_DOCKER_COMPOSE) start
## Stop containers.
stop:
@echo "Stopping containers for $(PROJECT_NAME)..."
@$(_DOCKER_COMPOSE) stop
## Remove containers and their volumes.
## You can optionally pass an argument with the service name to prune single container
prune:
@echo "Removing containers for $(PROJECT_NAME)..."
@$(_DOCKER_COMPOSE) down -v $(filter-out $@,$(MAKECMDGOALS))
ps:
@$(_DOCKER_COMPOSE) ps
shell:
@$(_DOCKER_COMPOSE) exec -u user wordpress bash
shell_root:
@$(_DOCKER_COMPOSE) exec wordpress bash
## Executes `wp cli`
## Doesn't support --flag arguments.
wp:
$(_DOCKER_COMPOSE) exec -u user wordpress wp $(filter-out $@,$(MAKECMDGOALS))
## composer
## Doesn't support --flag arguments.
composer:
$(_DOCKER_COMPOSE) exec -u user wordpress composer $(filter-out $@,$(MAKECMDGOALS))
## Show vontainers' logs
## You can optinally pass an argument with the service name to limit logs
logs:
@$(_DOCKER_COMPOSE) logs -f $(filter-out $@,$(MAKECMDGOALS))
## Check that all required variables are defined
check:
@echo "$$(tput setaf 125)Watch out for any lines starting '-', which indicate settings in .env.sample which aren't in .env$$(tput sgr0)"
diff -u <(grep -v '^#' .env.sample | grep -v '^$$' | sed -e 's/=.*//g' | sort) <(grep -v '^#' .env | grep -v '^$$' | sed -e 's/=.*//g' | sort) || true
@echo "$$(tput setaf 125)The following command shouldn't show any differences; if it does, re-copy WORDPRESS_CONFIG_EXTRA fr4om .env.sample to .env$$(tput sgr0)"
diff -wu <(grep 'CONFIG_EXTRA' .env.sample ) <(grep 'CONFIG_EXTRA' .env)
#######################################
# Content management
#######################################
## Download wp-content files from site
uploads_fetch:
@echo -n "About to download ~1.5GB of data, overwriting existing data/uploads.tar.gz. - are you sure? [Y/n] " && read ans && if [ $${ans:-'Y'} = 'n' ]; then \
printf $(_ERROR) "Aborting as requested\n"; \
exit 1 ; \
else \
printf $(_SUCCESS) "OK" "Continuing" ; \
$(ABRA) app run --no-tty $(SITE_URL) app tar --owner=0 --group=0 --no-same-owner --no-same-permissions -czf- /var/www/html/wp-content/uploads/ > data/uploads.tar.gz; \
fi
## Load latest wp-content from data/uploads.tar.gz
uploads_load:
tar -C wp-content --strip-components=4 -xzf data/uploads.tar.gz
2024-06-10 17:36:42 +00:00
## Sync wp-content from site
uploads_pull: uploads_fetch uploads_load
2024-05-08 20:03:17 +00:00
2024-07-16 22:27:36 +00:00
fetch_db_info:
ssh -p$(SSH_PORT) $(SSH_USER)@$(SSH_HOST) grep DB $(SSH_PATH)/wp-config.php
2024-05-08 20:03:17 +00:00
## Download database from dev site
db_fetch:
2024-07-16 22:27:36 +00:00
ssh -p$(SSH_PORT) autonomic@web1.mont58coffee.com mysqldump -u $(DB_USER) -p$(DB_PASSWORD) "$(DB_NAME)" | gzip > data/dbdump.sql.gz
2024-05-08 20:03:17 +00:00
## Load latest database from ~/.abra/backups
db_load:
zcat data/dbdump.sql.gz | $(_DOCKER_COMPOSE) exec -T db mysql -u wordpress -pwordpress wordpress
2024-07-16 22:27:36 +00:00
db_pull: db_fetch db_load fix_url
define SQL_HEADER
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
endef
export SQL_HEADER
define SQL_FOOTER
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
endef
export SQL_FOOTER
db_convert:
gunzip data/database.sql.gz
sed -i -e 's/SERVMASK_PREFIX/wp/g' -e 's/,0x,/,0,/g' data/database.sql
echo "$$SQL_HEADER" | cat - data/database.sql > data/database_wrapped.sql
echo "$$SQL_FOOTER" >> data/database_wrapped.sql
mv data/database_wrapped.sql data/database.sql
2024-05-08 20:03:17 +00:00
## Replace site URL
fix_url:
$(_DOCKER_COMPOSE) exec -u user wordpress wp --url=https://$(SITE_URL) search-replace --all-tables-with-prefix 'https://$(SITE_URL)' 'http://$(PROJECT_NAME).localhost'
$(_DOCKER_COMPOSE) exec -u user wordpress wp --url=https://$(SITE_URL) search-replace --all-tables-with-prefix '$(SITE_URL)' '$(PROJECT_NAME).localhost'
set_local_password:
$(_DOCKER_COMPOSE) exec -u user wordpress wp user update $(USERNAME) --user_pass=password
2024-05-08 20:03:17 +00:00
2024-07-16 22:27:36 +00:00
plugins_pull:
rsync -Pavz -e 'ssh -p$(SSH_PORT)' $(SSH_USER)@$(SSH_HOST):$(SSH_PATH)/wp-content/plugins/ wp-content/plugins/
2024-05-08 20:03:17 +00:00
2024-06-10 17:36:42 +00:00
## Download parent theme from site
theme_fetch:
$(ABRA) app run --no-tty $(SITE_URL) app tar --owner=0 --group=0 --no-same-owner --no-same-permissions -czf- /var/www/html/wp-content/themes/bridge > data/theme.tar.gz
## Load theme
theme_load:
tar -C wp-content --strip-components=4 -xzf data/theme.tar.gz
## Sync wp-content from site
theme_pull: theme_fetch theme_load
2024-07-10 23:40:10 +00:00
#######################################
# Releases
#######################################
# Generate ZIP of theme
theme_export:
cd wp-content/themes/mont58-coffee/ && zip -r ../../../data/mont58-theme_2024-07-09.zip . && cd -
2024-05-08 20:03:17 +00:00
# "Arguments" for makefiles..
# https://stackoverflow.com/a/6273809/1826109
%: