Skip to content

Commit 260598c

Browse files
committed
Rework makefile commands, instruction, add correct nginx config, add index.php file in the public dir, remove node Dockerfile
1 parent 23540f7 commit 260598c

File tree

14 files changed

+191
-152
lines changed

14 files changed

+191
-152
lines changed

.env.dist

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,46 @@ NGINX_SITE_DOMAIN=wp-docker-boilerplate.local
1212

1313

1414
#############################
15-
# Common
15+
# PHP
1616
#############################
17-
HH_SITE_DOMAIN=${NGINX_SITE_DOMAIN}:${NGINX_PORT}
17+
PHP_VER=7.4
1818

1919

2020
#############################
2121
# MySQL settings
2222
#############################
2323
MYSQL_PORT=3307
24-
MYSQL_DATABASE=charity_local
24+
MYSQL_DATABASE=wordpress
2525
MYSQL_USER=admin
26-
MYSQL_PASSWORD=lKJH5jkjg234ds
27-
MYSQL_ROOT_PASSWORD=lKJH5jkjg234ds
26+
MYSQL_PASSWORD=12345
27+
MYSQL_ROOT_PASSWORD=12345
2828
MYSQL_TZ=Europe/Moscow
2929

30-
3130
#############################
3231
# PhpMyAdmin settings
3332
#############################
3433
PMA_PORT=8082
3534

3635

36+
#############################
37+
# NODE
38+
#############################
39+
NODE_VER="16.14.2"
40+
41+
42+
#############################
43+
# Common
44+
#############################
45+
SITE_DOMAIN=${NGINX_SITE_DOMAIN}:${NGINX_PORT}
46+
47+
3748
#############################
3849
# WordPress config settings
3950
#############################
40-
HH_INSTALL_ADMIN_TITLE="Wordpress docker boilerplate"
41-
HH_INSTALL_ADMIN_LOGIN=admin
42-
HH_INSTALL_ADMIN_PASSWORD=12345
43-
HH_INSTALL_ADMIN_EMAIL=admin@${NGINX_SITE_DOMAIN}
51+
INSTALL_ADMIN_TITLE="WordPress Docker Boilerplate Site"
52+
INSTALL_ADMIN_LOGIN=admin
53+
INSTALL_ADMIN_PASSWORD=
54+
INSTALL_ADMIN_EMAIL=admin@${NGINX_SITE_DOMAIN}
4455

