Skip to content

Commit

Permalink
Merge pull request #3 from lucernae/master
Browse files Browse the repository at this point in the history
Upgrade configuration files
  • Loading branch information
lucernae authored Oct 30, 2019
2 parents 46d7e93 + 55615e1 commit ec72b38
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ backups/*.sql
db/*
*.tar
.idea

venv

# Credential files
sftp_db_credential.env
sftp_media_credential.env
wordpress_credential.env
mysql_credential.env

# Ignore folders
sftp_backup/backups/db/*
Expand Down
38 changes: 29 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
# Set this to the name of your project / website
# ------------------------------------------------------------------------
PROJECT_ID := inasafeorg
PASSWORD := wheatsworth499
CONF_FILE := -f docker-compose.yml
CONF_HELP := Uses docker-compose.yml

UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Linux)
CONF_HELP := Detecting Linux Environment. Use docker-compose-linux.yml
CONF_FILE += -f docker-compose-linux.yml
endif
ifeq ($(UNAME_S),Darwin)
CONF_HELP := Detecting OSX Environment. Use docker-compose-osx.yml
CONF_FILE += -f docker-compose-osx.yml
endif


# ------------------------------------------------------------------------
# Should not normally need to change anything below this point....
Expand All @@ -20,15 +33,17 @@ build:
@echo "------------------------------------------------------------------"
@echo "Building "
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) build
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) build

web:
@echo
@echo "------------------------------------------------------------------"
@echo "Running "
@echo "------------------------------------------------------------------"
@DB_PASS=$(PASSWORD) MYSQL_PASS=$(PASSWORD) docker-compose -p $(PROJECT_ID) up -d wordpress
@docker-compose -p $(PROJECT_ID) up -d btsync
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) up -d wordpress
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) up -d btsync
dps


Expand All @@ -46,36 +61,41 @@ kill:
@echo "------------------------------------------------------------------"
@echo "Killing all containers!"
@echo "------------------------------------------------------------------"
@echo $(CONF_HELP)

@docker-compose -p $(PROJECT_ID) kill
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) kill

rm: kill
@echo
@echo "------------------------------------------------------------------"
@echo "Removing all containers!!! "
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) rm
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) rm

wplogs:
@echo
@echo "------------------------------------------------------------------"
@echo "Showing wordpress logs "
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) logs wordpress
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) logs wordpress

dblogs:
@echo
@echo "------------------------------------------------------------------"
@echo "Showing mysql logs "
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) logs db
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) logs db

wpshell:
@echo
@echo "------------------------------------------------------------------"
@echo "Shelling in to wordpress (press enter to activate shell)"
@echo "------------------------------------------------------------------"
@docker-compose -p $(PROJECT_ID) run wordpress /bin/bash
@echo $(CONF_HELP)
@docker-compose $(CONF_FILE) -p $(PROJECT_ID) run wordpress /bin/bash

dbshell:
@echo
Expand Down
9 changes: 5 additions & 4 deletions backups/db-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ MONTH=$(date +%m)
BACKUP_PATH=/backups/${YEAR}/${MONTH}
mkdir -p $BACKUP_PATH

mysqldump wordpress -u root > ${BACKUP_PATH}/${DATE}.sql
# Directly create backups to target folder and feed
# it to sftp backup.
# sftp backup will handle the versioning
mysqldump wordpress -u root > /target/wordpress.sql

chown -R ${USER_ID}.${GROUP_ID} /backups

# copy latest backup to target dir
cp ${BACKUP_PATH}/${DATE}.sql /target/wordpress.sql
chown -R ${USER_ID}.${GROUP_ID} /target
5 changes: 5 additions & 0 deletions docker-compose-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Specific docker-compose configuration files for Linux
db:
volumes:
# Enable this in linux because we want to persist the db
- .db:/var/lib/mysql
16 changes: 16 additions & 0 deletions docker-compose-osx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Specific docker-compose configuration files for OSX
dbstorage:
image: busybox
hostname: db.storage
volumes:
- /var/lib/mysql

db:
volumes:
- ./backups:/backups
- ./sftp_backup/target/db:/target
volumes_from:
# Special treatment for OSX because it doesn't work to mount db
# folder directly
# See https://github.com/tutumcloud/tutum-docker-mariadb/issues/5
- dbstorage
23 changes: 14 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## Base compose configuration

wordpress:
image: tutum/wordpress-stackable
hostname: inasafe.org
restart: unless-stopped
links:
links:
- db
- sftpmediabackup:sftpmediabackup
- sftpdbbackup:sftpdbbackup
Expand All @@ -14,9 +16,12 @@ wordpress:
# Environment variables with only a key are resolved to their
# values on the machine Compose is running on.
# so make sure to set the DB_PASS env var before using this config file
DB_PASS:
# DB_PASS:
DB_HOST: db
DB_PORT: 3306
env_file:
# Wordpress credentials, set the DB_PASS environment
- wordpress_credential.env
volumes_from:
# so we can have /backups folder for making backups
- db
Expand Down Expand Up @@ -72,21 +77,21 @@ sftpmediabackup: &sftpmediabackup

db:
hostname: db.inasafe.org
image: tutum/mysql:5.5
build: docker-db
restart: unless-stopped
links:
- sftpdbbackup:sftpdbbackup
environment:
# Environment variables with only a key are resolved to their
# values on the machine Compose is running on.
# so make sure to set the MYSQL_PASS env var before using this config file
MYSQL_PASS:
env_file:
# Make sure to set the MYSQL_PASS env var before using this config file
# set MYSQL_PASS environment
- mysql_credential.env
volumes:
- ./backups:/backups
- ./sftp_backup/target/db:/target
# This will not work on OSX/Win - comment out for those oses
# See https://github.com/tutumcloud/tutum-docker-mariadb/issues/5
- db:/var/lib/mysql
# The linux configuration will override this for production mode
# - ./db:/var/lib/mysql

btsync:
image: kartoza/btsync
Expand Down
4 changes: 4 additions & 0 deletions docker-db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM tutum/mysql:5.5
MAINTAINER Rizky Maulana Nugraha <[email protected]>

ADD backups-cron /etc/cron.d/backups-cron
9 changes: 9 additions & 0 deletions docker-db/backups-cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For testing - run every minute
*/1 * * * * root /backups/db-backup.sh 2>&1

# Run the backups at 10pm each night
# This is because SFTP backup is run at 11pm each night
# This is to make sure pg backup is finished before then
#0 22 * * * root /backups/db-backup.sh 2>&1

# We need a blank line here for it to be a valid cron file
2 changes: 2 additions & 0 deletions mysql_credential.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# copy this template as wordpress_credential.env for production mode credential
MYSQL_PASS=wheatsworth499
2 changes: 2 additions & 0 deletions wordpress_credential.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# copy this template as wordpress_credential.env for production mode credential
DB_PASS=wheatsworth499
2 changes: 2 additions & 0 deletions wordpress_credential.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# copy this template as wordpress_credential.env for production mode credential
DB_PASS=wheatsworth499

0 comments on commit ec72b38

Please sign in to comment.