Skip to content

Commit 7255bd0

Browse files
committed
basic wordpress env
Signed-off-by: BlackEagle <[email protected]>
0 parents  commit 7255bd0

22 files changed

+1294
-0
lines changed

.env-sample

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# Configure what UID and GID your PHP container must use. This usually should
3+
# match your Hosts UID and GID. To find your local UID you can run id -u and
4+
# to find your local GID you can run id -g.
5+
#
6+
C_UID=1000
7+
C_GID=1000
8+
9+
#
10+
# Choose your PHP version. To see which versions are available see
11+
# https://github.com/dockerwest/php-wordpress
12+
#
13+
PHPVERSION=7.4
14+
15+
#
16+
# Choose what version of Nginx you want. To see which versions are available
17+
# see https://github.com/dockerwest/nginx-wordpress
18+
#
19+
NGINXVERSION=stable
20+
#
21+
22+
#
23+
# Choose your NodeJS version. To see which versions are available see
24+
# https://github.com/dockerwest/nodejs
25+
#
26+
NODEVERSION=10
27+
28+
#
29+
# Choose your MySQL version. To see which versions are available see
30+
# https://github.com/docker-library/mysql
31+
#
32+
MYSQLVERSION=8
33+
34+
#
35+
# This setting defines what the hostname will be you can browse your pimcore app.
36+
# The example configuration will be give you http://pimcore.docker.
37+
#
38+
BASEHOST=wordpress.docker
39+
# comma separated to the EXTRAHOSTS variable, when not needed you must at least
40+
# add something, let us default to www.${BASEHOST}
41+
EXTRAHOSTS=www.wordpress.docker
42+
43+
#
44+
# Choose whatever you want to use as default mysql root password.
45+
#
46+
MYSQL_ROOT_PASSWORD=toor
47+
48+
#
49+
# A relative or absolute path to your pimcore code.
50+
#
51+
APPLICATION=../wordpress
52+
53+
#
54+
# The `DEVELOPMENT` environment variable wich will enable xdebug, composer and
55+
# enable timestamp checking in opcache.
56+
#
57+
DEVELOPMENT=1
58+
59+
#
60+
# Set the default window manager when running the environment
61+
# Available options are: tmux, screen and byobu
62+
#
63+
WINDOW_MANAGER=tmux

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
__pycache__
3+
*.pyc

LICENSE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright © `2017-2020` `DockerWest contributors`
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the “Software”), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.
26+

README.md

