Skip to content

Commit

Permalink
Add sample WordPress project (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd authored Apr 13, 2019
1 parent 21feef7 commit 71be818
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
/examples/
/node_modules/
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.{json,yml,yaml,js}]
indent_style = space
indent_size = 2

[Vagrantfile]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor
/.vagrant
/composer.lock
/node_modules
/composer.lock
Gemfile.lock
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: ruby

install:
- bundle install

script:
- bash -c 'shopt -s globstar; shellcheck **/*.sh'
- rubocop

notifications:
email: false

branches:
only:
- master
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'rubocop'
26 changes: 12 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
projectPath = ENV["PWD"]
localPath = File.dirname(__FILE__)
project_path = ENV['PWD']
local_path = File.dirname(__FILE__)

Vagrant.configure(2) do |config|

config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder projectPath, "/vagrant"
config.vm.box = 'ubuntu/xenial64'
config.vm.network 'private_network', type: 'dhcp'
config.vm.synced_folder project_path, '/vagrant'

# Rename ubuntu-xenial-16.04-cloudimg-console.log to console.log
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--uartmode1", "file", "console.log"]
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--uartmode1', 'file', 'console.log']
end

config.vm.provision :shell,
path: File.join(localPath, 'scripts/vagrant/provision.sh')

config.vm.provision :shell,
path: File.join(localPath, 'scripts/vagrant/up.sh'),
run: "always"
config.vm.provision 'shell',
path: File.join(local_path, 'scripts/vagrant/provision.sh')

config.vm.provision 'shell',
path: File.join(local_path, 'scripts/vagrant/up.sh'),
run: 'always'
end
3 changes: 3 additions & 0 deletions examples/wordpress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/.vagrant/
/composer.lock
9 changes: 9 additions & 0 deletions examples/wordpress/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configure the hostname.
Vagrant.configure(2) do |config|
config.vm.hostname = 'wpsh-local'
end

load File.join(
File.dirname(__FILE__),
'vendor/wpsh/local/Vagrantfile'
)
6 changes: 6 additions & 0 deletions examples/wordpress/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": {},
"require-dev": {
"wpsh/local": "*"
}
}
44 changes: 44 additions & 0 deletions examples/wordpress/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3'

services:

mysql:
image: mysql:5
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password

wordpress:
image: wordpress:latest
links:
- mysql:mysql
depends_on:
- mysql
ports:
- "80:80"
- "443:443"
volumes:
- wp_data:/var/www/html
- "./plugin:/var/www/html/wp-content/plugins/plugin:ro" # Without "ro" flags it can't access the directory.
restart: always
environment:
WORDPRESS_DEBUG: 1
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password

wpcli:
image: wordpress:cli
depends_on:
- mysql
- wordpress
volumes:
- wp_data:/var/www/html

volumes:
db_data: {}
wp_data: {}
11 changes: 11 additions & 0 deletions examples/wordpress/plugin/plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Plugin Name: Demo Plugin Red
* Version: 0.0.1
*/

add_action( 'wp_footer', function() {
?>
<style type="text/css">body { background-color: red; }</style>
<?php
} );
9 changes: 9 additions & 0 deletions examples/wordpress/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# WordPress Development Environment

An example of a WordPress development environment created using Docker running inside Vagrant.

- `Vagrantfile` loads the Vagrant virtual environment defined in `vendor/wpsh/local/Vagrantfile`.

- `docker-compose.yaml` defines the development environment -- mounts the `plugin` directory to `/var/www/html/wp-content/plugins/plugin` inside the Docker container.

Use `vagrant up` to start the environment which will be available at `wpsh-local.local`.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@wpsh/local",
"version": "1.0.0",
"description": "A Docker Compose development environment for any project.",
"homepage": "https://github.com/wpsh/wpsh-local#readme",
"author": "Kaspars Dambis",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/wpsh/wpsh-local.git"
Expand All @@ -10,8 +13,5 @@
"docker-compose",
"docker",
"vagrant"
],
"author": "",
"license": "MIT",
"homepage": "https://github.com/wpsh/wpsh-local#readme"
]
}
43 changes: 32 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
# Local Development Environment

Use this package to quickly add a development environment to your project.
[![Build Status](https://travis-ci.com/wpsh/wpsh-local.svg?branch=master)](https://travis-ci.com/wpsh/wpsh-local)

Add this to any project with `docker-compose.yaml` to run the containers inside Vagrant. Useful for creating friendly development environments with beautiful hostnames (no port numbers) that don't require Docker on the host machine.


## Requirements

- [Vagrant](https://www.vagrantup.com/)
- [VirtualBox](https://www.virtualbox.org/)
- [Vagrant](https://www.vagrantup.com)
- [VirtualBox](https://www.virtualbox.org)

We suggest using [Homebrew](https://brew.sh) to install the dependencies:

brew cask install virtualbox vagrant


## Install

1. Add this package to your project using [Composer](https://getcomposer.org):

composer require --dev wpsh/local
composer require --dev wpsh/local

2. Add `Vagrantfile` to the root of your project with the following contents:

load File.join(
File.dirname(__FILE__),
'vendor/wpsh/local/Vagrantfile'
)
# Configure the hostname.
Vagrant.configure(2) do |config|
config.vm.hostname = 'wpsh-local'
end

where `vendor/wpsh/local` is the relative path to this packge.
load File.join(
File.dirname(__FILE__),
'vendor/wpsh/local/Vagrantfile'
)

where `vendor/wpsh/local` is the relative path to this packge.

3. Create `docker-compose.yaml` in the root of your project to define the virtual environment.


## Examples

- See [`examples/wordpress`](examples/wordpress) for a sample WordPress development environment.
- [Block Context WordPress plugin](https://github.com/preseto/block-context).


## Development

[Travis CI](https://travis-ci.com/wpsh/wpsh-local) lints all shell scripts in `scripts/vagrant` using [shellcheck](https://www.shellcheck.net) and `Vagrantfile` (and other Ruby files) using [rubocop](https://github.com/rubocop-hq/rubocop).


## To Do

- Add support for installing via `npm`.
- Automatically create the project `Vagrantfile` on the first install.
- Add examples of `docker-compose.yaml` for various projects.


## Credits
Expand All @@ -41,4 +62,4 @@ Created by [Kaspars Dambis](https://kaspars.net).

## License

See the LICENSE file for license rights and limitations (MIT).
See the LICENSE file for license rights and limitations (MIT).
4 changes: 2 additions & 2 deletions scripts/vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

# Map binary name to source URL.
REPOS=(
"docker-compose,https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m`"
"docker-compose,https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)"
)

# Add the Docker repo.
Expand All @@ -30,4 +30,4 @@ for repo_set in "${REPOS[@]}"; do
chmod +x "$dest_path"
fi
done <<< "$repo_set"
done
done
5 changes: 3 additions & 2 deletions scripts/vagrant/up.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

cd /vagrant
# See https://github.com/koalaman/shellcheck/wiki/SC2164 for why the exit.
cd /vagrant || exit

docker-compose up --detach --remove-orphans

echo "Done! Please wait a few seconds before the containers are up."
echo "Hostname: $HOSTNAME"
echo "Hostname: $HOSTNAME"

0 comments on commit 71be818

Please sign in to comment.