Compare commits

...

12 Commits

Author SHA1 Message Date
5794d7f9ce Updated capitalisation and fix typo 2024-10-01 16:40:45 +01:00
e21080fae8 Updated header 2024-10-01 16:39:29 +01:00
b0d12b11f3 Updated README with better instructions 2024-10-01 16:38:22 +01:00
3wc
3e92ae47a5 Update wordpress 2024-05-15 23:10:56 -03:00
3wc
9b2f5eec60 Allow customising username to reset password of 2024-05-15 23:08:24 -03:00
3wc
8870e4b837 Switch back to default-ignore-all-wp-content 2024-05-15 23:08:12 -03:00
3wc
cf00cc81da Switch to mariadb-dump, drop extra search-replace 2024-05-15 22:57:20 -03:00
3wc
bf5ecd7b7c Skip spurious error during id 2024-05-15 22:48:49 -03:00
3wc
b39b5ac713 More templating 2024-05-15 22:44:36 -03:00
3wc
4ccb5b9a4e Add PHP syntax check, and (commented-out) custom block build
Closes #9
2024-05-15 22:38:25 -03:00
3wc
79047e02e5 Skip composer installation unless requested 2024-05-15 22:32:59 -03:00
3wc
a0c19b759b Make Mailhog actually work
Fixes #5
2024-05-15 22:25:37 -03:00
9 changed files with 71 additions and 16 deletions

View File

@ -2,17 +2,32 @@
kind: pipeline
name: deploy main branch to live site
steps:
- name: php syntax check
image: php:8.3.7-cli
commands:
- for f in $(find /drone -name '*.php'); do php -l "$f"; done
# If a custom block is in use, uncomment this (and make sure package.json
# includes `scripts.build`, and change the `depends_on` below
# - name: compile custom block
# image: node:18.18.2
# commands:
# - npm install
# - npm run build
# depends_on:
# - php syntax check
- 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/*
service: ${REPO_NAME_SNAKE}
source: wp-content/themes/${REPO_NAME}
exec_pre: rm -rf /var/www/html/wp-content/themes/${REPO_NAME}/*
exec: composer install
dest: /var/www/html/
deploy_key:
from_secret: drone_ssh_server.example.com
depends_on:
- php syntax check
when:
branch:
- main

View File

@ -1,7 +1,10 @@
##############################################################################
# REQUIRED SETTINGS (you will need these) #
##############################################################################
# What username should `set_local_password` operate on?
USERNAME=admin
##############################################################################
# COMMON SETTINGS (you may need these) #
##############################################################################
@ -33,3 +36,6 @@ SITE_URL=$REPO_NAME_SNAKE.tld
# 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);"
# Use composer for plugin installation
#USE_COMPOSER=1

View File

@ -1,3 +1,4 @@
.drone.yml
.env.sample
.gitignore
README.md

4
.gitignore vendored
View File

@ -1,6 +1,8 @@
/.env
/wp-content/twenty*
/wp-content/**
# Add an exception here for any custom plugins or themes to be included, e.g.
#!/wp-content/themes/${REPO_NAME_SNAKE}
/data/**
!/data/.gitkeep

View File

@ -1,15 +1,26 @@
A template for Autonomic Wordpress projects, including local set-up, and auto-deployment.
To use it:
# Usage
1. Make a new repository, using this as a template
2. Remove this notice from `README.md` (everything until the `---`)
3. Create and deploy a Co-op Cloud Wordpress app
4. Edit `.env.sample` to set `SITE_URL` (and customise `PROJECT_NAME`, if
needed)
- Change USERNAME to whatever the wordpress admin username is / should be
- Set SITE_URL to the live site URL
- Set PROJECT_NAME to some identifier for the project
5. Make sure `.drone.yml` has the right settings for the server you'd like to
deploy to
deploy
- Change host to the FQDN of the host, likely smol-wp.autonomic.zone
- Set service to the docker service name, usually <app_name_snake_case>_app so like display_distribute_com_app
- Update source and exec_pre to the path to the theme
- Comment exec: composer install if composer isn't in use
- Set `deploy_key: from_secret:` to the secret name of the SSH key to access the server. this requires logging into drone as autonomic admin, then checking "organisation secrets" on the repo settings page of any repo in the same org. or you can use drone CLI and do drone orgsecret ls
6. Add any custom plugins / themes to `wp-content`
- Copying / moving files into the repo in wp-content, and possibly / probably excluding them from .gitignore
7. "Activate" this repository in Drone
- e.g. click "activate repository" here https://drone.autonomic.zone/autonomic-cooperative/display-distribute/settings
8. Commit to the repo to test and monitor the drone interface to troubleshoot
---

View File

@ -3,12 +3,13 @@ version: "3"
services:
wordpress:
image: "wordpress:6.2.0"
image: "wordpress:6.5.3"
ports:
- "80:80"
dns: 4.2.2.4
volumes:
- "./entrypoint.sh:/usr/local/bin/entrypoint.sh:z"
- "./mailhog-smtp.php:/var/www/html/wp-content/mu-plugins/mailhog-smtp.php: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"

View File

@ -8,7 +8,7 @@ if [ -n "$PHP_EXTENSIONS" ]; then
done
fi
if ! id -u "user" >/dev/null ; then
if ! id -u "user" >/dev/null 2>&1; then
useradd -u 1000 -m user
mkdir /var/www/html/vendor
chown -R user:user /var/www/html/vendor
@ -23,12 +23,12 @@ if [ ! -x /usr/local/bin/wp ]; then
chmod +x /usr/local/bin/wp
fi
if [ ! -x /usr/local/bin/composer ]; then
if [ -n "$USE_COMPOSER" ] && [ ! -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 -r "if (hash_file('sha384', '/tmp/composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php /tmp/composer-setup.php
rm /tmp/composer-setup.php

21
mailhog-smtp.php Normal file
View File

@ -0,0 +1,21 @@
<?php
// Send outgoing mails through Mailhog
function action_wp_mail_failed($wp_error) {
print_r($wp_error, true);
exit;
}
add_action('wp_mail_failed', 'action_wp_mail_failed', 10, 1);
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->SMTPAuth = false;
$phpmailer->SMTPSecure = false;
$phpmailer->SMTPAutoTLS = false;
$phpmailer->Host = "mailhog";
$phpmailer->Port = 1025;
$phpmailer->From = "noreply@radhr.localhost";
$phpmailer->FromName = "noreply@radhr.localhost";
$phpmailer->Username = null;
$phpmailer->Password = null;
});

View File

@ -112,7 +112,7 @@ uploads_load:
## 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
$(ABRA) app run $(SITE_URL) db bash -c 'mariadb-dump -u root -p"$$(cat /run/secrets/db_root_password)" wordpress' | gzip > data/dbdump.sql.gz
## Load latest database from ~/.abra/backups
db_load:
@ -121,11 +121,9 @@ db_load:
## 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
$(_DOCKER_COMPOSE) exec -u user wordpress wp user update $(USERNAME) --user_pass=password
db_pull: db_fetch db_load fix_url