Skip to content

Commit

Permalink
Initial version for Server Automation
Browse files Browse the repository at this point in the history
  • Loading branch information
evertramos committed Aug 6, 2021
1 parent 103f0a6 commit abc494c
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 141 deletions.
117 changes: 74 additions & 43 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,80 +1,111 @@
# .env file to set up your wordpress site
#-----------------------------------------------------------------------
#
# Docker Wordpress .env file
#
# https://github.com/evertramos/docker-wordpress
#
#-----------------------------------------------------------------------

#-----------------------------------------------------------------------
#
# Compose Project Name
#
# This is one of the variables available in Docker Compose command-line
# It will be used for naming conventions the containers, network and
# some other service. Check the refence below for more information:
#
# Compose default env variables
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
#
COMPOSE_PROJECT_NAME=new-site
COMPOSE_PROJECT_NAME=docker-wordpress-compose-project-name

#-----------------------------------------------------------------------
#
# Network name
# NGINX Proxy options
#
# Your container app must use a network conencted to your webproxy
# https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion
# Here you may set NGINX Proxy options, the network must match the proxy
# network, the domain name which will be used by the NGINX and issue
# the tls certificate by the Lets Encrypt, and the required email
#
NETWORK=webproxy
DOCKER_WORDPRESS_NETWORK=proxy

# Your domain (or domains)
DOCKER_WORDPRESS_DOMAINS=domain.com,www.domain.com

# Your email for Let's Encrypt register
DOCKER_WORDPRESS_LETSENCRYPT_EMAIL=[email protected]

#-----------------------------------------------------------------------
#
# Database container options
#
# Database Container options
# WordPress offers by default MySQL or MariaDB as database, make sure to set
# the image version when using this project, once it will be required when
# restoring your site from a backup file or even when cloning your site
#
# [IMPORTANT] We recommend to always set a version when starting a new site.
# When migrating or restoring a backup you must know the running version

# Database image (mariadb|mysql)
DB_IMAGE=mariadb
DOCKER_WORDPRESS_DB_IMAGE=mariadb

# Database version
DB_VERSION=latest

# Database container name
CONTAINER_DB_NAME=new-site-db
DOCKER_WORDPRESS_DB_VERSION=latest

# Path to store your database files
DB_FILES=./data/db
DOCKER_WORDPRESS_DB_FILES=./data/db

# Root password for your database
MYSQL_ROOT_PASSWORD=root_password
DOCKER_WORDPRESS_MYSQL_ROOT_PASSWORD=root_password

# Database name, user and password for your wordpress
MYSQL_DATABASE=database_name
MYSQL_USER=user_name
MYSQL_PASSWORD=user_password
DOCKER_WORDPRESS_MYSQL_DATABASE=database_name
DOCKER_WORDPRESS_MYSQL_USER=user_name
DOCKER_WORDPRESS_MYSQL_PASSWORD=user_password

#-----------------------------------------------------------------------
#
# Wordpress container options
#
# Site Container options
# Here you set the WordPress image and version you want to use for your project
# if you have local image you can use it here as well, just make sure to set
# the image version to make sure compatibility when restoring your site
#
# [IMPORTANT] We recommend to always set a version when starting a new site.
# When migrating or restoring a backup you must know the running version for
# theme and plugins compatibility.

# Site Image (wordpress)
SITE_IMAGE=wordpress
DOCKER_WORDPRESS_SITE_IMAGE=wordpress

# Site Version
SITE_VERSION=latest
DOCKER_WORDPRESS_SITE_VERSION=latest

# Path to store your site files
SITE_FILES=./data/site

# Site container name
CONTAINER_SITE_NAME=new-site-site

# Max Log File Size
LOGGING_OPTIONS_MAX_SIZE=200k
DOCKER_WORDPRESS_SITE_FILES=./data/site

# Table prefix
WORDPRESS_TABLE_PREFIX=wp_
DOCKER_WORDPRESS_TABLE_PREFIX=wp_

# Your domain (or domains)
DOMAINS=domain.com,www.domain.com
#-----------------------------------------------------------------------
#
# Logging options
#
# Please make sure to use this option carefuly, you may need to have some
# log to audit but you might end up to use a lot of disk space if you
# don't limit the maximum file size and the maximum mnumber of files
#
DOCKER_WORDPRESS_SITE_LOG_DRIVER=json-file
DOCKER_WORDPRESS_SITE_LOG_MAX_SIZE=800k
DOCKER_WORDPRESS_SITE_LOG_MAX_FILE=10

