Skip to content

Commit 3b9f744

Browse files
committed
The first commit
0 parents  commit 3b9f744

File tree

16 files changed

+554
-0
lines changed

16 files changed

+554
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.{json,yml,yaml}]
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DB_NAME=wordpress
2+
DB_USER=dbadmin
3+
DB_PASS=secret

.gitattributes

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Define the line ending behavior of the different file extensions
2+
# Set default behaviour, in case users don't have core.autocrlf set.
3+
* text=auto
4+
* text eol=lf
5+
6+
# Explicitly declare text files we want to always be normalized and converted
7+
# to native line endings on checkout.
8+
*.php text
9+
*.default text
10+
*.ctp text
11+
*.sql text
12+
*.md text
13+
*.po text
14+
*.js text
15+
*.css linguist-vendored
16+
*.scss linguist-vendored
17+
*.ini text
18+
*.properties text
19+
*.txt text
20+
*.xml text
21+
*.yml text
22+
.htaccess text
23+
24+
# Declare files that will always have CRLF line endings on checkout.
25+
*.bat eol=crlf
26+
27+
# Declare files that will always have LF line endings on checkout.
28+
*.pem eol=lf
29+
30+
# Denote all files that are truly binary and should not be modified.
31+
*.png binary
32+
*.jpg binary
33+
*.gif binary
34+
*.ico binary
35+
*.mo binary
36+
*.pdf binary
37+
*.phar binary
38+
# font files
39+
*.otf binary
40+
*.eot binary
41+
*.ttf binary
42+
*.woff binary
43+
*.woff2 binary
44+
45+
# Exclude unused files
46+
/.editorconfig export-ignore
47+
/.gitattributes export-ignore
48+
/.gitignore export-ignore
49+
/.travis.yml export-ignore
50+
/CHANGELOG.md export-ignore

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# User specific & automatically generated files #
2+
#################################################
3+
.env
4+
.rnd
5+
*.log
6+
7+
# IDE and editor specific files #
8+
#################################
9+
nbproject
10+
.idea
11+
.vscode
12+
.phpstorm.meta.php
13+
_ide_helper.php
14+
15+
# OS generated files #
16+
######################
17+
.DS_Store
18+
.DS_Store?
19+
._*
20+
.Spotlight-V100
21+
.Trashes
22+
Icon?
23+
ehthumbs.db
24+
Thumbs.db
25+
*.mo
26+
27+
# Elastic Beanstalk Files
28+
.elasticbeanstalk/*
29+
!.elasticbeanstalk/*.cfg.yml
30+
!.elasticbeanstalk/*.global.yml

Dockerrun.aws.json

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"AWSEBDockerrunVersion": 2,
3+
"volumes": [
4+
{
5+
"name": "app-source",
6+
"host": {
7+
"sourcePath": "/var/app/current/app"
8+
}
9+
},
10+
{
11+
"name": "web-config",
12+
"host": {
13+
"sourcePath": "/var/app/current/docker/nginx/default.conf"
14+
}
15+
}
16+
],
17+
"containerDefinitions": [
18+
{
19+
"name": "wp",
20+
"image": "wordpress:5-php7.3-fpm-alpine",
21+
"essential": true,
22+
"environment": [
23+
{
24+
"name": "WORDPRESS_DB_HOST",
25+
"value": "rds-endpoint"
26+
},
27+
{
28+
"name": "WORDPRESS_DB_NAME",
29+
"value": "wordpress"
30+
},
31+
{
32+
"name": "WORDPRESS_DB_USER",
33+
"value": "dbadmin"
34+
},
35+
{
36+
"name": "WORDPRESS_DB_PASSWORD",
37+
"value": "secret"
38+
},
39+
{
40+
"name": "WORDPRESS_DB_CHARSET",
41+
"value": "utf8"
42+
},
43+
{
44+
"name": "WORDPRESS_TABLE_PREFIX",
45+
"value": "wp_"
46+
}
47+
],
48+
"memory": 256,
49+
"links": [
50+
"db"
51+
],
52+
"mountPoints": [
53+
{
54+
"sourceVolume": "app-source",
55+
"containerPath": "/var/www/html",
56+
"readOnly": false
57+
}
58+
]
59+
},
60+
{
61+
"name": "web",
62+
"image": "nginx:stable-alpine",
63+
"essential": true,
64+
"memory": 256,
65+
"links": [
66+
"wp"
67+
],
68+
"volumesFrom": [
69+
{
70+
"sourceContainer": "wp"
71+
}
72+
],
73+
"mountPoints": [
74+
{
75+
"sourceVolume": "web-config",
76+
"containerPath": "/etc/nginx/conf.d/default",
77+
"readOnly": true
78+
},
79+
{
80+
"sourceVolume": "awseb-logs-nginx",
81+
"containerPath": "/var/log/nginx"
82+
}
83+
],
84+
"portMappings": [
85+
{
86+
"hostPort": 80,
87+
"containerPort": 80
88+
}
89+
]
90+
}
91+
],
92+
"localContainerDefinitions": [
93+
{
94+
"name": "db",
95+
"image": "mysql:5.7",
96+
"essential": true,
97+
"environment": [
98+
{
99+
"name": "MYSQL_ROOT_PASSWORD",
100+
"value": "rootpass"
101+
},
102+
{
103+
"name": "MYSQL_DATABASE",
104+
"value": "wordpress"
105+
},
106+
{
107+
"name": "MYSQL_USER",
108+
"value": "dbadmin"
109+
},
110+
{
111+
"name": "MYSQL_PASSWORD",
112+
"value": "secret"
113+
}
114+
]
115+
}
116+
]
117+
}

LICENSE

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

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# oanhnn/example-wordpress-with-docker
2+
3+
An example for developing Wordpress sites with Docker and deploy to AWS Elastic Beanstalk
4+
5+
## Requiments
6+
7+
- Bash
8+
- Git
9+
- Docker
10+
- Docker Compose
11+
12+
## Project organisation
13+
14+
This is what each item is for:
15+
16+
* `app/` – The WordPress application files are in this directory.
17+
* `bin/` – Useful command-line scripts.
18+
* `data/` – MySQL dump files go here.
19+
* `docker/` – Files required by the Docker setup are in this directory.
20+
* `README.md` – Every project needs a README!
21+
* `docker-compose.yml` – Development orchestration config file.
22+
* `Dockerrun.aws.json` - Elastic Beanstalk config file.
23+
24+
## Dev
25+
26+
#### Setup project
27+
28+
```
29+
$ git clone git@github.com:oanhnn/example-wordpress-with-docker.git project_dir
30+
$ cd project_dir
31+
$ cp .env.example .env
32+
$ mkdir app
33+
$ docker-compose up -d
34+
```
35+
36+
#### Backup database
37+
38+
```
39+
$ bin/backup-db.sh data/dump-20190807-102134.sql
40+
```
41+
42+
#### Restore database
43+
44+
```
45+
$ bin/restore-db.sh data/dump-20190807-102134.sql
46+
```
47+
48+
#### Change site URL
49+
50+
```
51+
$ bin/change-url.sh http://dev.example.com https://example.com
52+
```
53+
54+
## Deploy to AWS Elastic Beanstalk
55+
56+
Follow the steps below to deploy this application to an Elastic Beanstalk Multi-container Docker environment. Accept the default settings unless indicated otherwise in the steps below:
57+
58+
1. Download the ZIP file from the Releases section of this repository.
59+
2. Login to the [Elastic Beanstalk Management Console](https://console.aws.amazon.com/elasticbeanstalk)
60+
3. Click ***Create New Application*** and give your app a name and description
61+
4. Click ***Create web server*** and select an IAM instance profile to use.
62+
> Note: Please ensure the IAM instance profile you select has the necessary permissions. For more information, see [Container Instance Role](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_ecs.html#create_deploy_docker_ecs_role)
63+
5. Choose ***Multi-container Docker*** in the ***Predefined configuration*** dropdown and click ***Next***
64+
6. Upload the ZIP file downloaded in step 1
65+
7. Review and launch the application
66+
67+
## Contributing
68+
69+
All code contributions must go through a pull request and approved by a core developer before being merged.
70+
This is to ensure proper review of all the code.
71+
72+
Fork the project, create a feature branch, and send a pull request.
73+
74+
If you would like to help take a look at the [list of issues](https://github.com/oanhnn/example-nginx-proxy-auto-ssl/issues).
75+
76+
## License
77+
78+
This project is released under the MIT License.
79+
Copyright © 2019 [Oanh Nguyen](https://github.com/oanhnn)
80+
Please see [License File](https://github.com/oanhnn/example-nginx-proxy-auto-ssl/blob/master/LICENSE) for more information.

bin/backup-db.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
ROOT_DIR="$( cd `dirname $0` ; cd .. ; pwd -P )"
4+
source "$ROOT_DIR/.env"
5+
6+
file="ROOT_DIR/${1:-data/dump-$(date +%Y%m%d-%H%M%S).sql}"
7+
8+
# Create dump file
9+
cmd='mysqldump -u"$DB_USER" -p"$DB_PASS" "$DB_NAME"'
10+
docker-compose exec db sh -c "$cmd" > $file
11+
12+
# Remove password warning from the file
13+
sed -i '.bak' 1,1d $file && rm "$file.bak"
14+
15+
# Compressing dump file
16+
gzip $file > $file.gz && rm "$file"

bin/change-url.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
FROM_URL=$1
4+
TO_URL=$2
5+
6+
# Replace LIVE_URL using WP-CLI in wp container
7+
cmd='wp --allow-root search-replace "$FROM_URL" "$TO_URL" --skip-columns=guid'
8+
docker-compose exec wp sh -c "$cmd"

bin/restore-db.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
ROOT_DIR="$( cd `dirname $0` ; cd .. ; pwd -P )"
4+
source "$ROOT_DIR/.env"
5+
6+
file=$ROOT_DIR/$1
7+
if [ -z "$file" ]; then
8+
echo "USAGE: restore-db <filename>"
9+
exit 1;
10+
fi
11+
12+
# Uncompressing file
13+
14+
15+
# Restore database to db container
16+
cmd='mysql -u"$DB_USER" -p"$DB_PASS" "$DB_NAME"'
17+
docker exec -i $(docker-compose ps -q db) sh -c "$cmd" < $file

0 commit comments

Comments
 (0)