Skip to content

Commit

Permalink
Merge pull request #9 from russellmacshane/docker
Browse files Browse the repository at this point in the history
Converted from using Vagrant/Virtual box to Docker/Docker Compose
  • Loading branch information
russellmacshane authored Oct 12, 2020
2 parents c1d6574 + b1d570f commit 0538684
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 107 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.vagrant
*.log
backup
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ubuntu:latest

RUN apt update \
&& DEBIAN_FRONTEND=noninteractive apt install -y \
sudo \
dialog \
apt-utils \
curl

RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER docker

COPY . /home/docker/quick-wordpress

WORKDIR /home/docker/quick-wordpress

RUN sudo chown -R docker:docker /home/docker/quick-wordpress/

RUN ./build.sh

ENTRYPOINT ["./service-start.sh"]
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Quick WordPress
Quick WordPress Installation using Vagrant
Quick WordPress Installation using Docker

The goal of this project is to create a quick virtual machine setup with a WordPress installation for testing purposes. The following technologies are automatically installed for you:
* Ubuntu Bionic (18.04)
* Ubuntu
* Apache
* MariaDB
* PHP
Expand All @@ -11,29 +11,33 @@ The goal of this project is to create a quick virtual machine setup with a WordP
* WordPress

## Pre-Installation
1. Install [Vagrant](https://www.vagrantup.com/)
2. Install [Virtual Box](https://www.virtualbox.org/)
1. Install [Docker](https://docs.docker.com/get-docker/)
2. Install [Docker Compose](https://docs.docker.com/compose/install/)

## Installation Instructions
1. Find a directory on your computer that you'd like to install this repo
2. `$ git clone git@github.com:russellmacshane/quick-wordpress.git` or `git clone https://github.com/russellmacshane/quick-wordpress.git` if you don't have your [ssh keys setup](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
3. `$ cd quick-wordpress`
4. Your are strongly encouraged to modify the default passwords and WordPress setup information in the [config](./config) file
5. `$ vagrant up`
5. `$ docker-compose up -d`
6. Grab some ☕️ coffee, it'll take a bit to install all the necessary dependencies

## Usage
1. Make sure the vagrant process is completed and your virtual machine is ready
2. Point your web browser over to http://192.168.33.10/ to view your WordPress site
3. You can also get to phpMyAdmin by going to http://192.168.33.10/phpmyadmin/
4. If you'd like to login into your virtual machine - `$ vagrant ssh`
1. Make sure the container is up and running with `$ docker-compose ps`
2. Point your web browser over to http://localhost/ to view your WordPress site
3. You can also get to phpMyAdmin by going to http://localhost/phpmyadmin/
4. If you'd like to login into the container - `$ docker-compose exec qwp /bin/bash`
5. WordPress files are located in `/var/www/html` and you can run WPCli commands from there
6. This repo is mirrored from your local machine over to `/quick-wordpress` on your vm
6. This repo is mirrored from your local machine over to `/home/docker/quick-wordpress` on your container

## Backup and Restores
1. In order to do backup and restores login to your virtual machine - `$ vagrant ssh`
2. `$ qwcli backup` and follow the on screen instructions
3. If you'd like to restore from a previous backup - `$ qwcli restore` and follow the on screen instructions
1. In order to do backup and restores:
2. `$ docker-compose exec qwp qwcli backup` and follow the on screen instructions
3. If you'd like to restore from a previous backup - `$ docker-compose exec qwp qwcli restore` and follow the on screen instructions

## Start and Stopping
1. `$ docker-compose stop` to stop the container
2. `$ docker-compose start` to bring it back up again

## Cleanup
1. If you are ready to delete your WordPress VM from you local machine - `$ vagrant destroy -f`
1. If you are ready to delete your WordPress Container - `$ docker-compose down `
69 changes: 0 additions & 69 deletions Vagrantfile

This file was deleted.

26 changes: 13 additions & 13 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

DEBIAN_FRONTEND=noninteractive

source /quick-wordpress/config
source /home/docker/quick-wordpress/config

echo "***************************** Install Packages ***************************"
sudo -E apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections

echo "***************************** Install Apache *****************************"
sudo -E apt-get -y install apache2
sudo DEBIAN_FRONTEND=noninteractive apt install -y apache2
sudo service apache2 restart

echo "***************************** Modify Apache Docroot **********************"
cd /var/www
sudo -E chown -R $USER: html/
sudo -E chown -R $(whoami): html/
sudo -E chmod g+wx -R html/
sudo -E rm -f html/index.html

echo "***************************** Install MariaDB ****************************"
sudo -E debconf-set-selections <<< "mysql-server mysql-server/root_password password $mysql_root_password"
sudo -E debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $mysql_root_password"
sudo -E apt-get -y install mariadb-server
sudo -E apt install -y mariadb-server
sudo service mysql restart

echo "***************************** Install PHP ********************************"
sudo -E apt-get -y install php libapache2-mod-php php-mysql
sudo -E apt install -y php libapache2-mod-php php-mysql

echo "***************************** Install PHP My Admin ***********************"
sudo -E debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
sudo -E debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $phpyadmin_password"
sudo -E debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $mysql_root_password"
sudo -E debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $phpyadmin_password"
sudo -E debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
sudo -E apt-get install -y phpmyadmin
sudo -E apt install -y phpmyadmin

echo "***************************** Restart Apache *****************************"
sudo -E service apache2 restart
Expand All @@ -42,10 +42,10 @@ sudo -E mysql -u root -p$mysql_root_password -e "GRANT ALL PRIVILEGES ON $wp_db.
sudo -E mysql -u root -p$mysql_root_password -e "GRANT ALL PRIVILEGES ON $wp_db.* TO phpmyadmin@localhost IDENTIFIED BY '$phpyadmin_password'"

echo "***************************** Install QWCli *****************************"
sudo -E ln -s /quick-wordpress/qwcli/qwcli.sh /usr/local/bin/qwcli
sudo -E ln -s /home/docker/quick-wordpress/qwcli/qwcli.sh /usr/local/bin/qwcli

echo "***************************** Install WPCli *****************************"
cd /home/$USER
cd /home/$(whoami)
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo -E mv wp-cli.phar /usr/local/bin/wp
Expand All @@ -54,7 +54,7 @@ echo "***************************** Install WordPress **************************
cd /var/www/html
wp core download --version=$wp_version
wp core config --dbhost=localhost --dbname=$wp_db --dbuser=$wp_db_user --dbpass=$wp_db_password
wp core install --url=192.168.33.10 --title="$wp_site_title" --admin_name=$wp_admin_user --admin_password=$wp_admin_password --admin_email=$wp_admin_email
wp core install --url=localhost --title="$wp_site_title" --admin_name=$wp_admin_user --admin_password=$wp_admin_password --admin_email=$wp_admin_email

echo "***************************** Plugins ************************************"
wp plugin delete hello
Expand All @@ -65,7 +65,7 @@ do
done

echo "***************************** Modify Apache Docroot **********************"
sudo -E usermod -a -G www-data $USER
sudo -E usermod -a -G www-data $(whoami)
cd /var/www
sudo -E chown -R www-data: html/
sudo -E chmod g+wx -R html/
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ wp_db_password="wpdb-password"

# WordPress Site Details
wp_version="latest" #wp_version="nightly"
wp_site_title="Quick WordPress using Vagrant"
wp_site_title="Quick WordPress using Docker"
wp_admin_user="admin"
wp_admin_password="wpadmin-password"
wp_admin_email="test@example.com"
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.8"
services:
qwp:
build: .
ports:
- "80:80"
volumes:
- .:/home/docker/quick-wordpress
6 changes: 3 additions & 3 deletions qwcli/backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

source /quick-wordpress/config
source /home/docker/quick-wordpress/config

echo "***************************** WordPress Backup **************************"
run=true
Expand Down Expand Up @@ -32,8 +32,8 @@ echo "***************************** Backup Database ****************************
sudo mysqldump $wp_db > datadump.sql

echo "***************************** Backups Files ******************************"
mkdir -p /quick-wordpress/backup
tar -cjvf /quick-wordpress/backup/$backup_file /var/www/html datadump.sql
mkdir -p /home/docker/quick-wordpress/backup
tar -cjvf /home/docker/quick-wordpress/backup/$backup_file /var/www/html datadump.sql

echo "***************************** Cleanup ************************************"
rm datadump.sql
6 changes: 3 additions & 3 deletions qwcli/qwcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Commands:

case "$1" in
backup|b)
/quick-wordpress/qwcli/backup.sh
/home/docker/quick-wordpress/qwcli/backup.sh
;;
list|l)
ls /quick-wordpress/backup
ls /home/docker/quick-wordpress/backup
;;
restore|r)
/quick-wordpress/qwcli/restore.sh
/home/docker/quick-wordpress/qwcli/restore.sh
;;
*)
cli_help
Expand Down
4 changes: 2 additions & 2 deletions qwcli/restore.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

source /quick-wordpress/config
source /home/docker/quick-wordpress/config

echo "***************************** WordPress Restore **************************"
read -p "Enter the filename of the backup you would like to restore: " file

backup_dir=/quick-wordpress/backup
backup_dir=/home/docker/quick-wordpress/backup
backup_file=$backup_dir/$file

if [ ! -f $backup_file ]; then
Expand Down
4 changes: 4 additions & 0 deletions service-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

sudo service mysql restart
sudo apache2ctl -D FOREGROUND

0 comments on commit 0538684

Please sign in to comment.