From f59152c35271ebf0bdaf948a5a1adff6ab152ded Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 16 Apr 2019 20:21:47 +0100 Subject: [PATCH] Add Docksal configuration --- .docksal/.gitignore | 3 + .docksal/commands/init | 107 ++++++++++++++++++++++++++++++++++ .docksal/commands/test | 19 ++++++ .docksal/docksal.env | 37 ++++++++++++ .docksal/docksal.yml | 1 + .docksal/etc/mysql/my.cnf | 6 ++ .docksal/etc/php/php-fpm.conf | 4 ++ .docksal/etc/php/php.ini | 4 ++ 8 files changed, 181 insertions(+) create mode 100644 .docksal/.gitignore create mode 100755 .docksal/commands/init create mode 100755 .docksal/commands/test create mode 100644 .docksal/docksal.env create mode 100644 .docksal/docksal.yml create mode 100644 .docksal/etc/mysql/my.cnf create mode 100644 .docksal/etc/php/php-fpm.conf create mode 100644 .docksal/etc/php/php.ini diff --git a/.docksal/.gitignore b/.docksal/.gitignore new file mode 100644 index 0000000..7b6975c --- /dev/null +++ b/.docksal/.gitignore @@ -0,0 +1,3 @@ +# Exclude local configuration overrides +docksal-local.env +docksal-local.yml diff --git a/.docksal/commands/init b/.docksal/commands/init new file mode 100755 index 0000000..516686d --- /dev/null +++ b/.docksal/commands/init @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +## Initialize a Docksal powered Wordpress site +## +## Usage: fin init + +# Abort if anything fails +set -e + +#-------------------------- Settings -------------------------------- + +# PROJECT_ROOT is passed from fin. +# The following variables are configured in the '.env' file: DOCROOT, VIRTUAL_HOST. + +DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}" + +#-------------------------- END: Settings -------------------------------- + +#-------------------------- Helper functions -------------------------------- + +# Console colors +red='\033[0;31m' +green='\033[0;32m' +green_bg='\033[42m' +yellow='\033[1;33m' +NC='\033[0m' + +echo-red () { echo -e "${red}$1${NC}"; } +echo-green () { echo -e "${green}$1${NC}"; } +echo-green-bg () { echo -e "${green_bg}$1${NC}"; } +echo-yellow () { echo -e "${yellow}$1${NC}"; } + +is_windows () +{ + local res=$(uname | grep 'CYGWIN_NT') + if [[ "$res" != "" ]]; then + return 0 + else + return 1 + fi +} + +#-------------------------- END: Helper functions -------------------------------- + +#-------------------------- Functions -------------------------------- + +# Generate wp-config.php file +generate_config () +{ + cd $DOCROOT_PATH + + fin exec "rm -f wp-config.php" + fin exec "wp core config --dbname=${MYSQL_DATABASE} --dbuser=${MYSQL_USER} --dbpass=${MYSQL_PASSWORD} --dbhost=db" +} + +# Install site +site_install () +{ + cd $DOCROOT_PATH + + fin exec "wp core install \ + --url=${VIRTUAL_HOST} \ + --title='My WordPress Site' \ + --admin_user=${WP_ADMIN_USER} \ + --admin_password=${WP_ADMIN_PASS} \ + --admin_email=${WP_ADMIN_EMAIL}" +} + +#-------------------------- END: Functions -------------------------------- + +#-------------------------- Execution -------------------------------- + +if [[ "$PROJECT_ROOT" == "" ]]; then + echo-red "\$PROJECT_ROOT is not set" + exit 1 +fi + +if [[ $DOCKER_RUNNING == "true" ]]; then + echo -e "${green_bg} Step 1 ${NC}${green} Recreating services...${NC}" + fin reset -f +else + echo -e "${green_bg} Step 1 ${NC}${green} Creating services...${NC}" + fin up +fi + +echo "Waiting 10s for MySQL to initialize..."; +sleep 10 + +# Project initialization steps +echo -e "${green_bg} Step 2 ${NC}${green} Generating wp-config.php...${NC}" +generate_config + +echo -e "${green_bg} Step 3 ${NC}${green} Installing site...${NC}" +time site_install + + +if is_windows; then + echo-green "Add ${VIRTUAL_HOST} to your hosts file (/etc/hosts), e.g.:" + echo-green "192.168.64.100 ${VIRTUAL_HOST}" + echo +fi + +echo -en "${green_bg} DONE! ${NC} " +echo -e "Open ${yellow}http://${VIRTUAL_HOST}${NC} in your browser to verify the setup." +echo -e "Admin panel: ${yellow}http://${VIRTUAL_HOST}/wp-admin${NC}. User/password: ${yellow}${WP_ADMIN_USER}/${WP_ADMIN_PASS}${NC} " + +#-------------------------- END: Execution -------------------------------- diff --git a/.docksal/commands/test b/.docksal/commands/test new file mode 100755 index 0000000..8f9d5f8 --- /dev/null +++ b/.docksal/commands/test @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +## Test site installation +## +## Usage: fin test + +# Abort if anything fails +set -e + +# Debug mode switch +if [[ "${DEBUG}" != "" ]]; then + set -x +fi + +echo "Testing home page..." +curl -sL -I http://${VIRTUAL_HOST} | grep "HTTP/1.1 200 OK" +curl -sL http://${VIRTUAL_HOST} | grep "My WordPress Site" +echo "Testing login page..." +curl -sL -I http://${VIRTUAL_HOST}/wp-admin | grep "HTTP/1.1 200 OK" diff --git a/.docksal/docksal.env b/.docksal/docksal.env new file mode 100644 index 0000000..9f71832 --- /dev/null +++ b/.docksal/docksal.env @@ -0,0 +1,37 @@ +# This is a shared configuration file that is intended to be stored in the project repo. +# To override a variable locally: +# - create .docksal/docksal-local.env file and local variable overrides there +# - add .docksal/docksal-local.env to .gitignore + +# Use the default Docksal stack +DOCKSAL_STACK=default + +# Lock images versions for LAMP services +# This will prevent images from being updated when Docksal is updated +#WEB_IMAGE='docksal/web:x.x-apache2.4' +#DB_IMAGE='docksal/db:x.x-mysql-5.6' +#CLI_IMAGE='docksal/cli:x.x-php7.1' + +# Docksal configuration. +COMPOSE_PROJECT_NAME=wordcamp2019 +#VIRTUAL_HOST=wordpress.docksal +DOCROOT=. + +# MySQL settings. +MYSQL_ROOT_PASSWORD=root +MYSQL_USER=user +MYSQL_PASSWORD=user +MYSQL_DATABASE=default +# MySQL will be exposed on a random port. Use "fin ps" to check the port. +# To have a static MySQL port assigned, copy the line below into the .docksal/docksal-local.env file +# and replace the host port "0" with a unique host port number (e.g. MYSQL_PORT_MAPPING='33061:3306') +MYSQL_PORT_MAPPING='0:3306' + +# Enable/disable xdebug +# To override locally, copy the two lines below into .docksal/docksal-local.env and adjust as necessary +XDEBUG_ENABLED=0 + +# Wordpress settings +WP_ADMIN_USER=admin +WP_ADMIN_PASS=admin +WP_ADMIN_EMAIL=info@example.com diff --git a/.docksal/docksal.yml b/.docksal/docksal.yml new file mode 100644 index 0000000..193899e --- /dev/null +++ b/.docksal/docksal.yml @@ -0,0 +1 @@ +version: "2.1" diff --git a/.docksal/etc/mysql/my.cnf b/.docksal/etc/mysql/my.cnf new file mode 100644 index 0000000..1648455 --- /dev/null +++ b/.docksal/etc/mysql/my.cnf @@ -0,0 +1,6 @@ +[mysqld] + +# Enable slow query logging +#long_query_time=1 +#slow_query_log=1 +#slow_query_log_file=/dev/stdout diff --git a/.docksal/etc/php/php-fpm.conf b/.docksal/etc/php/php-fpm.conf new file mode 100644 index 0000000..931fb4a --- /dev/null +++ b/.docksal/etc/php/php-fpm.conf @@ -0,0 +1,4 @@ +; PHP FPM settings +[www] +; Maximum amount of memory a script may consume +;php_admin_value[memory_limit] = 256M diff --git a/.docksal/etc/php/php.ini b/.docksal/etc/php/php.ini new file mode 100644 index 0000000..7507bb1 --- /dev/null +++ b/.docksal/etc/php/php.ini @@ -0,0 +1,4 @@ +; Global PHP settings +[php] +; Maximum amount of memory a script may consume +;memory_limit = 1024M