# Your email for Let's Encrypt register
LETSENCRYPT_EMAIL=[email protected]
DOCKER_WORDPRESS_DB_LOG_DRIVER=json-file
DOCKER_WORDPRESS_DB_LOG_MAX_SIZE=200k
DOCKER_WORDPRESS_DB_LOG_MAX_FILE=10

#-----------------------------------------------------------------------
#
# Server Automation options
#
# docker-compose service name
# The otions below are used by the script Server Automation to replace
# the strings in docker-compose file and .env file. If you are not
# using the script you may ignore it of delete these options
#
# This variables below are used for the automation process
# and must be the same name used in docker-composer.yml
REPLACE_DB_SERVICE_NAME=new-site-db
REPLACE_SITE_SERVICE_NAME=new-site-wordpress
REPLACE_DB_SERVICE_NAME=docker-wordpress-new-db
REPLACE_SITE_SERVICE_NAME=docker-wordpress-new-site
REPLACE_PROXY_NETWORK_NAME=docker-wordpress-proxy-network

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
data
.idea
93 changes: 21 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,36 @@
## Docker Wordpress [automation]
# Docker Wordpress 🚀

This repo is part of a larger script to changes in the files must be reviewed.

If you are looking of the previous version check branch basic.

# Using Wordpress with SSL enabled integrated with NGINX proxy and autorenew LetsEncrypt certificates
<p align="center">
<a target="_blank" href="https://docs.docker.com/"><img src="https://img.shields.io/badge/Docker-2CA5E0?style=for-the-badge&logo=docker&logoColor=white" /></a>
<a target="_blank" href="https://developer.wordpress.org/"><img src="https://img.shields.io/badge/Wordpress-21759B?style=for-the-badge&logo=wordpress&logoColor=white" /></a>
</p>

