Browse Source

new: [wordpress] new charm

master
Valentin Lab 1 week ago
parent
commit
158360d5c7
  1. 18
      wordpress/hooks/init
  2. 26
      wordpress/hooks/mysql_database-relation-joined
  3. 50
      wordpress/lib/common
  4. 31
      wordpress/metadata.yml

18
wordpress/hooks/init

@ -0,0 +1,18 @@
#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
set -e
. lib/common
wordpress:init

26
wordpress/hooks/mysql_database-relation-joined

@ -0,0 +1,26 @@
#!/bin/bash
. lib/common
PASSWORD="$(relation-get password)"
USER="$(relation-get user)"
DBNAME="$(relation-get dbname)"
control=$(H "$USER" "$DBNAME" "$PASSWORD")
[ "$control" == "$(relation-get control || true)" ] && exit 0
set -e
wp-cli:run config create \
--dbname="$DBNAME" \
--dbuser="$USER" \
--dbpass="$PASSWORD" \
--dbhost="$TARGET_SERVICE_NAME" \
--skip-check
relation-set control "$control"
info "Configured wordpress code for mysql access."

50
wordpress/lib/common

@ -0,0 +1,50 @@
# -*- mode: shell-script -*-
WORDPRESS_DIR="/opt/apps/wordpress"
WORDPRESS_CODE="$SERVICE_DATASTORE$WORDPRESS_DIR"
# WORDPRESS_RELEASE=6.6.2
# WORDPRESS_URL=https://github.com/WordPress/WordPress/archive/refs/tags/"${WORDPRESS_RELEASE}".tar.gz
WPCLI_RELEASE=2.11.0
WPCLI_URL=https://github.com/wp-cli/wp-cli/releases/download/v${WPCLI_RELEASE}/wp-cli-${WPCLI_RELEASE}.phar
WPCLI_DOCKER_IMAGE="wpcli:$WPCLI_RELEASE"
wp-cli:run() {
if ! docker_has_image "$WPCLI_DOCKER_IMAGE"; then
echo '
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar &&
chmod +x wp-cli.phar &&
mv wp-cli.phar /usr/local/bin/wp
' | DEBUG=1 dupd -t "$WPCLI_DOCKER_IMAGE" "$DOCKER_BASE_IMAGE" || {
err "Couldn't build $WPCLI_DOCKER_IMAGE."
return 1
}
info "Successfully built $WPCLI_DOCKER_IMAGE."
fi
docker run --rm \
-v "$WORDPRESS_CODE:$WORDPRESS_DIR" \
-w "$WORDPRESS_DIR" \
-u www-data \
--entrypoint wp \
"$WPCLI_DOCKER_IMAGE" "$@"
}
wordpress:init() {
mkdir -p "$WORDPRESS_CODE" || {
err "Couldn't create $WORDPRESS_CODE."
return 1
}
dir_is_empty "$WORDPRESS_CODE" || return 0
uid=$(docker_get_uid "$SERVICE_NAME" "www-data")
chown "$uid" "$WORDPRESS_CODE" || {
err "Couldn't change owner of $WORDPRESS_CODE to $uid."
return 1
}
cd "$WORDPRESS_CODE" || return 1
wp-cli:run core download
}

31
wordpress/metadata.yml

@ -0,0 +1,31 @@
description: Wordpress
subordinate: true
requires:
web-publishing-directory:
interface: publish-dir
scope: container
uses:
mysql-database:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
database: "main storage"
publish-dir:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
scope: container
constraint: required
auto: summon
solves:
container: "main running server"
default-options:
location: !var-expand "$DATASTORE/$BASE_SERVICE_NAME/opt/apps/wordpress"
fpm: php
backup:
constraint: recommended
auto: pair
solves:
backup: "Automatic regular backup"
Loading…
Cancel
Save