4556
WP_CORE_VERSION=5.7.1
4657
WP_CORE_LOCALE=en_US

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Configuration files
33
##################################
44
.env
5+
docker-compose.override.yaml
56
docker/mysql/backup/*
67
!docker/mysql/backup/.gitkeep
78
vendor/
@@ -11,9 +12,8 @@ node_modules/
1112

1213
# Project public files
1314
##################################
14-
!/public/index.php
15-
1615
public/*
16+
!/public/index.php
1717
!public/wp-content
1818
public/wp-content/*
1919

Makefile

100644100755
Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,135 @@
11
include .env
22
export
33

4-
UID = $(shell id -u)
5-
GUID = $(shell id -g)
6-
7-
# Build
8-
build: d.up
9-
@$(MAKE) c.install
10-
@$(MAKE) wp.core.download
4+
#UID = $(shell id -u)
5+
#GUID = $(shell id -g)
116

7+
##########################
128
# Docker
13-
d.ps:
14-
docker ps
9+
##########################
10+
d:
11+
docker $(filter-out $@,$(MAKECMDGOALS))
1512

1613
d.up:
1714
docker-compose up -d
1815

16+
d.ps:
17+
docker ps
18+
1919
d.restart: d.down
2020
@$(MAKE) up
2121

2222
d.down:
2323
docker-compose down --remove-orphans
2424

25-
d.build-image:
26-
docker-compose up -d --no-deps --build $(filter-out $@,$(MAKECMDGOALS))
25+
d.compose:
26+
docker-compose $(filter-out $@,$(MAKECMDGOALS))
2727

28-
d.build-all-images:
29-
docker-compose up -d --no-deps --build
28+
d.build:
29+
docker-compose up --no-deps -d --build $(filter-out $@,$(MAKECMDGOALS))
3030

31-
d.recreate-container:
32-
docker-compose up -d --force-recreate $(filter-out $@,$(MAKECMDGOALS))
31+
d.build.all:
32+
docker-compose up -d --build
3333

34-
d.recreate-all-containers:
35-
docker-compose up -d --force-recreate
34+
d.recreate:
35+
docker-compose up --no-deps -d --build $(filter-out $@,$(MAKECMDGOALS))
3636

37-
d.bash:
38-
docker-compose exec $(filter-out $@,$(MAKECMDGOALS)) bash
37+
d.recreate.all:
38+
docker-compose up -d --force-recreate
3939

4040
d.test:
4141
docker run hello-world
4242

43+
##########################
44+
# Nginx
45+
##########################
46+
nginx.connect:
47+
docker-compose exec nginx sh
48+
4349

44-
connect.php:
50+
##########################
51+
# PHP
52+
##########################
53+
php.connect:
4554
docker-compose exec php bash
4655

56+
php.connect.root:
57+
docker-compose exec --user=root php bash
4758

59+
60+
##########################
4861
# MySQL
62+
##########################
63+
mysql.connect:
64+
docker-compose exec mysql bash
65+
#docker-compose exec mysql mysql -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE}
66+
67+
mysql.client.connect:
68+
docker-compose exec mysql sh -c 'echo "Import db" && mysql -u${DB_USER} -p${DB_PASSWORD}'
69+
4970
mysql.export:
5071
docker-compose exec mysql bash -c "mysqldump -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} > backup-`date +"\%Y.\%m.\%d_\%H-\%M-\%s"`.sql \
5172
&& chown -R ${UID}:${GUID} ./*"
5273

5374
mysql.import:
5475
docker-compose exec mysql mysql -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} < import_db.sql
5576

56-
mysql.connect:
57-
docker-compose exec mysql mysql -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE}
5877

5978

79+
80+
##########################
6081
# Composer
61-
c:
62-
docker-compose exec php composer $(filter-out $@,$(MAKECMDGOALS))
82+
##########################
83+
# Root directory
84+
composer:
85+
cd ${PATH_TO_DOCKER} && docker-compose exec php composer $(filter-out $@,$(MAKECMDGOALS))
6386

64-
c.install:
87+
composer.install:
6588
docker-compose exec php composer install $(filter-out $@,$(MAKECMDGOALS))
6689

67-
c.install-production:
68-
docker-compose exec php composer install --no-dev
69-
70-
c.update:
90+
composer.update:
7191
docker-compose exec php composer update $(filter-out $@,$(MAKECMDGOALS))
7292

73-
c.update-production:
74-
docker-compose exec php composer update --no-dev
7593

94+
##########################
95+
# Node
96+
##########################
97+
node.connect:
98+
docker run -it --rm --name=npm -v "$(PWD)/:/usr/src/app" -w="/usr/src/app/" "node:${NODE_VER}" bash
7699

77-
# Front
78-
npm.install:
79-
docker-compose run --rm node npm install
100+
node.install:
101+
docker run -it --rm --name=npm -v "$(PWD)/:/usr/src/app" -w="/usr/src/app/" "node:${NODE_VER}" npm install
80102

81-
npm.ci:
82-
docker-compose run --rm node npm ci
103+
node.ci:
104+
docker run -it --rm --name=npm -v "$(PWD)/:/usr/src/app" -w="/usr/src/app/" "node:${NODE_VER}" npm ci
83105

84-
npm.update:
85-
docker-compose run --rm node npm update
106+
node.update:
107+
docker run -it --rm --name=npm -v "$(PWD)/:/usr/src/app" -w="/usr/src/app/" "node:${NODE_VER}" npm update
86108

87109
npm.webpack-start:
88-
docker-compose run --rm node npm start
110+
docker run -it --rm --name=npm -v "$(PWD)/:/usr/src/app" -w="/usr/src/app/" "node:${NODE_VER}" node npm start
89111

90112

113+
##########################
114+
# Linters
115+
##########################
116+
#lint.php:
117+
# docker-compose exec php sh -c 'composer run phpcs'
118+
#
119+
#lint.php.fix:
120+
# docker-compose exec php sh -c 'composer run phpcbf'
121+
122+
123+
##########################
124+
# Tests
125+
##########################
126+
#unit.run:
127+
# docker-compose exec php sh -c 'phpunit --do-not-cache-result'
128+
129+
130+
##########################
91131
# WP-CLI
132+
##########################
92133
wp:
93134
docker-compose exec php wp --allow-root $(filter-out $@,$(MAKECMDGOALS))
94135

@@ -99,8 +140,12 @@ wp.core.download:
99140
docker-compose exec php wp core download --force --version=${WP_CORE_VERSION} --locale=${WP_CORE_LOCALE}
100141

101142
wp.core.install:
102-
docker-compose exec php wp core install --url=${HH_SITE_DOMAIN} --title=${HH_INSTALL_ADMIN_TITLE} --admin_user=${HH_INSTALL_ADMIN_LOGIN} --admin_email=${HH_INSTALL_ADMIN_EMAIL} --admin_password=${HH_INSTALL_ADMIN_PASSWORD}
143+
docker-compose exec php wp core install --url=${SITE_DOMAIN} --title=${HH_INSTALL_ADMIN_TITLE} --admin_user=${INSTALL_ADMIN_LOGIN} --admin_email=${INSTALL_ADMIN_EMAIL} --admin_password=${INSTALL_ADMIN_PASSWORD}
144+
103145

146+
##########################
147+
# Commands helpers
148+
##########################
104149
# It is used for fixing access right errors for files on OS-side, has created on docker-side.
105150
fix-access-right-for:
106151
sudo chown -R $(USER):$(shell id -g -n) $(filter-out $@,$(MAKECMDGOALS))

Readme.md renamed to README.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# Docker Environment Boilerplate for WordPress
22

33
### Docker configuration:
4-
- Nginx 1.19
4+
- Nginx 1.20
55
- PHP 7.4
66
- Composer > 2.1
77
- MySQL 5.6
88
- PhpMyAdmin 5
9-
- Node 15
9+
- Node 16.14.2
1010
- WP-CLI > 2.5.0
1111

1212
## Instructions
1313
1. You need to add the string to `hosts` file your OS:
1414
`127.0.0.1 wp-docker-boilerplate.local`
15-
```bash
16-
# create env file
17-
docker/sh/create.env.sh
18-
# !!! You must fill variables in .env file.
15+
```bash
16+
# copy & paste and fill variables
17+
cp .env.dist .env
1918

2019
# run docker project.
2120
make d.up
@@ -44,17 +43,16 @@ or
4443
If you want change domain, you need to change `server_name` in `./docker/nginxconf.d/default.conf`.
4544

4645

47-
## If you have troubles with VPN
48-
1. If you use VPN, you need to disable VPN and run command:
49-
`docker network create localdev`
50-
2. After It you can run your VPN.
51-
3. Add the code at end of the file:
52-
```networks:
53-
default:
54-
external:
55-
name: localdev
56-
3. Make to
57-
`docker-compose up -d`
58-
46+
### Q/A
47+
If you get next error on MacOS
48+
```failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest sha256:20575ecebe6216036d25dab5903808211f1e9ba63dc7825ac20cb975e34cfcae: not found```
49+
50+
create `docker-compose.override.yml` in the project and add following lines:
51+
```
52+
services:
53+
mysql:
54+
platform: linux/amd64
55+
image: mysql:5.6 #or any other version
56+
```
5957

6058

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
{
22
"name": "renakdup/wp-docker-boilerplate",
3-
"description": "Docker Environment Example",
3+
"description": "Docker Boilerplate Environment for WordPress",
44
"authors": [
55
{
6-
"name": "Andrew Pisarevsky",
6+
"name": "Andrei Pisarevskii",
77
"email": "[email protected]"
88
}
99
],
1010
"require": {
1111
"vlucas/phpdotenv": "^5.3"
12-
},
13-
"scripts": {
14-
"wp-install": "wp core download"
1512
}
1613
}

docker-compose.yaml

100644100755
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ services:
1515
- ./docker/nginx/templates:/etc/nginx/templates
1616
depends_on:
1717
- php
18+
networks:
19+
- rd-network
1820

1921
php:
2022
restart: always
@@ -23,8 +25,11 @@ services:
2325
args:
2426
UID: $UID
2527
GUID: $GUID
28+
PHP_VER: $PHP_VER
2629
volumes:
2730
- ./:/app
31+
networks:
32+
- rd-network
2833

2934
mysql:
3035
restart: always
@@ -44,6 +49,8 @@ services:
4449
- ./docker/mysql/backup/:/backup
4550
ports:
4651
- $MYSQL_PORT:3307
52+
networks:
53+
- rd-network
4754

4855
phpmyadmin:
4956
restart: always
@@ -56,16 +63,13 @@ services:
5663
PMA_PASSWORD: $MYSQL_PASSWORD
5764
depends_on:
5865
- mysql
59-
60-
# You need to define the "npm start" command in the package.json file in the "./ directory", or comment out
61-
# the string "npm start" in the Dockerfile.
62-
# node:
63-
# build: ./docker/node
64-
# ports:
65-
# - "3000:3000"
66-
# volumes_from:
67-
# - php
68-
66+
networks:
67+
- rd-network
6968

7069
volumes:
7170
mysql-data:
71+
72+
73+
networks:
74+
rd-network:
75+
driver: bridge

docker/mysql/Dockerfile

100644100755
File mode changed.

docker/mysql/backup/.gitkeep

100644100755
File mode changed.

0 commit comments

Comments
 (0)