Initial commit
This commit is contained in:
commit
2e60d1d4cf
18
.drone.yml
Normal file
18
.drone.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: deploy main branch to live site
|
||||
steps:
|
||||
- name: docker cp deploy
|
||||
image: git.coopcloud.tech/coop-cloud/docker-cp-deploy:latest
|
||||
settings:
|
||||
host: server.example.com
|
||||
service: wordpress_example_com_app
|
||||
source: wp-content/themes/theme
|
||||
exec_pre: rm -rf /var/www/html/wp-content/themes/theme/*
|
||||
exec: composer install
|
||||
dest: /var/www/html/
|
||||
deploy_key:
|
||||
from_secret: drone_ssh_server.example.com
|
||||
when:
|
||||
branch:
|
||||
- main
|
38
.env.sample
Normal file
38
.env.sample
Normal file
@ -0,0 +1,38 @@
|
||||
##############################################################################
|
||||
# REQUIRED SETTINGS (you will need these) #
|
||||
##############################################################################
|
||||
|
||||
|
||||
##############################################################################
|
||||
# COMMON SETTINGS (you may need these) #
|
||||
##############################################################################
|
||||
|
||||
# If you don't have docker-compose, but do have newer docker, uncomment this
|
||||
#DOCKER_COMPOSE=docker compose
|
||||
|
||||
# Uncomment the following line if you need `sudo` to run Docker commands
|
||||
#DOCKER_SUDO=1
|
||||
|
||||
# Wordpress debugging
|
||||
WORDPRESS_DEBUG=1
|
||||
|
||||
##############################################################################
|
||||
# RARE SETTINGS (you probably won't need these) #
|
||||
##############################################################################
|
||||
|
||||
# Connect to a remote database
|
||||
#WORDPRESS_DB_HOST=fr.swarm.autonomic.zone
|
||||
#WORDPRESS_DB_PASSWORD="see README.md"
|
||||
|
||||
##############################################################################
|
||||
# INFINITE NERD DEPTH SETTINGS (if you're changing these, good luck!) #
|
||||
##############################################################################
|
||||
|
||||
# Docker container names, probably just needs to be set once per project
|
||||
PROJECT_NAME=foobar
|
||||
|
||||
# Site URL, also just needs to be set once per project
|
||||
SITE_URL=foobar.org
|
||||
|
||||
# Multi-site config
|
||||
#WORDPRESS_CONFIG_EXTRA="define('MULTISITE', true); define('SUBDOMAIN_INSTALL', true); define('DOMAIN_CURRENT_SITE', 'frms.localhost'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); define('SUNRISE', true);"
|
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/.env
|
||||
|
||||
/wp-content/**
|
||||
!/wp-content/themes/weareplanc/
|
||||
|
||||
/data/**
|
||||
!/data/.gitkeep
|
||||
|
||||
.vscode/
|
||||
**.tar.gz
|
||||
**.sql
|
||||
**.zip
|
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
54
docker-compose.yml
Normal file
54
docker-compose.yml
Normal file
@ -0,0 +1,54 @@
|
||||
---
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
wordpress:
|
||||
image: "wordpress:6.2.0"
|
||||
ports:
|
||||
- "80:80"
|
||||
dns: 4.2.2.4
|
||||
volumes:
|
||||
- "./entrypoint.sh:/usr/local/bin/entrypoint.sh:z"
|
||||
- "./wp-content:/var/www/html/wp-content/:z"
|
||||
- "./composer.json:/var/www/html/composer.json:z"
|
||||
- "./composer.lock:/var/www/html/composer.lock:z"
|
||||
entrypoint: ["/usr/local/bin/entrypoint.sh"]
|
||||
networks:
|
||||
- backend
|
||||
environment:
|
||||
- WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST:-db}
|
||||
- WORDPRESS_DB_USER=${WORDPRESS_DB_USER:-wordpress}
|
||||
- WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD:-wordpress}
|
||||
- WORDPRESS_DB_NAME=wordpress
|
||||
- WORDPRESS_CONFIG_EXTRA=${WORDPRESS_CONFIG_EXTRA}
|
||||
- WORDPRESS_DEBUG=${WORDPRESS_DEBUG}
|
||||
- PHP_EXTENSIONS=calendar
|
||||
- PAGER=more
|
||||
container_name: "${PROJECT_NAME}_wordpress"
|
||||
|
||||
db:
|
||||
image: "mariadb:10.6"
|
||||
volumes:
|
||||
- "${MARIADB_VOLUME:-mariadb}:/var/lib/mysql"
|
||||
networks:
|
||||
- backend
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=wordpress
|
||||
- MYSQL_DATABASE=wordpress
|
||||
- MYSQL_USER=wordpress
|
||||
- MYSQL_PASSWORD=wordpress
|
||||
container_name: "${PROJECT_NAME}_db"
|
||||
|
||||
mailhog:
|
||||
image: "mailhog/mailhog"
|
||||
networks:
|
||||
- backend
|
||||
ports:
|
||||
- "8025:8025"
|
||||
container_name: "${PROJECT_NAME}_mailhog"
|
||||
|
||||
volumes:
|
||||
mariadb:
|
||||
|
||||
networks:
|
||||
backend:
|
47
entrypoint.sh
Executable file
47
entrypoint.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -n "$PHP_EXTENSIONS" ]; then
|
||||
for extension in $PHP_EXTENSIONS; do
|
||||
if ! php -m | grep -q $extension; then
|
||||
docker-php-ext-install $PHP_EXTENSIONS
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if ! id -u "user" >/dev/null ; then
|
||||
useradd -u 1000 -m user
|
||||
mkdir /var/www/html/vendor
|
||||
chown -R user:user /var/www/html/vendor
|
||||
fi
|
||||
|
||||
if [ ! -x /usr/bin/zip ]; then
|
||||
apt update && apt install unzip
|
||||
fi
|
||||
|
||||
if [ ! -x /usr/local/bin/wp ]; then
|
||||
curl -z /usr/local/bin/wp -o /usr/local/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
||||
chmod +x /usr/local/bin/wp
|
||||
fi
|
||||
|
||||
if [ ! -x /usr/local/bin/composer ]; then
|
||||
mkdir -p /var/www/.composer
|
||||
chown user:user /var/www/.composer
|
||||
|
||||
curl https://getcomposer.org/installer -o /tmp/composer-setup.php
|
||||
php -r "if (hash_file('sha384', '/tmp/composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
|
||||
php /tmp/composer-setup.php
|
||||
rm /tmp/composer-setup.php
|
||||
|
||||
mv /var/www/html/composer.phar /usr/local/bin/composer
|
||||
fi
|
||||
|
||||
export APACHE_RUN_USER=user
|
||||
export APACHE_RUN_GROUP=user
|
||||
|
||||
if [ -n "$@" ]; then
|
||||
"$@"
|
||||
fi
|
||||
|
||||
# Upstream ENTRYPOINT
|
||||
# https://github.com/docker-library/wordpress/blob/master/php7.4/apache/Dockerfile#L120
|
||||
/usr/local/bin/docker-entrypoint.sh apache2-foreground
|
148
makefile
Normal file
148
makefile
Normal file
@ -0,0 +1,148 @@
|
||||
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
|
||||
|
||||
#######################################
|
||||
# Wacky commands you probably won't need to use
|
||||
#######################################
|
||||
|
||||
## Download database from dev site
|
||||
db_fetch:
|
||||
$(ABRA) app run $(SITE_URL) db bash -c 'mysqldump -u root -p"$$(cat /run/secrets/db_root_password)" wordpress' | gzip > data/dbdump.sql.gz
|
||||
|
||||
## Load latest database from ~/.abra/backups
|
||||
db_load:
|
||||
zcat data/dbdump.sql.gz | $(_DOCKER_COMPOSE) exec -T db mysql -u wordpress -pwordpress wordpress
|
||||
|
||||
## 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'
|
||||
$(_DOCKER_COMPOSE) exec -u user wordpress wp --url=https://$(SITE_URL) search-replace --all-tables-with-prefix 'fashionrevolution.org' '$(PROJECT_NAME).localhost'
|
||||
|
||||
set_local_password:
|
||||
$(_DOCKER_COMPOSE) exec -u user wordpress wp user update admin --user_pass=password
|
||||
|
||||
db_pull: db_fetch db_load fix_url
|
||||
|
||||
## Sync wp-content from site
|
||||
uploads_pull: uploads_fetch uploads_load
|
||||
|
||||
## Download wp-content files from site
|
||||
plugins_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/plugins/ > data/plugins.tar.gz
|
||||
|
||||
## Load latest plugins from data/plugins.tar.gz
|
||||
plugins_load:
|
||||
tar -C wp-content --strip-components=4 -xzf data/plugins.tar.gz
|
||||
|
||||
## Sync plugins from site
|
||||
plugins_pull: plugins_fetch plugins_load
|
||||
|
||||
# "Arguments" for makefiles..
|
||||
# https://stackoverflow.com/a/6273809/1826109
|
||||
%:
|
Loading…
Reference in New Issue
Block a user