Skip to content

Commit

Permalink
Update Docker documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Mar 18, 2022
1 parent 176958a commit 1f01034
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
POSTGRES_HOST=
AMQP_USER=
AMQP_PASS=
AMQP_HOST=
PHP_ENV=
DOCKER=
82 changes: 48 additions & 34 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This project relies on the following 3 application images:

* [php.package.health/nginx](docker/nginx.Dockerfile): Serves static assets (css, fonts etc.) and routes dynamic traffic to php-fpm;
* [php.package.health/php-fpm](docker/php.Dockerfile): Serves dynamic traffic based in the application code;
* [php.package.health/php-cli](docker/php.Dockerfile): Used to perform maintenance tasks, such as database migration.
* [package-health/nginx](docker/nginx.Dockerfile): Serves static assets (css, fonts etc.) and routes dynamic traffic to php-fpm;
* [package-health/php-fpm](docker/php.Dockerfile): Serves dynamic traffic based in the application code;
* [package-health/php-cli](docker/php.Dockerfile): Used to perform maintenance tasks, such as database migration.

## Requirements

Expand All @@ -15,23 +15,23 @@ Before running, the application images must be available in the docker daemon.
Get the latest release links from [https://github.com/package-health/php/releases](https://github.com/package-health/php/releases).

**NGINX**
```bash
```shell
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/nginx-prod-f0d3f68.tar.gz && \
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/nginx-prod-f0d3f68.tar.gz.sha1 && \
shasum -c nginx-prod-f0d3f68.tar.gz.sha1 && \
docker load < nginx-prod-f0d3f68.tar.gz
```

**PHP-FPM**
```bash
```shell
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/php-fpm-prod-f0d3f68.tar.gz && \
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/php-fpm-prod-f0d3f68.tar.gz.sha1 && \
shasum -c php-fpm-prod-f0d3f68.tar.gz.sha1 && \
docker load < php-fpm-prod-f0d3f68.tar.gz
```

**PHP-CLI**
```bash
```shell
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/php-cli-prod-f0d3f68.tar.gz && \
wget https://github.com/package-health/php/releases/download/prod%40f0d3f68/php-cli-prod-f0d3f68.tar.gz.sha1 && \
shasum -c php-cli-prod-f0d3f68.tar.gz.sha1 && \
Expand All @@ -43,18 +43,18 @@ docker load < php-cli-prod-f0d3f68.tar.gz
From the root directory of this repository:

**NGINX**
```bash
docker build --file docker/nginx.Dockerfile --tag php.package.health/nginx:latest .
```shell
docker build --file docker/nginx.Dockerfile --tag package-health/nginx:latest .
```

**PHP-FPM**
```bash
docker build --file docker/php.Dockerfile --target fpm --tag php.package.health/php-fpm:latest .
```shell
docker build --file docker/php.Dockerfile --target fpm --tag package-health/php-fpm:latest .
```

**PHP-CLI**
```bash
docker build --file docker/php.Dockerfile --target cli --tag php.package.health/php-cli:latest .
```shell
docker build --file docker/php.Dockerfile --target cli --tag package-health/php-cli:latest .
```

## Running
Expand All @@ -68,6 +68,9 @@ POSTGRES_USER=<database username>
POSTGRES_PASSWORD=<database password>
POSTGRES_DB=<database name>
POSTGRES_HOST=pph-postgres
AMQP_USER=<rabbitmq username>
AMQP_PASS=<rabbitmq password>
AMQP_HOST=pph-rabbit
PHP_ENV=development
DOCKER=true
```
Expand All @@ -76,74 +79,85 @@ DOCKER=true

The network will be shared by the containers, so they can communicate without exposing ports to the host machine.

```bash
docker network create php-package-health-network
```shell
docker network create pph-network
```

### Starting the containers

Start the database container:

```bash
```shell
docker run \
--detach \
--env-file "$(pwd -P)/.env" \
--volume "$(pwd -P)/var/db":/var/lib/postgresql/data \
--network php-package-health-network \
--volume "$(pwd -P)/run/db":/var/lib/postgresql/data \
--network pph-network \
--name pph-postgres \
postgres:14.2-alpine3.15
```

Start the message broker container:

```shell
docker run \
--detach \
--volume "$(pwd -P)/run/rmq":/var/lib/rabbitmq \
--network pph-network \
--name pph-rabbit \
rabbitmq:3.9-management-alpine
```

Start the PHP-FPM container:

```bash
```shell
docker run \
--rm \
--detach \
--env-file "$(pwd -P)/.env" \
--network php-package-health-network \
--network pph-network \
--name pph-php-fpm \
php.package.health/php-fpm:latest
package-health/php-fpm:latest
```

Start the NGINX container:

```bash
```shell
docker run \
--rm \
--detach \
--env PHP_FPM=pph-php-fpm \
--network php-package-health-network \
--network pph-network \
--publish 8080:80/tcp \
--name pph-nginx \
php.package.health/nginx:latest
package-health/nginx:latest
```

### Database Migration

Start the PHP-CLI container:

```bash
```shell
docker run \
--rm \
--interactive \
--tty \
--env-file "$(pwd -P)/.env" \
--network php-package-health-network \
--network pph-network \
--name pph-php-cli \
php.package.health/php-cli:latest \
package-health/php-cli:latest \
sh
```

Check migration status:

```bash
```shell
../vendor/bin/phinx status --configuration ../phinx.php --environment "${PHP_ENV}"
```

Run migrations:

```bash
```shell
../vendor/bin/phinx migrate --configuration ../phinx.php --environment "${PHP_ENV}"
```

Expand All @@ -159,29 +173,29 @@ The following sections are dedicated to maintenance tasks only.

Start the PHP-CLI container:

```bash
```shell
docker run \
--rm \
--interactive \
--tty \
--env-file "$(pwd -P)/.env" \
--network php-package-health-network \
--network pph-network \
--name pph-php-cli \
php.package.health/php-cli:latest \
package-health/php-cli:latest \
sh
```

List console commands:

```bash
```shell
php console.php
```

### PostgreSQL Command Line Interface (PSQL)

Execute `sh` in the running `pph-postgres` container:

```bash
```shell
docker exec \
--interactive \
--tty \
Expand All @@ -191,7 +205,7 @@ docker exec \

Run `psql`:

```bash
```shell
psql \
--username "${POSTGRES_USER}" \
--dbname "${POSTGRES_DB}"
Expand Down

0 comments on commit 1f01034

Please sign in to comment.