Skip to content

Commit

Permalink
Merge pull request #239 from OneSignal/add_docker_dev_setup
Browse files Browse the repository at this point in the history
Add docker dev setup
  • Loading branch information
jkasten2 authored Mar 31, 2020
2 parents 218b9b9 + a729e98 commit c2230af
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONTAINER=wordpress
WORDPRESS_HTTP_PORT=8000
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ crashlytics-build.properties
.DS_Store

onesignal-extra.php

docker-instance-files/*
# Expection to the rule as we need this files to modify plugin upload limits
!uploads.ini
16 changes: 16 additions & 0 deletions PluginDevDockerUsage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Setup
1. Run `./docker.sh`
2. Go to http://localhost:8000/ in your browser.
3. Follow the WordPress page's setup guide create your user
4. After logging in to the WordPress admin go to "Plugins" > "Add New" > "Upload Plugin"
5. Zip up all file in this directory expect "docker-instance-files"
6. Upload this on the page from step 4. above
7. Make sure to active the plugin on the Plugins page
8. Your done, happy editing!

## Editing
1. Test changes by editing files under docker-instance-files/plugins/
- Modify these directly on your host machine, changes take effect immediately!
2. Make sure to get your changes in to the original source to commit
- Careful not to re-upload your plugin, it will overwrite files docker-instance-files/plugins/

34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.3'

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "${WORDPRESS_HTTP_PORT}:80"
restart: always
container_name: "${CONTAINER}"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
working_dir: /var/www/html
volumes:
- ./docker-instance-files/plugins:/var/www/html/wp-content/plugins
- ./docker-instance-files/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
db_data: {}
5 changes: 5 additions & 0 deletions docker-instance-files/uploads.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600
34 changes: 34 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# The purpose of this script is to provide write access to the wordpress plugins folder for
# both the host machine and the docker container itself.
# This makes plugin testing much easy as the the file in the plugins folder can be directly
# edited on the host machine's IDE.
# This means no more needing to copy files from host->container or using vim in the container!

export $(xargs < .env)

USER_ID=`id -u`
GROUP_ID=`id -g`

# Starting docker images without allowing them to execute anything yet.
# This is so we can correctly set the permission below before it starts creating files
echo "Starting $CONTAINER in --no-start mode"
docker-compose up --no-start $CONTAINER
docker-compose up --detach $CONTAINER

echo "Wait for all wordpress files to be comes available"
docker exec -ti $CONTAINER /bin/bash -c 'until [[ -f .htaccess ]]; do sleep 1; done'

echo "Allowing Wordpress container to modify any files in the docker-instance-file/plugins folder"
docker exec -ti $CONTAINER /bin/bash -c "usermod -u ${USER_ID} www-data"
docker exec -ti $CONTAINER /bin/bash -c "groupmod -g ${GROUP_ID} www-data"
echo "Restart container for permsision settings to take effect"
docker container restart $CONTAINER

echo "Updating '/var/www' folder ownership"
docker exec -ti $CONTAINER /bin/bash -c 'chown -R www-data:www-data /var/www'

echo "Started Scuessfully!"
echo "──────────────────────────────────────────────────────"

echo "Tailing logs"
docker-compose up

0 comments on commit c2230af

Please sign in to comment.