Skip to content

Commit bde28dd

Browse files
author
ironex
committed
Allow new project to be created by one command, add Xdebug switcher, fix some permission issues
1 parent 8fda7d6 commit bde28dd

File tree

16 files changed

+188
-82
lines changed

16 files changed

+188
-82
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
magento
2-
auth.json
2+
docker/php-fpm/auth.json
33
.idea
44
.DS_Store

README.md

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Docker Magento
1+
# Docker Magento 2
22

33
```Rootless containers```,
44
```Docker```,
5-
```Magento```,
5+
```Magento 2```,
66
```Nginx```,
77
```MySQL```,
88
```PHP-FPM```,
@@ -13,36 +13,68 @@
1313
```Elastic Search```,
1414
```Kibana```
1515

16+
## Currently supported versions of Magento
17+
18+
- 2.4.x
19+
1620
## Setup
1721

18-
__1) Add following to etc/hosts__
22+
__Add following to etc/hosts__
1923
- 127.0.0.1 magento.local
2024
- 127.0.0.1 kibana.magento.local
2125
- 127.0.0.1 redis.magento.local
2226
- 127.0.0.1 rabbitmq.magento.local
2327
- 127.0.0.1 adminer.magento.local
2428

25-
__2) Start Docker__
26-
27-
- ```sh bin/start.sh```
28-
- Accepts additional arguments (--build <container>)
29-
30-
__3) Create new or add existing Magento project__
31-
32-
- Create new project
33-
- ```sh bin/new-project.sh```
34-
- Keys can be found in https://marketplace.magento.com/customer/accessKeys/
35-
36-
- Add existing project
29+
__A) Create brand new Magento project__
30+
31+
1) Run ```sh bin/new-project.sh <version>```
32+
- Requires Magento version as an argument
33+
- Make sure "magento" folder exists and is owned by current user before you bind it to the container by running the script above, otherwise it will be created by Docker and owned by root.
34+
- Keys can be found in https://marketplace.magento.com/customer/accessKeys/ and you can opt-in to store your keys (login and password) to /home/docker/.composer/auth.json, which is bind mounted to docker/php-fpm/auth.json
35+
- Magento default settings - these can be edited in bin/new-project.sh
36+
- base-url=http://magento.local
37+
- db-host=mysql
38+
- db-name=magento
39+
- db-user=magento
40+
- db-password=magento
41+
- admin-firstname=admin
42+
- admin-lastname=admin
43+
44+
- admin-user=admin
45+
- admin-password=admin123
46+
- language=en_US
47+
- currency=USD
48+
- timezone=America/Chicago
49+
- use-rewrites=1
50+
- elasticsearch-host=elasticsearch
51+
- session-save=redis
52+
- session-save-redis-host=redis
53+
- session-save-redis-db=0 --session-save-redis-password=""
54+
- cache-backend=redis
55+
- cache-backend-redis-server=redis
56+
- cache-backend-redis-db=1
57+
- page-cache=redis
58+
- page-cache-redis-server=redis
59+
- page-cache-redis-db=2
60+
- amqp-host="rabbitmq"
61+
- amqp-port="5672"
62+
- amqp-user="guest"
63+
- amqp-password="guest"
64+
- amqp-virtualhost="/"
65+
66+
__B) Run already existing Magento project__
67+
68+
1) Run ```sh bin/start.sh```
69+
70+
2) Add existing project
3771
- Paste your existing Magento project to magento folder
3872

39-
__4) Install Magento__
40-
41-
- ```sh bin/install.sh```
42-
43-
__5) Setup Xdebug in IDE__
73+
__Setup Xdebug in IDE__
4474

45-
- PhpStorm should offer you automatic setup after you add breakpoint and make http request (open magento.local in a browser) and correct settings should be similar to this:
75+
1) Run ```sh bin/xdebug.sh debug```
76+
- You can turn off Xdebug by running ```sh bin/xdebug.sh off``` and turn it on again with ```sh bin/xdebug.sh debug```, you can also use this command to set all other Xdebug modes (https://xdebug.org/docs/all_settings#mode)
77+
2) PhpStorm should offer you automatic setup after you add breakpoint and make http request (open magento.local in a browser) and correct settings should be similar to this:
4678

