Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Dockerfile for BuildKit and add Github Actions #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/workflows/drupal-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Drupal test routine

on:
push:
branches:
- 'main'
- 'dev'
pull_request:
branches:
- 'main'

jobs:
test-suite:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Pull all images
run: |
docker compose pull --ignore-pull-failures
- name: Install test harness
run: |
yarn add leia-parser mocha chai@4 command-line-test
- name: Generate test files
run: |
yarn leia "TESTING*.md" test -r 2 -s 'Start up tests' -t 'Verification commands' -c 'Destroy tests' --split-file
- name: Run docker compose tests
run: |
yarn mocha --timeout 900000 test/*compose*.func.js
16 changes: 12 additions & 4 deletions .lagoon/cli.dockerfile → .lagoon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
FROM uselagoon/php-8.3-cli-drupal:latest
FROM uselagoon/php-8.3-cli-drupal:latest AS cli

COPY composer.json /app
COPY .lagoon/assets /app/assets
COPY .lagoon/scripts /app/scripts
COPY config /app/config

ADD https://git.drupalcode.org/project/drupal_cms.git#0.x /app/drupal_cms

RUN /app/scripts/refresh-components \
&& composer install --no-dev
RUN composer install --no-dev

RUN mkdir -p -v -m775 /app/web/sites/default/files

# Define where the Drupal Root is located
ENV WEBROOT=web

FROM uselagoon/nginx-drupal:latest AS nginx

COPY --from=cli /app /app

ENV WEBROOT=web

FROM uselagoon/php-8.3-fpm:latest AS php

COPY --from=cli /app /app
9 changes: 0 additions & 9 deletions .lagoon/nginx.dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions .lagoon/php.dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions .lagoon/scripts/refresh-components

This file was deleted.

96 changes: 96 additions & 0 deletions TESTING_dockercompose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Docker Compose Drupal base - php8, nginx, mariadb
=================================================

This is a docker compose version of the Lando example tests:

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should remove any previous runs and poweroff
sed -i -e "/###/d" docker-compose.yml
docker network inspect amazeeio-network >/dev/null || docker network create amazeeio-network
docker compose down

# Should start up our Lagoon Drupal site successfully
docker compose build && docker compose up -d

# Ensure mariadb pod is ready to connect
docker compose exec -T cli bash -c "wait-for mariadb:3306"
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should be able to site install via Drush
docker compose exec -T cli bash -c "drush si -y"
docker compose exec -T cli bash -c "drush cr -y"
docker compose exec -T cli bash -c "drush status" | grep "Drupal bootstrap" | grep "Successful"

# Should have all the services we expect
docker ps --filter label=com.docker.compose.project=drupal-cms-example | grep Up | grep drupal-cms-example-nginx-1
docker ps --filter label=com.docker.compose.project=drupal-cms-example | grep Up | grep drupal-cms-example-mariadb-1
docker ps --filter label=com.docker.compose.project=drupal-cms-example | grep Up | grep drupal-cms-example-php-1
docker ps --filter label=com.docker.compose.project=drupal-cms-example | grep Up | grep drupal-cms-example-cli-1

# Should ssh against the cli container by default
docker compose exec -T cli bash -c "env | grep LAGOON=" | grep cli-drupal

# Should have the correct environment set
docker compose exec -T cli bash -c "env" | grep LAGOON_ROUTE | grep drupal-cms-example.localhost
docker compose exec -T cli bash -c "env" | grep LAGOON_ENVIRONMENT_TYPE | grep development

# Should be running PHP 8
docker compose exec -T cli bash -c "php -v" | grep "PHP 8"

# Should have composer
docker compose exec -T cli bash -c "composer --version"

# Should have php cli
docker compose exec -T cli bash -c "php --version"

# Should have drush
docker compose exec -T cli bash -c "drush --version"

# Should have npm
docker compose exec -T cli bash -c "npm --version"

# Should have node
docker compose exec -T cli bash -c "node --version"

# Should have yarn
docker compose exec -T cli bash -c "yarn --version"

# Should have a running Drupal site served by nginx on port 8080
docker compose exec -T cli bash -c "curl -kL http://nginx:8080" | grep "Drush Site-Install"

# Should be able to db-export and db-import the database
docker compose exec -T cli bash -c "drush sql-dump --result-file /app/test.sql"
docker compose exec -T cli bash -c "drush sql-drop -y"
docker compose exec -T cli bash -c "drush sql-cli < /app/test.sql"
docker compose exec -T cli bash -c "rm test.sql*"

# Should be able to show the drupal tables
docker compose exec -T cli bash -c "echo U0hPVyBUQUJMRVM7 | base64 -d > /app/showtables.sql"
docker compose exec -T cli bash -c "drush sqlq --file /app/showtables.sql" | grep users

# Should be able to rebuild and persist the database
docker compose build && docker compose up -d
docker compose exec -T cli bash -c "echo U0hPVyBUQUJMRVM7 | base64 -d > /app/showtables.sql"
docker compose exec -T cli bash -c "drush sqlq --file /app/showtables.sql" | grep users
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be able to destroy our Drupal site with success
docker compose down --volumes --remove-orphans
```
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
"chat": "https://drupal.org/node/314178"
},
"repositories": {
"drupal_cms": {
"type": "path",
"url": "./drupal_cms/*",
"options": {
"symlink": false
}
},
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
Expand Down
14 changes: 6 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ services:
cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.)
build:
context: .
dockerfile: .lagoon/cli.dockerfile
image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal-cms-example}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds
target: cli
dockerfile: .lagoon/Dockerfile
labels:
# Lagoon Labels
lagoon.type: cli-persistent
Expand All @@ -44,9 +44,8 @@ services:
nginx:
build:
context: .
dockerfile: .lagoon/nginx.dockerfile
args:
CLI_IMAGE: *cli-image # Inject the name of the cli image
target: nginx
dockerfile: .lagoon/Dockerfile
labels:
lagoon.type: nginx-php-persistent
lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too
Expand All @@ -65,9 +64,8 @@ services:
php:
build:
context: .
dockerfile: .lagoon/php.dockerfile
args:
CLI_IMAGE: *cli-image
target: php
dockerfile: .lagoon/Dockerfile
labels:
lagoon.type: nginx-php-persistent
lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon
Expand Down