Skip to content

Latest commit

 

History

History
231 lines (175 loc) · 5.07 KB

README.md

File metadata and controls

231 lines (175 loc) · 5.07 KB

Docker

This project relies on the following 3 application images:

Requirements

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

Pull the base images from GitHub container registry

Get the image tags for each image from the packages page.

NGINX

docker pull ghcr.io/package-health/nginx:prod-6a56f91

PHP-FPM

docker pull ghcr.io/package-health/php-fpm:prod-6a56f91

PHP-CLI

docker pull ghcr.io/package-health/php-cli:prod-6a56f91

Download the base images (deprecated, old releases only)

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

NGINX

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

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

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

docker build --file docker/nginx.Dockerfile --tag package-health/nginx:latest .

PHP-FPM

docker build --file docker/php.Dockerfile --target fpm --tag package-health/php-fpm:latest .

PHP-CLI

docker build --file docker/php.Dockerfile --target cli --tag package-health/php-cli:latest .

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
AMQP_USER=<rabbitmq username>
AMQP_PASS=<rabbitmq password>
AMQP_HOST=pph-rabbit
PHP_ENV=dev
DOCKER=true

Creating a network

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

docker network create pph-network

Starting the containers

Start the database container:

docker run \
  --detach \
  --env-file "$(pwd -P)/.env" \
  --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:

  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:

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

Start the NGINX container:

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

Database Migration

Start the PHP-CLI container:

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

Check migration status:

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

Run migrations:

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

Accessing the application

Open your browser and head to http://localhost:8080/.

Maintenance

The following sections are dedicated to maintenance tasks only.

Application Console

Start the PHP-CLI container:

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

List console commands:

php console.php

PostgreSQL Command Line Interface (PSQL)

Execute sh in the running pph-postgres container:

docker exec \
  --interactive \
  --tty \
  pph-postgres \
  sh

Run psql:

psql \
  --username "${POSTGRES_USER}" \
  --dbname "${POSTGRES_DB}"