Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup cache environment.
id: cache-env
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: docker

permissions:
contents: read

on:
pull_request: &ignore-paths
paths-ignore:
- ".bowerrc"
- ".editorconfig"
- ".git-blame-ignore-revs"
- ".gitattributes"
- ".github/CONTRIBUTING.md"
- ".github/FUNDING.yml"
- ".github/ISSUE_TEMPLATE.md"
- ".github/PULL_REQUEST_TEMPLATE.md"
- ".github/SECURITY.md"
- ".gitignore"
- "LICENSE.md"
- "README.md"
- "requirements.php"
- "Vagrantfile"

push: *ignore-paths

jobs:
apache:
runs-on: ubuntu-latest

steps:
- name: Checkout.
uses: actions/checkout@v6
Comment thread
terabytesoftw marked this conversation as resolved.

- name: Build and start containers.
run: docker compose up -d --build --wait

- name: Composer install.
run: docker compose exec -T frontend composer install --prefer-dist --no-interaction
Comment thread
terabytesoftw marked this conversation as resolved.
Outdated

- name: Initialize application.
run: docker compose exec -T frontend php /app/init --env=Development --overwrite=All

Comment thread
terabytesoftw marked this conversation as resolved.
- name: Configure database for Docker.
run: |
docker compose exec -T frontend bash -c '
for f in /app/common/config/main-local.php /app/common/config/test-local.php; do
if [ -f "$f" ]; then
sed -i \
-e "s|host=localhost|host=mysql|g" \
-e "s|'\''username'\'' => '\''root'\''|'\''username'\'' => '\''yii2advanced'\''|g" \
-e "s|'\''password'\'' => '\'''\''|'\''password'\'' => '\''secret'\''|g" \
Comment thread
terabytesoftw marked this conversation as resolved.
"$f"
Comment thread
terabytesoftw marked this conversation as resolved.
fi
done
'

- name: Wait for MySQL to be ready.
run: |
ready=0
for i in $(seq 1 60); do
docker compose exec -T frontend php -r "new PDO('mysql:host=mysql;dbname=yii2advanced', 'yii2advanced', 'secret');" 2>/dev/null && { ready=1; break; }
sleep 3
done
Comment thread
terabytesoftw marked this conversation as resolved.
if [ "$ready" -ne 1 ]; then
echo "MySQL did not become ready after 60 attempts."
exit 1
fi

- name: Create test database.
run: |
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;
"

- name: Run database migrations.
run: docker compose exec -T frontend php /app/yii migrate --interactive=0

- name: Run test database migrations.
run: docker compose exec -T frontend php /app/yii_test migrate --interactive=0

- name: Codeception build.
run: docker compose exec -T frontend vendor/bin/codecept build

- name: Codeception run.
run: docker compose exec -T frontend vendor/bin/codecept run
Comment thread
terabytesoftw marked this conversation as resolved.
165 changes: 165 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
[![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)
[![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)

## Docker

[![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)

REQUIREMENTS
------------

> [!IMPORTANT]
> - The minimum required [PHP](https://www.php.net/) version of Yii is PHP `8.2`.

## Install via Composer

If you do not have [Composer](https://getcomposer.org/), you may install it by following the instructions
at [getcomposer.org](https://getcomposer.org/doc/00-intro.md#installation-nix).

You can then install this project template using the following commands:

```bash
composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
cd advanced
```

### Frontend

<picture>
Expand Down Expand Up @@ -78,6 +100,149 @@ vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
```

Initialize the application for the `Development` environment:

```bash
php init --env=Development --overwrite=All
```

Now you should be able to access the application through the following URLs, assuming `advanced` is the directory
directly under the Web root.

```
http://localhost/advanced/frontend/web/
http://localhost/advanced/backend/web/
```

## Install with Docker

Build and start the containers:

```bash
docker compose up -d --build
```

Install dependencies inside the container:

```bash
docker compose exec frontend composer install --prefer-dist --no-interaction
Comment thread
terabytesoftw marked this conversation as resolved.
Outdated
```

Initialize the application for the `Development` environment:

```bash
docker compose exec frontend php /app/init --env=Development --overwrite=All
```

After running `init`, update the database connection in `common/config/main-local.php` to use the `mysql`
service hostname:

```php
'db' => [
'class' => \yii\db\Connection::class,
'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
'username' => 'yii2advanced',
'password' => 'secret',
'charset' => 'utf8',
],
```

You can then access the application through the following URLs:

```
http://127.0.0.1:20080 (frontend)
http://127.0.0.1:21080 (backend)
```

To run the test suite, also update `common/config/test-local.php` to use the `mysql` hostname and create the
test database:

```php
'db' => [
'dsn' => 'mysql:host=mysql;dbname=yii2advanced_test',
],
```

```bash
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;"
docker compose exec -T frontend php /app/yii_test migrate --interactive=0
docker compose exec -T frontend vendor/bin/codecept build
docker compose exec -T frontend vendor/bin/codecept run
```
Comment thread
terabytesoftw marked this conversation as resolved.

**NOTES:**
- Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
- The default configuration uses a host-volume in your home directory `~/.composer-docker/cache` for Composer caches

CONFIGURATION
-------------

## Database

Edit the file `common/config/main-local.php` with real data, for example:

```php
return [
'components' => [
'db' => [
'class' => \yii\db\Connection::class,
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
],
],
];
```

When using Docker, the MySQL service is pre-configured. Update `common/config/main-local.php` to use:

```php
'db' => [
'class' => \yii\db\Connection::class,
'dsn' => 'mysql:host=mysql;dbname=yii2advanced',
'username' => 'yii2advanced',
'password' => 'secret',
'charset' => 'utf8',
],
```

Apply migrations:

```bash
php yii migrate
```

Or with Docker:

```bash
docker compose exec frontend php /app/yii migrate
```

**NOTES:**
- Yii won't create the database for you, this has to be done manually before you can access it.
When using Docker, the MySQL service creates the database automatically.
- Check and edit the other files in the `config/` directories to customize your application as required.
- Refer to the README in the `tests` directory for information specific to application tests.

TESTING
-------

Tests are located in `frontend/tests`, `backend/tests`, and `common/tests` directories.
They are developed with [Codeception PHP Testing Framework](https://codeception.com/).

Tests can be executed by running:

```bash
vendor/bin/codecept run --env php-builtin
```

Or using the Composer script:

```bash
composer tests
```

## Support the project

[![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)
Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM yiisoftware/yii2-php:8.1-apache
FROM yiisoftware/yii2-php:8.4-apache

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