Skip to content

Commit

Permalink
build: use Docker for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
opdavies committed Oct 24, 2021
1 parent 3b052a8 commit b50f428
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .docker.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
COMPOSE_PROJECT_NAME=phpsouthwales-uk

COMPOSER_MEMORY_LIMIT=-1

DRUPAL_DOCROOT=web
DRUPAL_SALT=abc123

MYSQL_ROOT_PASSWORD=root
Expand Down
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.dependabot/
/.github/
/.git/
/.platform/
/Makefile
/README.md
/**/node_modules/
34 changes: 6 additions & 28 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
#
# Copy and rename this file to .env at root of this project.
#
MYSQL_DATABASE=phpsouthwales
MYSQL_HOSTNAME=mysql
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_USER=phpsouthwales

# A common use case is to supply database creds via the environment. Edit settings.php
# like so:
#
# $databases['default']['default'] = [
# 'database' => getenv('MYSQL_DATABASE'),
# 'driver' => 'mysql',
# 'host' => getenv('MYSQL_HOSTNAME'),
# 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
# 'password' => getenv('MYSQL_PASSWORD'),
# 'port' => getenv('MYSQL_PORT'),
# 'prefix' => '',
# 'username' => getenv('MYSQL_USER'),
# ];
#
# Uncomment and populate as needed.
# MYSQL_DATABASE=
# MYSQL_HOSTNAME=
# MYSQL_PASSWORD=
# MYSQL_PORT=
# MYSQL_USER=

# Another common use case is to set Drush's --uri via environment.
# DRUSH_OPTIONS_URI=http://example.com

DRUPAL_SALT=
DRUPAL_SALT=abc123

MEETUP_EVENT_STATUSES=upcoming
MEETUP_GROUP_URL_NAME=php-south-wales
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest

- run: make vendor

- name: Install Drupal
run: >
bin/drush --root=$(pwd)/web
Expand Down
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
*
!*/
/bin/
/vendor
!/.docker.env.example
!/.dockerignore
!/.github/**
!/bin/*
!/config/*
!/docker-compose.yaml
!/run
!/tools/**
!/web/modules/custom
!/tools/docker/**
!/web/modules/custom/**
!/web/sites/default/settings.php
!/web/sites/default/settings.platformsh.php
!/web/themes/custom
/bin/
/vendor/
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ The Drupal codebase for the [PHP South Wales user group](https://www.phpsouthwal

## Local environment

The project is using DDEV for local development.
The project is using Docker and Docker Compose for local development.

### Installing the site

To install the site from scratch, run `ddev drupal-site-install`. This will install Drupal from the existing configuration, build the theme assets, and import a set of events from Meetup.com.
If you are using [Traefik](https://docs.traefik.io) (recommended), then the site should now be available at <http://phpsouthwales.docker.localhost>.

## Updating Drupal core using Composer

ddev composer update 'drupal/core-*'
docker-compose exec php composer update 'drupal/core-*'

## Hosting

Expand Down
49 changes: 49 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
x-app: &default-app
env_file:
- .docker.env

services:
proxy:
image: nginxproxy/nginx-proxy
volumes:
- /var/run/docker.sock:/tmp/docker.sock
ports:
- "${DOCKER_WEB_PORT_FORWARD:-127.0.0.1:80}:80"

nginx:
<<: *default-app
build:
dockerfile: tools/docker/Dockerfile
context: .
target: nginx
volumes:
- ./:/app
depends_on:
- php
environment:
VIRTUAL_HOST: phpsouthwales.localhost

php:
<<: *default-app
build:
dockerfile: tools/docker/Dockerfile
context: .
target: dev
volumes:
- ./:/app
depends_on:
mysql:
condition: service_healthy

mysql:
<<: *default-app
image: mariadb:10
volumes:
- ./tools/assets/development:/docker-entrypoint-initdb.d
- db-data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "bash", "-c", "echo > /dev/tcp/localhost/3306"]
interval: 1s

volumes:
db-data: {}
60 changes: 60 additions & 0 deletions run
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e

TTY=""
if [[ ! -t 1 ]]; then
TTY="-T"
fi

DC="${DC:-exec}"

function sh {
cmd sh "${@}"
}

function cmd {
# Run any command in the php container.
_dc php "${@}"
}

function composer {
# Execute Composer commands.
. .docker.env

_dc -e COMPOSER_MEMORY_LIMIT=${COMPOSER_MEMORY_LIMIT} php composer "${@}"
}

function drupal:install {
# Install Drupal and pull in the latest event data.
drush site:install -y --account-pass admin123 --existing-config
drush migrate:import --all
drush cache:rebuild
drush core:cron
drush advancedqueue:queue:process event_pull
}

function drupal:refresh {
# Drop the current database and start again from scratch.
drush sql:drop -y
drupal:install
}

function drush {
# Execute Drush commands.
cmd drush "${@}"
}

function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"

compgen -A function | grep -v "^_" | cat -n

printf "\nExtended help:\n Each task has comments for general usage\n"
}

function _dc {
docker-compose ${DC} ${TTY} "${@}"
}

eval "${@:-help}"
28 changes: 28 additions & 0 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG NGINX_VERSION=1
ARG PHP_VERSION=7.4

FROM php:${PHP_VERSION}-fpm-alpine AS base
ENV PATH=$PATH:/app/bin
WORKDIR /app
RUN apk add --no-cache \
libpng-dev \
mariadb-client \
&& docker-php-ext-install \
bcmath \
gd \
pdo_mysql

FROM base AS dev
RUN apk add --no-cache \
git \
unzip
COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
WORKDIR /app
#COPY composer.* ./
#RUN composer validate --strict
#RUN composer install
#COPY . .

FROM nginx:${NGINX_VERSION}-alpine AS nginx
WORKDIR /app
COPY tools/docker/images/nginx/root /
19 changes: 19 additions & 0 deletions tools/docker/images/nginx/configs/vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
server_name _;
root /app/web;

location / {
try_files $uri /index.php?$query_string;
}

location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass php:9000;
}
}
2 changes: 2 additions & 0 deletions tools/docker/images/php/configs/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
date.timezone=UTC
expose_php=Off
Loading

0 comments on commit b50f428

Please sign in to comment.