Skip to content

Commit

Permalink
Improve docker docs and nginx image
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Mar 7, 2022
1 parent 1052511 commit e51e13c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Project Idea:

## Docker

Documentation about running the project using Docker is available in [DOCKER.md](DOCKER.md).
Documentation about running the project using Docker is available in [docker/README.md](docker/README.md).

## License

Expand Down
67 changes: 62 additions & 5 deletions DOCKER.md → docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,81 @@ This project relies on the following 3 application images:
* [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.

## Building the base images
## Requirements

Before running, the application images must be available in the docker daemon.

### Download the base images

Get the latest release links from [https://github.com/package-health/php/releases](https://github.com/package-health/php/releases).

**NGINX**
```bash
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
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
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 && \
docker load < php-cli-prod-f0d3f68.tar.gz
```

### Build the base images

From the root directory of this repository:

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

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

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

## Creating a network
## Running

### Configuration

Copy `.env-dist` to `.env` and setup accordingly:

```
POSTGRES_USER=<database username>
POSTGRES_PASSWORD=<database password>
POSTGRES_DB=<database name>
POSTGRES_HOST=pph-postgres
PHP_ENV=development
DOCKER=true
```

### Creating a network

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
```

## Starting the containers
### Starting the containers

Start the database container:

Expand Down Expand Up @@ -56,13 +112,14 @@ Start the NGINX container:
docker run \
--rm \
--detach \
--env PHP_FPM=pph-php-fpm \
--network php-package-health-network \
--publish 8080:80/tcp \
--name pph-nginx \
php.package.health/nginx:latest
```

## Database Migration
### Database Migration

Start the PHP-CLI container:

Expand Down Expand Up @@ -90,7 +147,7 @@ Run migrations:
../vendor/bin/phinx migrate --configuration ../phinx.php --environment "${PHP_ENV}"
```

## Accessing the application
### Accessing the application

Open your browser and head to [http://localhost:8080/](http://localhost:8080/).

Expand Down
1 change: 1 addition & 0 deletions docker/nginx.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ENV TZ=:/etc/localtime
# nginx settings
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY docker/nginx/upstream.conf.template /etc/nginx/templates/upstream.conf.template

# static assets
COPY public/css/ /usr/share/nginx/html/css/
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ server {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass pph-php-fpm:9000;
fastcgi_pass php-fpm-upstream;
}

location /status {
Expand Down
3 changes: 3 additions & 0 deletions docker/nginx/upstream.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
upstream php-fpm-upstream {
server ${PHP_FPM:-php-fpm}:9000;
}

0 comments on commit e51e13c

Please sign in to comment.