Skip to content

Commit

Permalink
Wordpress install
Browse files Browse the repository at this point in the history
deployment of Wordpress is done through git cloning from from github Wordpress mirror.
Auth to github is ssh using a deploy key supplied by the docker host.

The design of the deploy key processing works around the following two issues:

moby/moby#7198

http://stackoverflow.com/questions/26050899/how-to-mount-host-volumes-into-docker-containers-in-dockerfile-during-build
  • Loading branch information
Rija Ménagé committed May 15, 2017
1 parent ce0c1b8 commit c06202f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
22 changes: 4 additions & 18 deletions Dockerfile
Expand Up @@ -184,29 +184,15 @@ RUN /usr/bin/easy_install supervisor-stdout
RUN mkdir -p /var/log/supervisor
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Install Wordpress

# Select Vanilla Wordpress or Git install

ARG WP_VANILLA
ARG GIT_SSH_URL
ENV WP_VANILLA ${WP_VANILLA:-1}
ENV GIT_SSH_URL ${GIT_SSH_URL:-''}


# Download Wordpress

ARG WP_VERSION
ENV WP_VERSION ${WP_VERSION:-4.5.3}

COPY download_wordpress /download_wordpress
RUN chmod 755 /download_wordpress
RUN /download_wordpress

# Install Wordpress
ENV GIT_SSH_URL ${GIT_SSH_URL:-"git@github.com:WordPress/WordPress.git"}

COPY install_wordpress /install_wordpress
COPY ssh_config /root/.ssh/config
RUN chmod 700 /root/.ssh/config
RUN chmod 755 /install_wordpress
RUN /install_wordpress

# Bootstrap logs
RUN mkdir -p /var/log/nginx \
Expand Down
4 changes: 4 additions & 0 deletions bootstrap.sh
Expand Up @@ -9,6 +9,10 @@ DB_DATABASE=${DB_DATABASE:-$DB_MYSQL_DATABASE}

echo "$(date): Boostraping a new Wordpress instance for $SERVER_NAME"

echo "Cloning a new Wodpress install from a remote GIT repository"

/install_wordpress

echo "Backing up existing wp-config in case variables have been manually added to it"
if [ -f /usr/share/nginx/www/wp-config.php ]; then
cp /usr/share/nginx/www/wp-config.php /usr/share/nginx/www/wp-config.php.bak
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.override.yml
Expand Up @@ -7,4 +7,9 @@ services:
GIT_SSH_URL: ${GIT_REPO_SSH_URL}
environment:
DEBUG: 'true'
GIT_DEPLOY_KEY: 'git_deploy_key'
image: ${IMAGE_NAME}
volumes:
- /etc/letsencrypt:/etc/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
- /${HOME}/.ssh:/root/deploykeys:ro
3 changes: 2 additions & 1 deletion docker-compose.yml
Expand Up @@ -7,13 +7,14 @@ services:
volumes:
- /etc/letsencrypt:/etc/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock:ro
- /${HOME}/.docker/machine/machines/local/composed/${COMPOSE_PROJECT_NAME}:/root/.ssh
- /${HOME}/.ssh:/root/deploykeys:ro
ports:
- 443:443
- 80:80
depends_on:
- db
environment:
GIT_DEPLOY_KEY: 'git_deploy_key'
SERVER_NAME:
LE_EMAIL:
DB_HOSTNAME: dbs
Expand Down
35 changes: 16 additions & 19 deletions install_wordpress
@@ -1,35 +1,32 @@
#!/bin/bash


# Creating webroot directory
mkdir -p /usr/share/nginx/www

# Installing wordpress
# allowing the certs to be accessed

if [ "$GIT_SSH_URL" != '' ]; then
# from a git repository using SSH. It is assumed appropriate credentials are set up
ssh-keyscan -t rsa github.com >> /root/.ssh/known_hosts

cd /usr/share/nginx/www && git init
git remote add origin $GIT_SSH_URL
cp /root/deploykeys/$GIT_DEPLOY_KEY /root/.ssh/
cp /root/deploykeys/$GIT_DEPLOY_KEY.pub /root/.ssh/
chown root:root /root/.ssh/$GIT_DEPLOY_KEY

echo "create a local git repository at /usr/share/nginx/www linked to the web app remote repository"
ls -alrt /root/.ssh/ | grep $GIT_DEPLOY_KEY

elif [ "$WP_VANILLA" != '' ]; then
# use a previously downloaded and unpacked tarball release of Wordpress

test -d /usr/share/nginx/wordpress \
&& cp -r /usr/share/nginx/wordpress/* /usr/share/nginx/www/ \
&& rm -rf /usr/share/nginx/wordpress \
&& chown -R www-data:www-data /usr/share/nginx/www
# Installing wordpress

echo "Installed vanilla Wordpress at /usr/share/nginx/www"
if [ "$GIT_SSH_URL" != '' ]; then
# from a git repository using SSH. It is assumed appropriate credentials are set up

else
# nothing to install, not necessarily an error condition
cd /usr/share/nginx
git clone $GIT_SSH_URL www
fi

echo "Nothing to do"
# Removing the deploy key
rm /root/.ssh/$GIT_DEPLOY_KEY.pub
rm /root/.ssh/$GIT_DEPLOY_KEY

fi
ls -alrt /root/.ssh/

# Boostraping Nginx Helper Wordpress plugin's log
mkdir -p /usr/share/nginx/www/wp-content/uploads/nginx-helper
Expand Down
4 changes: 4 additions & 0 deletions ssh_config
@@ -0,0 +1,4 @@
host github.com
HostName github.com
IdentityFile ~/.ssh/git_deploy_key
User git

0 comments on commit c06202f

Please sign in to comment.