Commit c6200157 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Replicate (more-or-less) the old deployment of singing-chimes

parents
Loading
Loading
Loading
Loading

Dockerfile

0 → 100644
+42 −0
Original line number Diff line number Diff line
FROM php:7.3-fpm

LABEL uk.org.kodo.maintainer "Dom Sekotill <dom.sekotill@kodo.org.uk>"

# From the official wordpress docker file (modified):
# ----
# install the PHP extensions we need
RUN apt-get update && apt-get install -y \
		libgmp-dev \
		libjpeg-dev \
		libpng-dev \
	&& rm -rf /var/lib/apt/lists/* \
	&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
	&& docker-php-ext-install gd mysqli opcache gmp

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
		echo 'opcache.memory_consumption=128'; \
		echo 'opcache.interned_strings_buffer=8'; \
		echo 'opcache.max_accelerated_files=4000'; \
		echo 'opcache.revalidate_freq=60'; \
		echo 'opcache.fast_shutdown=1'; \
		echo 'opcache.enable_cli=1'; \
	} > /usr/local/etc/php/conf.d/opcache-recommended.ini
# ----

ARG wp_version
ARG wp_sha1=
ENV WORDPRESS_VERSION=${wp_version}

WORKDIR /app
VOLUME /app/wp-content
ENV WORDPRESS_ROOT=/app

ADD install.sh /install.sh
RUN /install.sh "${wp_version}" "${wp_sha1}" && rm /install.sh

COPY entrypoint.sh /bin/entrypoint

ENTRYPOINT ["/bin/entrypoint"]
CMD ["php-fpm"]

build.sh

0 → 100644
+18 −0
Original line number Diff line number Diff line
#!/bin/bash

get_latest() {
	curl -sSL 'http://api.wordpress.org/core/version-check/1.7/' |
		sed -r 's/^.*"current":"([^"]+)".*$/\1/'
}

get_version() {
	echo "${UPSTREAM_VERSION}"
}

build() {
	docker_build \
		--build-arg wp_version="${UPSTREAM_VERSION}" \
		--tag $1

		# --build-arg base_image="${WORDPRESS_BASE_IMAGE:-php:7.3-fpm}" \
}

entrypoint.sh

0 → 100755
+121 −0
Original line number Diff line number Diff line
#!/bin/bash
set -eu

# constants
WP_ROOT=${WORDPRESS_ROOT:-/var/www/html}
WP_CONTENT=${WP_ROOT}/wp-content
WP_CONFIG=${WP_ROOT}/wp-config.php

die() { echo "$*" >&2; exit 1; }

genkey() { head -c1M /dev/urandom | sha1sum | cut -d' ' -f1; }

create_config()
{
cat > $WP_CONFIG <<END_CONFIG
<?php
/**
 * Generated by entrypoint.sh
 * `date`
 */

define('DB_HOST', '${DB_HOST}');
define('DB_NAME', '${DB_NAME}');
define('DB_USER', '${DB_USER}');
define('DB_PASSWORD', '${DB_PASSWORD}');

define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

\$table_prefix = 'wp_';

define('AUTH_KEY',         '`genkey`');
define('SECURE_AUTH_KEY',  '`genkey`');
define('LOGGED_IN_KEY',    '`genkey`');
define('NONCE_KEY',        '`genkey`');
define('AUTH_SALT',        '`genkey`');
define('SECURE_AUTH_SALT', '`genkey`');
define('LOGGED_IN_SALT',   '`genkey`');
define('NONCE_SALT',       '`genkey`');

define('FS_METHOD', 'direct');

define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

require_once(ABSPATH . 'wp-settings.php');
END_CONFIG
}

run_setup()
{
	# setup entrypoint
	# ----------------
	# Setup the database, install the scripts & make a config
	
	source /etc/wordpress/mysql.conf

	# parse command line arguments
	SHIFT=shift
	POP='"$2"; SHIFT=shift; shift'
	while [ $# -gt 0 ]; do
		case "$1" in
			--*=*)
				set ${1%%=*} ${1#*=} "${@:2}"
				continue
				;;
			-*)
				set ${1:0:2} ${1#??} "${@:2}"
				# SHIFT adds the character-option hyphen onto $2 if is not POPed
				# as an argument first.
				SHIFT='set -$2 "${@:3}"; SHIFT=shift'
				continue
				;;

			-h|--host) exec DB_HOST=$POP ;;
			-d|--database) exec DB_NAME=$POP ;;
			-u|--user) exec DB_USER=$POP ;;
			-p|--password) exec DB_PASSWORD=$POP ;;
		esac
		$SHIFT
	done

	# command line argument defaults
	: ${DB_HOST:=mysql}
	: ${DB_USER:="${DB_NAME?A database name is required}_user"}
	: ${DB_PASSWORD:=}

	create_config
}

run_install()
{
	# overwrite current source onto deployed scripts
	rm -r /usr/src/wordpress/wp-content/
	cp -r /usr/src/wordpress/* ${WP_ROOT}/
	mkdir -p ${WP_CONTENT}
	# prevent core scripts from being overwritten by the application.
	chown -R root:root ${WP_ROOT}/
	# allow themes, plugins & content to be installed/managed by the application
	chown -R www-data:www-data ${WP_CONTENT}
}

run_cmd()
{
	# main entrypoint
	# ---------------
	# Run the given command after sanity checks

	# install/upgrade to volume from image source
	run_install
	# run setup entrypoint if it has not been run on this container before
	test -e $WP_CONFIG || run_setup
	# exec the command
	exec "$@"
}

case "$1" in
	setup) run_install && shift && run_setup "$@" ;;
	*) run_cmd "$@" ;;
esac

install.sh

0 → 100755
+29 −0
Original line number Diff line number Diff line
#!/bin/sh
set -eu

die() { echo "$*"; exit 1; }

VERSION="$1"
SHA1="$2"
URL="https://wordpress.org/wordpress-${VERSION}.tar.gz"

# check user has not attempted to override WORDPRESS_VERSION
test "$VERSION" = "$WORDPRESS_VERSION" ||
	die 'Use --build-arg="version=[...]" to set the wordpress version'

# get a hash if not passed in
if [ -z "$SHA1" ]; then
	SHA1="$(curl -sSL "${URL}.sha1")"
fi

curl -o wordpress.tar.gz -SL "$URL"

# check hash if available
if [ -n "$SHA1" ]; then
	echo "${SHA1} *wordpress.tar.gz" | sha1sum -c - ||
		die "Hash does not match, maybe there was a download error?"
fi

# unpack source
tar -xzf wordpress.tar.gz -C /usr/src/ &&
	rm wordpress.tar.gz