فهرست منبع

Automate install using wp-cli

Girish Ramakrishnan 10 سال پیش
والد
کامیت
322090b4f3
4فایلهای تغییر یافته به همراه56 افزوده شده و 129 حذف شده
  1. 5 3
      Dockerfile
  2. 4 0
      README.md
  3. 47 22
      start.sh
  4. 0 104
      wp-config.php.template

+ 5 - 3
Dockerfile

@@ -1,17 +1,19 @@
-FROM girish/base:0.1.0
+FROM cloudron/base:0.3.0
 MAINTAINER Girish Ramakrishnan <girish@forwardbias.in>
 
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN mkdir -p /app/code
 WORKDIR /app/code
-RUN curl -L http://wordpress.org/wordpress-4.1.tar.gz | tar -xz --strip-components 1 -f -
+RUN curl -L http://wordpress.org/wordpress-4.2.tar.gz | tar -xz --strip-components 1 -f -
 RUN chown -R www-data.www-data /app/code
 
 ADD start.sh /app/code/start.sh
 RUN chmod +x /app/code/start.sh
 
-ADD wp-config.php.template /app/configs/wp-config.php.template
+RUN curl -o /app/code/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 
+RUN chmod +x /app/code/wp
+
 RUN ln -sf /app/data/wp-config.php /app/code/wp-config.php
 
 # configure apache

+ 4 - 0
README.md

@@ -1,3 +1,7 @@
+Notes
+=====
+The site_url() will always be the location where you can reach the site by tacking on /wp-admin on the end, while home_url() would not reliably be this location.
+
 Building
 ========
 

+ 47 - 22
start.sh

@@ -2,33 +2,58 @@
 
 set -eux
 
+readonly WP=/app/code/wp
+
 if [[ -z "$(ls -A /app/data)" ]]; then
     echo "Copying wp-content files on first run"
     mv /app/code/wp-content /app/data/wp-content/
+    rm -rf /app/code/wp-content
+    ln -sf /app/data/wp-content /app/code/wp-content
+
+    $WP core config --allow-root --dbname="${MYSQL_DATABASE}" --dbuser="${MYSQL_USERNAME}" --dbpass="${MYSQL_PASSWORD}" --dbhost="${MYSQL_HOST}" --extra-php <<EOF
+    // prevent user from changing the Settings->General, WordPress and Blog address values.
+    define('WP_HOME',    'https://$(hostname -f)');
+    define('WP_SITEURL', 'https://$(hostname -f)');
+
+    /*
+     http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
+     http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
+     https://wordpress.org/support/topic/wp_home-and-wp_siteurl
+     */
+    // If WordPress is behind reverse proxy which proxies https to http
+    if (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'])) {
+        \$_SERVER['HTTP_HOST'] = \$_SERVER['HTTP_X_FORWARDED_HOST'];
+
+        if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
+            \$_SERVER['HTTPS']='on';
+    }
+EOF
+
+    readonly admin_password=$(pwgen -1)
+    readonly admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
+    echo "Admin password is ${admin_password}"
+
+    $WP --url="https://$(hostname -f)" core install \
+        --allow-root \
+        --url="https://$(hostname -f)" \
+        --title="My blog" \
+        --admin_user=admin \
+        --admin_password="${admin_password}" \
+        --admin_email="${admin_email}"
+
+    echo "Installing OAuth plugin"
+    ./wp plugin install --allow-root --activate --force https://github.com//cloudron-io/WP-OAuth/archive/5e77ff326b26f6175fefcd25f46d6c45e0fa14fa.zip
+else
+    rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
+    ln -sf /app/data/wp-content /app/code/wp-content
 fi
 
