Skip to content

Commit e193746

Browse files
Upgrade Docker to PHP 8.4 and MySQL 8.0, remove composer.lock. (#581)
1 parent 902200d commit e193746

8 files changed

Lines changed: 264 additions & 6325 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
steps:
4343
- name: Checkout.
44-
uses: actions/checkout@v5
44+
uses: actions/checkout@v6
4545

4646
- name: Setup cache environment.
4747
id: cache-env

.github/workflows/docker.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: docker
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request: &ignore-paths
8+
paths-ignore:
9+
- ".bowerrc"
10+
- ".editorconfig"
11+
- ".git-blame-ignore-revs"
12+
- ".gitattributes"
13+
- ".github/CONTRIBUTING.md"
14+
- ".github/FUNDING.yml"
15+
- ".github/ISSUE_TEMPLATE.md"
16+
- ".github/PULL_REQUEST_TEMPLATE.md"
17+
- ".github/SECURITY.md"
18+
- ".gitignore"
19+
- "LICENSE.md"
20+
- "README.md"
21+
- "requirements.php"
22+
- "Vagrantfile"
23+
24+
push: *ignore-paths
25+
26+
jobs:
27+
apache:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout.
32+
uses: actions/checkout@v6
33+
34+
- name: Build and start containers.
35+
run: docker compose up -d --build --wait
36+
37+
- name: Composer update.
38+
run: docker compose exec -T frontend composer update --prefer-dist --no-interaction
39+
40+
- name: Initialize application.
41+
run: docker compose exec -T frontend php /app/init --env=Development --overwrite=All
42+
43+
- name: Configure database for Docker.
44+
run: |
45+
docker compose exec -T frontend bash -c '
46+
for f in /app/common/config/main-local.php /app/common/config/test-local.php; do
47+
if [ -f "$f" ]; then
48+
sed -i \
49+
-e "s|host=localhost|host=mysql|g" \
50+
-e "s|'\''username'\'' => '\''root'\''|'\''username'\'' => '\''yii2advanced'\''|g" \
51+
-e "s|'\''password'\'' => '\'''\''|'\''password'\'' => '\''secret'\''|g" \
52+
"$f"
53+
fi
54+
done
55+
'
56+
57+
- name: Wait for MySQL to be ready.
58+
run: |
59+
ready=0
60+
for i in $(seq 1 60); do
61+
docker compose exec -T frontend php -r "new PDO('mysql:host=mysql;dbname=yii2advanced', 'yii2advanced', 'secret');" 2>/dev/null && { ready=1; break; }
62+
sleep 3
63+
done
64+
if [ "$ready" -ne 1 ]; then
65+
echo "MySQL did not become ready after 60 attempts."
66+
exit 1
67+
fi
68+
69+
- name: Create test database.
70+
run: |
71+
docker compose exec -T mysql mysql -uroot -pverysecret -e "
72+
CREATE DATABASE IF NOT EXISTS yii2advanced_test;
73+
GRANT ALL PRIVILEGES ON yii2advanced_test.* TO 'yii2advanced'@'%';
74+
FLUSH PRIVILEGES;
75+
"
76+
77+
- name: Run database migrations.
78+
run: docker compose exec -T frontend php /app/yii migrate --interactive=0
79+
80+
- name: Run test database migrations.
81+
run: docker compose exec -T frontend php /app/yii_test migrate --interactive=0
82+
83+
- name: Codeception build.
84+
run: docker compose exec -T frontend vendor/bin/codecept build
85+
86+
- name: Codeception run.
87+
run: docker compose exec -T frontend vendor/bin/codecept run

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ Thumbs.db
2525

2626
# composer itself is not needed
2727
composer.phar
28+
composer.lock
2829

2930
# Mac DS_Store Files
3031
.DS_Store
3132

33+
# node
34+
/node_modules
35+
/package.json
36+
/package-lock.json
37+
3238
# phpunit itself is not needed
3339
phpunit.phar
3440
# local phpunit config

README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
2424
[![build](https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/build.yml?style=for-the-badge&logo=github&label=Build)](https://github.com/yiisoft/yii2-app-advanced/actions?query=workflow%3Abuild)
2525
[![Static Analysis](https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/static.yml?style=for-the-badge&label=Static)](https://github.com/yiisoft/yii2-app-advanced/actions/workflows/static.yml)
2626

27+
## Docker
28+
29+
[![Apache](https://img.shields.io/github/actions/workflow/status/yiisoft/yii2-app-advanced/docker.yml?style=for-the-badge&logo=apache&label=Apache)](https://github.com/yiisoft/yii2-app-advanced/actions/workflows/docker.yml)
30+
31+
REQUIREMENTS
32+
------------
33+
34+
> [!IMPORTANT]
35+
> - The minimum required [PHP](https://www.php.net/) version of Yii is PHP `8.2`.
36+
37+
## Install via Composer
38+
39+
If you do not have [Composer](https://getcomposer.org/), you may install it by following the instructions
40+
at [getcomposer.org](https://getcomposer.org/doc/00-intro.md#installation-nix).
41+
42+
You can then install this project template using the following commands:
43+
44+
```bash
45+
composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
46+
cd advanced
47+
```
48+
2749
### Frontend
2850

2951
<picture>
@@ -78,6 +100,149 @@ vendor/ contains dependent 3rd-party packages
78100
environments/ contains environment-based overrides
79101
```
80102

103+
Initialize the application for the `Development` environment:
104+
105+
```bash
106+
php init --env=Development --overwrite=All
107+
```
108+
109+
Now you should be able to access the application through the following URLs, assuming `advanced` is the directory
110+
directly under the Web root.
111+
112+
```
113+
http://localhost/advanced/frontend/web/
114+
http://localhost/advanced/backend/web/
115+
```
116+
117+
## Install with Docker
118+
119+
Build and start the containers:
120+
121+
```bash
122+
docker compose up -d --build
123+
```
124+
125+
Install dependencies inside the container:
126+
127+
```bash
128+
docker compose exec frontend composer update --prefer-dist --no-interaction
129+
```
130+
131+
Initialize the application for the `Development` environment:
132+
133+
```bash
134+
docker compose exec frontend php /app/init --env=Development --overwrite=All
135+
```
136+
137+
After running `init`, update the database connection in `common/config/main-local.php` to use the `mysql`
138+
service hostname:
139+
140+
```php
141+
'db' => [
142+
'class' => \yii\db\Connection::class,
143+
'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
144+
'username' => 'yii2advanced',
145+
'password' => 'secret',
146+
'charset' => 'utf8',
147+
],
148+
```
149+
150+
You can then access the application through the following URLs:
151+
152+
```
153+
http://127.0.0.1:20080 (frontend)
154+
http://127.0.0.1:21080 (backend)
155+
```
156+
157+
To run the test suite, also update `common/config/test-local.php` to use the `mysql` hostname and create the
158+
test database:
159+
160+
```php
161+
'db' => [
162+
'dsn' => 'mysql:host=mysql;dbname=yii2advanced_test',
163+
],
164+
```
165+
166+
```bash
167+
docker compose exec -T mysql mysql -uroot -pverysecret -e "CREATE DATABASE IF NOT EXISTS yii2advanced_test; GRANT ALL PRIVILEGES ON yii2advanced_test.* TO 'yii2advanced'@'%'; FLUSH PRIVILEGES;"
168+
docker compose exec -T frontend php /app/yii_test migrate --interactive=0
169+
docker compose exec -T frontend vendor/bin/codecept build
170+
docker compose exec -T frontend vendor/bin/codecept run
171+
```
172+
173+
**NOTES:**
174+
- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
175+
- The default configuration uses a host-volume in your home directory `~/.composer-docker/cache` for Composer caches
176+
177+
CONFIGURATION
178+
-------------
179+
180+
## Database
181+
182+
Edit the file `common/config/main-local.php` with real data, for example:
183+
184+
```php
185+
return [
186+
'components' => [
187+
'db' => [
188+
'class' => \yii\db\Connection::class,
189+
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
190+
'username' => 'root',
191+
'password' => '1234',
192+
'charset' => 'utf8',
193+
],
194+
],
195+
];
196+
```
197+
198+
When using Docker, the MySQL service is pre-configured. Update `common/config/main-local.php` to use:
199+
200+
```php
201+
'db' => [
202+
'class' => \yii\db\Connection::class,
203+
'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
204+
'username' => 'yii2advanced',
205+
'password' => 'secret',
206+
'charset' => 'utf8',
207+
],
208+
```
209+
210+
Apply migrations:
211+
212+
```bash
213+
php yii migrate
214+
```
215+
216+
Or with Docker:
217+
218+
```bash
219+
docker compose exec frontend php /app/yii migrate
220+
```
221+
222+
**NOTES:**
223+
- Yii won't create the database for you, this has to be done manually before you can access it.
224+
When using Docker, the MySQL service creates the database automatically.
225+
- Check and edit the other files in the `config/` directories to customize your application as required.
226+
- Refer to the README in the `tests` directory for information specific to application tests.
227+
228+
TESTING
229+
-------
230+
231+
Tests are located in `frontend/tests`, `backend/tests`, and `common/tests` directories.
232+
They are developed with [Codeception PHP Testing Framework](https://codeception.com/).
233+
234+
Tests can be executed by running:
235+
236+
```bash
237+
vendor/bin/codecept run --env php-builtin
238+
```
239+
240+
Or using the Composer script:
241+
242+
```bash
243+
composer tests
244+
```
245+
81246
## Support the project
82247

83248
[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?style=for-the-badge&logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM yiisoftware/yii2-php:8.1-apache
1+
FROM yiisoftware/yii2-php:8.4-apache
22

33
# Change document root for Apache
44
RUN sed -i -e 's|/app/web|/app/backend/web|g' /etc/apache2/sites-available/000-default.conf

0 commit comments

Comments
 (0)