4779
Preferences - PHP - Debug
4880

auth.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

bin/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
export USER_ID=$(id -u)
4+
export GROUP_ID=$(id -u)
5+
6+
# Build images
7+
docker-compose build $@

bin/cleanup.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#!/bin/sh
22

3-
docker-compose down
3+
export USER_ID=$(id -u)
4+
export GROUP_ID=$(id -u)
45

5-
docker container rm $(docker container ls -aq)
6+
# Stop running containers, remove images and volumes
7+
sh bin/stop.sh -v --rmi all
68

7-
docker image rm $(docker image ls -aq) --force
8-
9-
echo "###### docker container ls -a"
10-
11-
docker container ls -a
12-
13-
echo "###### docker image ls"
14-
15-
docker image ls
9+
# Remove stopped containers
10+
docker-compose rm

bin/composer.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
export USER_ID=$(id -u)
44
export GROUP_ID=$(id -u)
55

6-
docker-compose run --rm --workdir /magento php-fpm composer $@
6+
# Run Composer command
7+
docker-compose run --rm --workdir /home/dockeruser/magento php-fpm composer $@

bin/install.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

bin/new-project.sh

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
11
#!/bin/sh
22

3+
export USER_ID=$(id -u)
4+
export GROUP_ID=$(id -u)
5+
6+
if [ -z $1 ]
7+
then echo "Please select Magento 2 version. Currently supported versions: 2.4.x";
8+
exit;
9+
fi
10+
11+
# Ask user before removing magento folder and then re-creating it
12+
while true; do
13+
read -p "Running this command will remove magento folder including its contents and then re-create it. Do you wish to proceed Y/n?" yn
14+
case $yn in
15+
[Yy]* ) rm -rf magento; mkdir magento; break;;
16+
[Nn]* ) exit;;
17+
* ) echo "Please answer Y/n.";;
18+
esac
19+
done
20+
21+
# Create magento folder if it does not exist
22+
magento="magento"
23+
24+
if [ ! -d $magento ]
25+
then
26+
mkidr $magento
27+
fi
28+
29+
# Build images and create and start containers
30+
sh bin/build.sh --no-cache
31+
sh bin/start.sh
32+
33+
# Create new project
334
rm magento/.placeholder
35+
sh bin/composer.sh create-project --ignore-platform-reqs --repository-url=https://repo.magento.com/ magento/project-community-edition=$1 .
436

5-
sh bin/composer.sh create-project --ignore-platform-reqs --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.2-p1 .
37+
# Install Magento
38+
docker-compose exec -T php-fpm /home/dockeruser/magento/bin/magento setup:install \
39+
--base-url=http://magento.local \
40+
--db-host=mysql \
41+
--db-name=magento \
42+
--db-user=magento \
43+
--db-password=magento \
44+
--admin-firstname=admin \
45+
--admin-lastname=admin \
46+
47+
--admin-user=admin \
48+
--admin-password=admin123 \
49+
--language=en_US \
50+
--currency=USD \
51+
--timezone=America/Chicago \
52+
--use-rewrites=1 \
53+
--elasticsearch-host=elasticsearch \
54+
--session-save=redis \
55+
--session-save-redis-host=redis \
56+
--session-save-redis-db=0 --session-save-redis-password="" \
57+
--cache-backend=redis \
58+
--cache-backend-redis-server=redis \
59+
--cache-backend-redis-db=1 \
60+
--page-cache=redis \
61+
--page-cache-redis-server=redis \
62+
--page-cache-redis-db=2 \
63+
--amqp-host="rabbitmq" \
64+
--amqp-port="5672" \
65+
--amqp-user="guest" \
66+
--amqp-password="guest" \
67+
--amqp-virtualhost="/"

bin/start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
export USER_ID=$(id -u)
44
export GROUP_ID=$(id -u)
55

6+
# Build images if needed and create and start containers
67
docker-compose up -d $@

bin/stop.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/bin/sh
22

3-
docker-compose down
3+
export USER_ID=$(id -u)
4+
export GROUP_ID=$(id -u)
5+
6+
# Stop running containers
7+
docker-compose down $@

0 commit comments

Comments
 (0)