-[[ ! -L "/app/code/wp-content" ]] && rm -rf /app/code/wp-content # upgrades & updates - starting out with existing data
-
-ln -sf /app/data/wp-content /app/code/wp-content
-
-: ${MYSQL_URL:=}
-if [[ -z "${MYSQL_URL}" ]]; then
-    echo "MYSQL_URL is empty"
-    exit 1
-fi
-
-proto="$(echo "${MYSQL_URL}" | sed -e's,^\(.*://\).*,\1,g')"
-url="$(echo ${MYSQL_URL/$proto/})"
-username="$(echo ${url} | cut -d: -f1)"
-password=$(echo ${url/$username:/} | cut -d@ -f1)
-host="$(echo ${url/$username:$password@/} | cut -d/ -f1)"
-db="$(echo ${url} | grep / | cut -d/ -f2-)"
-
-sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${db}');/" \
-    -e "s/define('DB_USER',.*/define('DB_USER', '${username}');/" \
-    -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${password}');/" \
-    -e "s/define('DB_HOST',.*/define('DB_HOST', '${host}');/" \
-    /app/configs/wp-config.php.template > /app/code/wp-config.php
+# Settings to be updated on every run
+sed -e "s/define('DB_NAME',.*/define('DB_NAME', '${MYSQL_DATABASE}');/" \
+    -e "s/define('DB_USER',.*/define('DB_USER', '${MYSQL_USERNAME}');/" \
+    -e "s/define('DB_PASSWORD',.*/define('DB_PASSWORD', '${MYSQL_PASSWORD}');/" \
+    -e "s/define('DB_HOST',.*/define('DB_HOST', '${MYSQL_HOST}');/" \
+    -i /app/data/wp-config.php # sed -i seems to destroy symlink
 
 /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i WordPress
 

+ 0 - 104
wp-config.php.template

@@ -1,104 +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
- */
-
-// ** MySQL settings - You can get this info from your web host ** //
-/** The name of the database for WordPress */
-define('DB_NAME', '');
-
-/** MySQL database username */
-define('DB_USER', '');
-
-/** MySQL database password */
-define('DB_PASSWORD', '');
-
-/** MySQL hostname */
-define('DB_HOST', '');
-
-/** 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',         'emE$cbj0XG=$-sNvH65GlVUq!1jhA(k-:-GL^4lh*_=+-/vQqBXoe:x616_?.]q~');
-define('SECURE_AUTH_KEY',  '_?e=o.me4ki ~8n%+-GW{hg>XMr@Kq?C|5v%6R|#>oFz-EIv,wR70%3w*@j*f+!Q');
-define('LOGGED_IN_KEY',    '4%PU`*?EP@>m_DoEb},%|)o~y>r7Etj-|t+[[D%eGx5z<v[`hgUxP/lMk{;Qjli(');
-define('NONCE_KEY',        '6cWaRQ0{X{2-8<?2,u[z#Z+$<FFmb}VFT.E]8~| C,PI{o~wyx:p JVY-K&q*2w_');
-define('AUTH_SALT',        'V6D|O!PDne5_-3PtOl]jBB&cN-&i=s9Z[fIKq]$duN|)DV6Jb/Ew!Xw/0.Mj-,#w');
-define('SECURE_AUTH_SALT', 'L|~ibPPAPu<$?RV!8gffS$?MB{(h8L-y8,:_m]4{c.,F=/;u3uzTe(X*IX>,wrL*');
-define('LOGGED_IN_SALT',   'i-P@Zc ,xG+kwH&D[R-n@|f]>5+{U`i/5=0|R6(Ycx,~:ckX|HO8@?XAE-`t@AkV');
-define('NONCE_SALT',       '|;x#`|:5heUdp.j1%p(Ub-%BPOepY+)CoRy|2WOl/vn0R@y!En=/x#c7sTg[y]{`');
-
-/**#@-*/
-
-/**
- * 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);
-
-/*
- http://cmanios.wordpress.com/2014/04/12/nginx-https-reverse-proxy-to-wordpress-with-apache-http-and-different-port/
- http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy
- https://wordpress.org/support/topic/wp_home-and-wp_siteurl
- */
-// If WordPress is behind reverse proxy which proxies https to http
-if (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) {
-    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
-
-    if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
-        $_SERVER['HTTPS']='on';
-}
-
-/* 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');
-