![wordpress-docker-letsencrypt](https://github.com/evertramos/images/raw/master/wordpress.jpg)

This docker-compose should be used with WebProxy (the NGINX Proxy):

[https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion)


### Usage

After everything is settle, and you have your three containers running (_proxy, generator and letsencrypt_) you do the following:

1. Clone this repository:

```bash
git clone https://github.com/evertramos/docker-wordpress.git
```

2. Update the service name in your _docker-compose.yml_ file **VERY IMPORTANT**

You must use any name, but make sure it is a unique service name in your environment, otherwise it will conflict with other services.

3. Configure your _.env_ file:

Copy .env.sample to .env and update with your data

> The proxy network must match the network name you have set in the proxy settings.
4. Start your project

```bash
docker-compose up -d
```

**Be patient** - when you first run this repo, the database might take sometime to launch and the process of getting a new certificate for your domain might take some time.
## How to start 🔰

----
This script was designed to work along with [**Server Automation**](https://github.com/evertramos/server-automation),
where you will be able to start a new WordPress site in less than a minute.
You may use directly with your [NGINX Proxy Automation](https://github.com/evertramos/nginx-proxy-automation)
following the [previous docs](./docs/v0.5.md).

#### Make sure the wordpress data files has user and group set to **www-data**, so you could update, install, delete files from your admin panel.
## Known Issues 💭

----
### 1. Azure

Running docker on Azure servers you must mount your database in your disks partitions (example: `/mnt/data/`) so your db container can work. This is a some kind of issue regarding Hyper-V sharing drivers... not really sure why.

#### WebProxy

[WebProxy - docker-compose-letsencrypt-nginx-proxy-companion](https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion)

----

### Further Options

#### wp-cli (https://wp-cli.org/)

For whoever uses *wp-cli* here is how to implement it on this repo.


Test to see if it´s working

```bash
./wp-cli-test.sh

```

If you would, add the alias "wp" to your `.bash_aliases`:

```bash
alias wp="docker-compose run --rm wpcli"
```

Next time you need to run a wp-cli command just go to where you have your docker-compose file and run a `wp` command.

----

### Known Issues
## Versions

#### Azure
The versioning of this project matches the same tag of
[Server Automation](https://github.com/evertramos/server-automation) and
[NGINX proxy automation](https://github.com/evertramos/nginx-proxy-automation).

Running docker on Azure servers you must mount your database in your disks partitions (example: `/mnt/data/`) so your db container can work. This is a some kind of issue regarding Hyper-V sharing drivers... not really sure why.
Table of compatibility:

docker-wordpress | nginx-proxy-automation | server-automation
:---: | :---: | :---:
v0.5 | v0.5 | v0.5

75 changes: 49 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
version: '3'

services:
new-site-db:
container_name: ${CONTAINER_DB_NAME}
image: ${DB_IMAGE:-mariadb}:${DB_VERSION:-latest}
docker-wordpress-new-db:
image: ${DOCKER_WORDPRESS_DB_IMAGE:-mysql}:${DOCKER_WORDPRESS_DB_VERSION:-latest}
restart: unless-stopped
networks:
- docker-wordpress-proxy-network
volumes:
- ${DB_FILES}:/var/lib/mysql
- ${DOCKER_WORDPRESS_DB_FILES}:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DOCKER_WORDPRESS_MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${DOCKER_WORDPRESS_MYSQL_DATABASE}
MYSQL_USER: ${DOCKER_WORDPRESS_MYSQL_USER}
MYSQL_PASSWORD: ${DOCKER_WORDPRESS_MYSQL_PASSWORD}
logging:
driver: ${DOCKER_WORDPRESS_DB_LOG_DRIVER:-json-file}
options:
max-size: ${DOCKER_WORDPRESS_DB_LOG_MAX_SIZE:-1m}
max-file: ${DOCKER_WORDPRESS_DB_LOG_MAX_FILE:-10}

new-site-wordpress:

docker-wordpress-new-site:
depends_on:
- new-site-db
container_name: ${CONTAINER_SITE_NAME}
image: ${SITE_IMAGE:-wordpress}:${SITE_VERSION:-latest}
- docker-wordpress-new-db
image: ${DOCKER_WORDPRESS_SITE_IMAGE:-wordpress}:${DOCKER_WORDPRESS_SITE_VERSION:-latest}
restart: unless-stopped
networks:
- docker-wordpress-proxy-network
- docker-wordpress-db-net
volumes:
- ${SITE_FILES}:/var/www/html
- ${DOCKER_WORDPRESS_SITE_FILES}:/var/www/html
- ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini
environment:
WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306
WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
VIRTUAL_HOST: ${DOMAINS}
LETSENCRYPT_HOST: ${DOMAINS}
LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
WORDPRESS_DB_HOST: ${DOCKER_WORDPRESS_CONTAINER_DB_NAME}:3306
WORDPRESS_DB_NAME: ${DOCKER_WORDPRESS_MYSQL_DATABASE}
WORDPRESS_DB_USER: ${DOCKER_WORDPRESS_MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${DOCKER_WORDPRESS_MYSQL_PASSWORD}
WORDPRESS_TABLE_PREFIX: ${DOCKER_WORDPRESS_TABLE_PREFIX}
VIRTUAL_HOST: ${DOCKER_WORDPRESS_DOMAINS}
LETSENCRYPT_HOST: ${DOCKER_WORDPRESS_DOMAINS}
LETSENCRYPT_EMAIL: ${DOCKER_WORDPRESS_LETSENCRYPT_EMAIL}
# WORDPRESS_AUTH_KEY: ${DOCKER_WORDPRESS_AUTH_KEY:-null}
# WORDPRESS_SECURE_AUTH_KEY: ${DOCKER_WORDPRESS_SECURE_AUTH_KEY:-null}
# WORDPRESS_LOGGED_IN_KEY: ${DOCKER_WORDPRESS_LOGGED_IN_KEY:-null}
# WORDPRESS_NONCE_KEY: ${DOCKER_WORDPRESS_NONCE_KEY:-null}
# WORDPRESS_AUTH_SALT: ${DOCKER_WORDPRESS_AUTH_SALT:-null}
# WORDPRESS_SECURE_AUTH_SALT: ${DOCKER_WORDPRESS_SECURE_AUTH_SALT:-null}
# WORDPRESS_LOGGED_IN_SALT: ${DOCKER_WORDPRESS_LOGGED_IN_SALT:-null}
# WORDPRESS_NONCE_SALT: ${DOCKER_WORDPRESS_NONCE_SALT:-null}
# WORDPRESS_DEBUG: ${DOCKER_WORDPRESS_DEBUG:-null}
# WORDPRESS_CONFIG_EXTRA: ${DOCKER_WORDPRESS_CONFIG_EXTRA:-null}
logging:
driver: ${DOCKER_WORDPRESS_SITE_LOG_DRIVER:-json-file}
options:
max-size: ${LOGGING_OPTIONS_MAX_SIZE:-200k}
max-size: ${DOCKER_WORDPRESS_SITE_LOG_MAX_SIZE:-2m}
max-file: ${DOCKER_WORDPRESS_SITE_LOG_MAX_FILE:-10}

wpcli:
image: tatemz/wp-cli
networks:
- docker-wordpress-db-net
volumes:
- ${SITE_FILES}:/var/www/html
depends_on:
- new-site-db
- docker-wordpress-new-db
entrypoint: wp

networks:
default:
external:
name: ${NETWORK}
docker-wordpress-proxy-network:
external: true
docker-wordpress-db-net:
Loading

0 comments on commit abc494c

Please sign in to comment.