Skip to content

Instantly share code, notes, and snippets.

@clcollins
Last active May 15, 2019 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save clcollins/cfab1f63dc1aa927bf9f to your computer and use it in GitHub Desktop.
Save clcollins/cfab1f63dc1aa927bf9f to your computer and use it in GitHub Desktop.
Docker Appstack WP Instance, via command line
#!/bin/bash
# Version 1.2 - 2015-01-07
# https://gist.github.com/clcollins/cfab1f63dc1aa927bf9f
# REQUIRES:
#
# Software -
# 1. Docker: https://docker.com
#
# SSL Certificates -
# 1. Named localhost.key, localhost.crt
# 2. Located in /tmp/certs
#
# Docker images -
# 1. appstack-data image: https://github.com/DockerDemos/appstack-data
# 2. appstack-setup-mysql image: https://github.com/DockerDemos/appstack-setup-mysql
# 3. appstack-mysql image: https://github.com/DockerDemos/appstack-mysql
# 4. appstack-phpfpm image: https://github.com/DockerDemos/appstack-phpfpm
# 5. appstack-apache image: https://github.com/DockerDemos/appstack-apache
# 6. appstack-wpcli image: https://github.com/DockerDemos/appstack-wpcli
f_err () {
echo 'Uh, something went wrong:'
echo "$1"
exit 1
}
pwgen -cns 32 1 > /dev/null || f_err 'Command: pwgen... NOT FOUND'
PWD="$(pwgen -cns 32 1)"
SITENAME="$1"
SMTPSERVER="$2"
APPNAME="${SITENAME}_$(date +%s)"
APPDIR="/tmp/${APPNAME}"
if [ -z $SITENAME ] ; then
f_err 'You must supply a site name.'
fi
if [ -z $SMTPSERVER ] ; then
echo "No SMTP SERVER specified. Continuing without mail support."
fi
if [ ! -d /tmp/certs ] ; then
f_err 'You must generate a key and certificate and place it into /tmp/certs for this script to work.'
elif [ ! -f /tmp/certs/localhost.crt ] ; then
f_err 'You must generate a key and certificate and place it into /tmp/certs for this script to work.'
fi
docker run --name ${APPNAME}-data -v ${APPDIR}/html:/var/www/html -v ${APPDIR}/mysql:/var/lib/mysql -v ${APPDIR}/log:/var/log -v ${APPDIR}/backup:/var/backup -v ${APPDIR}/conf:/conf -v ${APPDIR}/secret:/root/.secret -it appstack-data "WordPress: ${SITENAME}"|| f_err 'Failed creating data container'
### COPY 'localhost.{crt|key}' to /conf ###
cp /tmp/certs/localhost.crt ${APPDIR}/conf || f_err 'Failed to copy localhost.crt'
cp /tmp/certs/localhost.key ${APPDIR}/conf || f_err 'Failed to copy localhost.key'
if [[ -f /tmp/certs/ca-cert.crt ]] ; then
cp /tmp/certs/ca-cert.crt ${APPDIR}/conf || f_err 'Failed to copy CA Intermediate Cert'
fi
docker run --volumes-from ${APPNAME}-data -it appstack-setup-mysql || f_err 'MySQL Setup Failed'
docker run --name ${APPNAME}-db --volumes-from ${APPNAME}-data -d appstack-mysql || f_err 'MySQL container Failed'
docker run --name ${APPNAME}-fpm --link ${APPNAME}-db:db --volumes-from ${APPNAME}-data -e SMTPSERVER="${SMTPSERVER}" -d appstack-php-fpm || f_err 'PHP-FPM container failed'
docker run --volumes-from ${APPNAME}-data -w /var/www/html -it appstack-wpcli /scripts/core-download.sh || f_err 'Failed WP download'
docker run --volumes-from ${APPNAME}-data -w /var/www/html -it appstack-wpcli /scripts/core-config.sh || f_err 'Failed wp-config.php generation'
docker run --link ${APPNAME}-db:db --volumes-from ${APPNAME}-data -w /var/www/html -e SITENAME="https://${SITENAME}" -e TITLE="${SITENAME}" -e ADMIN="admin" -e ADMINPASS="${PWD}" -e ADMINEMAIL='admin@example.org' -it appstack-wpcli /scripts/core-install.sh || f_err 'Failed WP install'
docker run --name ${APPNAME}-apache --link ${APPNAME}-fpm:fpm --volumes-from ${APPNAME}-data -p 80:80 -p 443:443 -e 'SITENAME=${SITENAME}' -d appstack-apache || f_err 'Apache container failed'
echo "Username: admin"
echo "Password: ${PWD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment