From 67ea3734a92fb1605706d9de199d7404d585ac0d Mon Sep 17 00:00:00 2001 From: pierreozoux <pierre@ozoux.net> Date: Thu, 17 Sep 2015 17:20:34 +0100 Subject: [PATCH] migrate to official image! --- Dockerfile | 31 ++++---------- docker-compose.yml | 20 ++++++--- nginx.conf | 67 ++++++++++++++++++++++++++++++ php.ini | 1 + run-wordpress.sh | 71 -------------------------------- run.sh | 19 +++++++++ wp-config.php | 100 --------------------------------------------- 7 files changed, 109 insertions(+), 200 deletions(-) create mode 100644 nginx.conf create mode 100644 php.ini delete mode 100644 run-wordpress.sh create mode 100644 run.sh delete mode 100644 wp-config.php diff --git a/Dockerfile b/Dockerfile index a8acd0a..115ddd8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,11 @@ -FROM indiepaas/apache +FROM wordpress:fpm -# Download latest version of Wordpress into /app -RUN curl -L https://wordpress.org/latest.tar.gz | tar xz && \ - mv wordpress/* app && \ - mv /app/wp-content /wp-content && \ - 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 -ADD wp-config.php /app/wp-config.php +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + ssmtp \ + && rm -rf /var/lib/apt/lists/* -# Add script to create 'wordpress' DB -ADD run-wordpress.sh /run-wordpress.sh -RUN chmod 755 /run-wordpress.sh - -# Expose environment variables -ENV DB_HOST **LinkMe** -ENV DB_PORT **LinkMe** -ENV DB_NAME wordpress -ENV DB_USER admin -ENV DB_PASS **ChangeMe** - -EXPOSE 80 -VOLUME ["/app/wp-content", "/app/.htaccess"] -CMD ["/run-wordpress.sh"] +COPY run.sh /run.sh +COPY php.ini /usr/local/etc/php/php.ini +CMD ["/run.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index d57fac4..bde33f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,16 +2,24 @@ db: image: mysql volumes: - ./mysql/runtime:/var/lib/mysql + - ./mysql/dump:/dump env_file: - ./.env -web: +app: image: indiehosters/wordpress links: - - db + - db:mysql volumes: - - ./wordpress/data:/app/wp-content - - ./wordpress/.htaccess:/app/.htaccess - - ./mysql/dump.sql:/initial_db.sql + - ./wordpress/data:/var/www/html/wp-content env_file: - ./.env - +web: + image: nginx + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + links: + - app + volumes_from: + - app + ports: + - 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..fb0baf8 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,67 @@ +user www-data; + +events { + worker_connections 768; +} + +http { + upstream backend { + server app:9000; + } + include /etc/nginx/mime.types; + default_type application/octet-stream; + gzip on; + gzip_disable "msie6"; + server { + listen 80; + + root /var/www/html; + index index.php; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location / { + # This is cool because no php is touched for static content. + # include the "?$args" part so non-default permalinks doesn't break when using query string + try_files $uri $uri/ /index.php?$args; + } + + location ~ \.php$ { + fastcgi_param GATEWAY_INTERFACE CGI/1.1; + fastcgi_param SERVER_SOFTWARE nginx; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param DOCUMENT_URI $document_uri; + fastcgi_param DOCUMENT_ROOT $document_root; + fastcgi_param SERVER_PROTOCOL $server_protocol; + fastcgi_param REMOTE_ADDR $remote_addr; + fastcgi_param REMOTE_PORT $remote_port; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + fastcgi_intercept_errors on; + fastcgi_pass backend; + } + + location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { + expires max; + log_not_found off; + } + + } +} + diff --git a/php.ini b/php.ini new file mode 100644 index 0000000..638241e --- /dev/null +++ b/php.ini @@ -0,0 +1 @@ +sendmail_path = /usr/sbin/ssmtp -t diff --git a/run-wordpress.sh b/run-wordpress.sh deleted file mode 100644 index 942e32d..0000000 --- a/run-wordpress.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -if [ ! "$(ls -A /app/wp-content)" ]; then - cp -av /wp-content/* /app/wp-content/ -fi - -DB_HOST=db -DB_PORT=3306 -export DB_PASS=$MYSQL_PASSWORD - -echo "=> Trying to connect to MySQL/MariaDB using:" -echo "========================================================================" -echo " Database Host Address: $DB_HOST" -echo " Database Port number: $DB_PORT" -echo " Database Name: $DB_NAME" -echo " Database Username: $DB_USER" -echo " Database Password: $DB_PASS" -echo "========================================================================" - -for ((i=0;i<10;i++)) -do - DB_CONNECTABLE=$(mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT -e 'status' >/dev/null 2>&1; echo "$?") - if [[ DB_CONNECTABLE -eq 0 ]]; then - break - fi - sleep 5 -done - -if [[ $DB_CONNECTABLE -eq 0 ]]; then - DB_EXISTS=$(mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT -e "SHOW DATABASES LIKE '"$DB_NAME"';" 2>&1 |grep "$DB_NAME" > /dev/null ; echo "$?") - - if [[ DB_EXISTS -eq 1 ]]; then - echo "=> Creating database $DB_NAME" - RET=$(mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT -e "CREATE DATABASE $DB_NAME") - if [[ RET -ne 0 ]]; then - echo "Cannot create database for wordpress" - exit RET - fi - if [ -f /initial_db.sql ]; then - echo "=> Loading initial database data to $DB_NAME" - RET=$(mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT $DB_NAME < /initial_db.sql) - if [[ RET -ne 0 ]]; then - echo "Cannot load initial database data for wordpress" - exit RET - fi - fi - echo "=> Done!" - echo "=> Installation of Wordpress" - PASS=`openssl rand -base64 15` - cd /app - wp --allow-root core install --url=https://${URL} --title=${URL} --admin_user=${EMAIL} --admin_password=${PASS} --admin_email=${EMAIL} - wp --allow-root plugin install wordpress-https - wp --allow-root plugin activate wordpress-https - echo "=> Done!" - echo "=============================================" - echo "to connect ${EMAIL}:${PASS}" - echo "=============================================" - else - echo "=> Skipped creation of database $DB_NAME – it already exists." - fi -else - echo "Cannot connect to Mysql" - exit $DB_CONNECTABLE -fi - -chown -R root:www-data /app -chmod -R 650 /app -chmod -R 770 /app/wp-content/ -chmod -R 660 /app/.htaccess - -exec /run.sh - diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..f3bc3e8 --- /dev/null +++ b/run.sh @@ -0,0 +1,19 @@ +/bin/bash -eux + +chfn -f 'Wordpress Admin' www-data + +cat > /etc/ssmtp/ssmtp.conf << EOF +UseTLS=Yes +UseSTARTTLS=Yes +root=${MAIL_USER} +mailhub=${MAIL_HOST}:${MAIL_PORT} +hostname=${MAIL_USER} +AuthUser=${MAIL_USER} +AuthPass=${MAIL_PASS} +EOF + +echo "www-data:${MAIL_USER}:${MAIL_HOST}:${MAIL_PORT}" >> /etc/ssmtp/revaliases + +#echo "sendmail_from = ${MAIL_USER}" >> /usr/local/etc/php/php.ini + +/entrypoint.sh php-fpm diff --git a/wp-config.php b/wp-config.php deleted file mode 100644 index 7382d5f..0000000 --- a/wp-config.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php -/** - * The base configurations of the WordPress. - * - * This file has the following configurations: MySQL settings, Table Prefix, - * Secret Keys, WordPress Language, and ABSPATH. You can find more information - * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing - * wp-config.php} Codex page. You can get the MySQL settings from your web host. - * - * This file is used by the wp-config.php creation script during the - * installation. You don't have to use the web site, you can just copy this file - * to "wp-config.php" and fill in the values. - * - * @package WordPress - */ - -define('FORCE_SSL_ADMIN', true); -if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') - $_SERVER['HTTPS']='on'; -$_SERVER["SERVER_PORT"]='443'; - -// ** MySQL settings - You can get this info from your web host ** // -/** The name of the database for WordPress */ -define('DB_NAME', getenv('DB_NAME')); - -/** MySQL database username */ -define('DB_USER', getenv('DB_USER')); - -/** MySQL database password */ -define('DB_PASSWORD', getenv('DB_PASS')); - -/** MySQL hostname */ -define('DB_HOST', getenv('DB_HOST').":".getenv('DB_PORT')); - -/** Database Charset to use in creating database tables. */ -define('DB_CHARSET', 'utf8'); - -/** The Database Collate type. Don't change this if in doubt. */ -define('DB_COLLATE', ''); - -/**#@+ - * Authentication Unique Keys and Salts. - * - * Change these to different unique phrases! - * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} - * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. - * - * @since 2.6.0 - */ -define('AUTH_KEY', '--w,=nO-t>g:EOH>e-ZXs!7x(: W4:}1A2$E?Sn9P>TW-[=:u[nc-eQ<vIi<6|wh'); -define('SECURE_AUTH_KEY', 'PlM~WQ/9-~V:-3&be`nxuaghz@JyN!]SzVr_]lAM2b?QH(d(|`.z_;1jIE4kY&f+'); -define('LOGGED_IN_KEY', 'K]6*uCb-m~>zj5C1krtu:>2VT(WlI/Jl5T~Pov2-`r+Zb5s3i6&aIN$*/+k/~sLN'); -define('NONCE_KEY', '~; xvP`h^{Pl9zaD#/!f@M21BAk0#sKg>*P+=1LV+FY+;HNE)%Y`4(Xq|&})fCj^'); -define('AUTH_SALT', 'A2|G[jvSLB+z dy S/ S>(lLyzxDvJ8(ps1(F%~x]eRD`UHv(h*IDjye+SYV-a;O'); -define('SECURE_AUTH_SALT', '9cv/Hy~a;qr]4)i*udy-/$non@_:CU0SIdm-L[WH^k_}s:Jq[)HV,Wu8na<_;ef3'); -define('LOGGED_IN_SALT', '{d*4OCrk9x`|cb-4EBK7=ewJ3D]y%z,7mSEd:8?=eP![zD.O`<Uubt-u%@TA+x T'); -define('NONCE_SALT', 'z6G5thFC]JIW]|ZQIBgZ?zBb^!N#3-Un=)`!Xb/,Yd8[2&}.W{ITu?=PE0oZ,<8^'); - -/**#@-*/ - -/** - * WordPress Database Table prefix. - * - * You can have multiple installations in one database if you give each a unique - * prefix. Only numbers, letters, and underscores please! - */ -$table_prefix = 'wp_'; - -/** - * WordPress Localized Language, defaults to English. - * - * Change this to localize WordPress. A corresponding MO file for the chosen - * language must be installed to wp-content/languages. For example, install - * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German - * language support. - */ -define('WPLANG', ''); - -/** - * For developers: WordPress debugging mode. - * - * Change this to true to enable the display of notices during development. - * It is strongly recommended that plugin and theme developers use WP_DEBUG - * in their development environments. - */ -define('WP_DEBUG', false); - -/* That's all, stop editing! Happy blogging. */ - -/** Absolute path to the WordPress directory. */ -if ( !defined('ABSPATH') ) - define('ABSPATH', dirname(__FILE__) . '/'); - -/** Sets up WordPress vars and included files. */ -require_once(ABSPATH . 'wp-settings.php'); - -/** change permisssions for plugin installation */ -define("FS_METHOD","direct"); -define("FS_CHMOD_DIR", 0777); -define("FS_CHMOD_FILE", 0777); -- GitLab