+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
PHP basic developer environment
2+
===============================
3+
4+
Basic developer environment for Wordpress apps.
5+
6+
Usage
7+
-----
8+
9+
For your convenience the developer environment has some helpers which take away
10+
some difficulties you could experience using docker containers.
11+
12+
If you want this easy helpers to be readily available for you you can use
13+
`environment` before you start. `environment` allows you to start your
14+
environment with an updated `PATH` and allows you to choose between `tmux`,
15+
`screen` or `byobu`. You can also define a default in the .env file.
16+
17+
explicit setting the window manager:
18+
19+
~~~ sh
20+
$ ./environment [tmux|screen|byobu]
21+
~~~
22+
23+
using default window manager, defined in .env
24+
25+
~~~ sh
26+
$ ./environment
27+
~~~
28+
29+
When you are running in this environment all helpers are available in your path.
30+
31+
You are not required to use the environent, but then you have to call the
32+
helpers with their full path.
33+
34+
To make use of the helpers you should use the `run` wrapper for `docker-compose`.
35+
36+
~~~ sh
37+
$ run up
38+
~~~
39+
40+
Configuration
41+
-------------
42+
43+
There is a sample configuration `.env-sample` which contains the defaults used
44+
in this environment.
45+
46+
If you want to change some of these values, copy `.env-sample` to `.env` and
47+
start editing.
48+
49+
default `.env-sample`
50+
51+
~~~
52+
C_UID=1000
53+
C_GID=1000
54+
PHPVERSION=7.1
55+
NGINXVERSION=stable
56+
BASEHOST=application.dev
57+
MYSQL_ROOT_PASSWORD=toor
58+
APPLICATION=../application
59+
DEVELOPMENT=1
60+
WINDOW_MANAGER=tmux
61+
~~~
62+
63+
### C_UID / C_GID
64+
65+
Configure what UID and GID your PHP container must use. This usually should
66+
match your Hosts UID and GID. To find your local UID you can run `id -u` and to
67+
find your local GID you can run `id -g`.
68+
69+
### PHPVERSION
70+
71+
Choose your PHP version. To see which versions are available
72+
[here](https://gitlab.com/dockerwest/image/php-wordpress).
73+
74+
### NGINXVERSION
75+
76+
Choose what version of Nginx you want. To see which versions are available see
77+
[here](https://gitlab.com/dockerwest/image/nginx-wordpress)
78+
79+
### BASEHOST
80+
81+
This setting defines what the hostname will be you can browse your wordpress app.
82+
The example configuration will be give you `http://application.dev`.
83+
84+
### MYSQL_ROOT_PASSWORD
85+
86+
Choose whatever you want to use as default root password.
87+
88+
### APPLICATION
89+
90+
A relative or absolute path to your application code. this can be a checkout of any wordpress project
91+
92+
### DEVELOPMENT
93+
94+
There is the `DEVELOPMENT` environment variable wich will enable xdebug,
95+
composer and enable timestamp checking in opcache.
96+
97+
When `DEVELOPMENT` is enabled xdebug should work out of the box. When you have
98+
issues - like while running docker for mac - you can set the extra environment
99+
variable `XDEBUG_CONFIG` with your hosts ip in it so xdebug can properly
100+
connect back.
101+
102+
### WINDOW_MANAGER
103+
Set the default window manager when running the environment.
104+
Available options are: tmux, screen and byobu
105+
106+
Helpers
107+
-------
108+
109+
The helpers are written in python, so you should have python2 or python3
110+
installed on your system to be able to use them. Most Linux distributions and
111+
macOS have python already installed so there should be no issue there. There
112+
are no extra dependencies on python modules.
113+
114+
### wp
115+
116+
Run the [wp](https://wp-cli.org) command inside the running php container, or inside a php-wordpress container if none is running.
117+
The working directory will be the current directory you are executing this command from.
118+
119+
eg. `$ wp --version`
120+
121+
### composer
122+
123+
Run the [composer](https://getcomposer.org/) command inside the php docker container.
124+
The working directory will be the current directory you are executing this command from.
125+
Your $HOME/.ssh and $HOME/.composer folders wil be mounted inside this container to enable you to make use of your ssh keys and composer cache.
126+
127+
eg. `$ composer require package_name`
128+
129+
### create_db
130+
Create a new database inside the running mysql container with the name 'pimcore' and 'DEFAULT CHARSET utf8'.
131+
132+
eg. `$ create_db`
133+
134+
### mysql
135+
Execute a mysql command inside the running mysql container as the root user.
136+
137+
eg. `$ mysql "SELECT * FROM table_name;"`
138+
139+
### mysqldump
140+
Execute the mysqldump command inside the running mysql container as the root user.
141+
142+
eg. `$ mysqldump db_name > export_file_name.sql`
143+
144+
### mysqlimport
145+
Import a given mysql file into a given database, inside the running mysql container as the root user.
146+
147+
eg. `$ mysqlimport db_name import_file_name.sql`
148+
149+
### node
150+
Execute the [node](https://nodejs.org) command inside a node container.
151+
The working directory will be the current directory you are executing this command from.
152+
153+
eg. `$ node js_file.js`
154+
155+
### npm
156+
Execute the [npm](https://www.npmjs.com/) command inside a node container.
157+
The working directory will be the current directory you are executing this command from.
158+
Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.
159+
160+
eg. `$ npm install package_name`
161+
162+
### yarn
163+
Execute the [yarn](https://yarnpkg.com) command inside a node container.
164+
The working directory will be the current directory you are executing this command from.
165+
Your $HOME/.ssh and $HOME/.npm folders wil be mounted inside this container to enable you to make use of your ssh keys and npm cache.
166+
167+
eg. `$ yarn add package_name`
168+
169+
### php
170+
Execute the php command inside the running php container, or inside a php-pimcore container if none is running.
171+
The working directory will be the current directory you are executing this command from.
172+
173+
eg. `$ php -v`
174+
175+
### redis-cli
176+
Execute the [redis-cli](https://redis.io/topics/rediscli) command in the running redis container.
177+
178+
eg. `$ redis-cli flushall`
179+
180+
### run
181+
Run docker-compose for the current project, setting the project name to the BASEHOST variable from the .env file
182+
183+
eg. `$ run up`
184+
185+
Tricks
186+
------
187+
188+
### macOS
189+
190+
For this environment to work properly you should install gnu coreutils
191+
192+
using homebrew:
193+
194+
~~~ sh
195+
$ brew install coreutils
196+
~~~
197+
198+
On macOS you could just install docker from the docker site and run like this.
199+
But our experience is that the native docker install is fairly slow to use. We
200+
would suggest you to install [dinghy](https://github.com/codekitchen/dinghy).
201+
202+
[install dinghy](https://github.com/codekitchen/dinghy#install) and install the
203+
VM technology you want to use. If you want native xhyve support you can
204+
additionally install
205+
[xhyve driver for docker machine](https://github.com/zchee/docker-machine-driver-xhyve).
206+
207+
If you have dinghy installed this environment will try to use it.
208+
209+
Currently there is an annoying limitation when we are using dinghy and that is
210+
that the hostnames used must end with `docker`.
211+
212+
### oh-my-zsh users
213+
214+
[oh-my-zsh](http://ohmyz.sh/) users should check if there is no fixed setting
215+
for `$PATH` in their `~/.zshrc`. If that is the case you can safely comment it
216+
out. If somewhere in your shell startup `$PATH` is forced you lose the features
217+
the `./environment` script brings to you.
218+
219+
License
220+
-------
221+
222+
MIT License (MIT). See [License File](LICENSE.md) for more information.

bin/composer

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
import re
7+
from environment import Environment
8+
9+
currentpath = os.getcwd()
10+
composepath = os.path.abspath(os.path.dirname(sys.argv[0]) + '/../')
11+
12+
sshconfigpath = os.getenv("HOME") + '/.ssh'
13+
composerconfigpath = os.getenv("HOME") + '/.composer'
14+
15+
# make sure .ssh and .composer exist in the users home
16+
if not os.path.exists(sshconfigpath):
17+
os.mkdir(sshconfigpath)
18+
if not os.path.exists(composerconfigpath):
19+
os.mkdir(composerconfigpath)
20+
21+
env = Environment(composepath + '/.env')
22+
23+
cmd = [
24+
os.path.dirname(sys.argv[0]) + '/run',
25+
'ps', 'application'
26+
]
27+
28+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
29+
try:
30+
p.wait()
31+
except KeyboardInterrupt:
32+
try:
33+
p.terminate()
34+
except OSError:
35+
pass
36+
p.wait()
37+
out, err = p.communicate()
38+
out = out.decode('utf-8')
39+
40+
dockerrun = ['docker', 'run', '--rm']
41+
if sys.stdin.isatty() and sys.stdout.isatty():
42+
dockerrun += ['-it']
43+
44+
cmd = dockerrun
45+
46+
if re.search('Up', out):
47+
containercmd = [
48+
os.path.dirname(sys.argv[0]) + '/run',
49+
'ps', '-q', 'application'
50+
]
51+
52+
p = subprocess.Popen(containercmd, stdout=subprocess.PIPE)
53+
try:
54+
p.wait()
55+
except KeyboardInterrupt:
56+
try:
57+
p.terminate()
58+
except OSError:
59+
pass
60+
p.wait()
61+
out, err = p.communicate()
62+
applicationcontainer = out.decode('utf-8').strip()
63+
cmd += [
64+
'--pid=container:' + applicationcontainer,
65+
'--net=container:' + applicationcontainer
66+
]
67+
68+
cmd += [
69+
'-v', sshconfigpath + ":/var/www/.ssh",
70+
'-v', composerconfigpath + ":/var/www/.composer",
71+
'-v', currentpath + ":/phpapp",
72+
'-e', "DEVELOPMENT=" + env.get('DEVELOPMENT'),
73+
'-e', "C_UID=" + env.get('C_UID'),
74+
'-e', "C_GID=" + env.get('C_GID'),
75+
'-e', "COMPOSER_MEMORY_LIMIT=-1",
76+
'dockerwest/php-wordpress:' + env.get('PHPVERSION'),
77+
'composer'
78+
] + sys.argv[1:]
79+
80+
os.execvp(cmd[0], cmd)

0 commit comments

Comments
 (0)