diff --git a/.github/workflows/drupal-example.yaml b/.github/workflows/drupal-example.yaml new file mode 100644 index 0000000..874ba74 --- /dev/null +++ b/.github/workflows/drupal-example.yaml @@ -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 diff --git a/.lagoon/cli.dockerfile b/.lagoon/Dockerfile similarity index 53% rename from .lagoon/cli.dockerfile rename to .lagoon/Dockerfile index 350f381..4da6e38 100644 --- a/.lagoon/cli.dockerfile +++ b/.lagoon/Dockerfile @@ -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 diff --git a/.lagoon/nginx.dockerfile b/.lagoon/nginx.dockerfile deleted file mode 100644 index 8374249..0000000 --- a/.lagoon/nginx.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -ARG CLI_IMAGE -FROM ${CLI_IMAGE} AS cli - -FROM uselagoon/nginx-drupal:latest - -COPY --from=cli /app /app - -# Define where the Drupal Root is located -ENV WEBROOT=web diff --git a/.lagoon/php.dockerfile b/.lagoon/php.dockerfile deleted file mode 100644 index c34ae8f..0000000 --- a/.lagoon/php.dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -ARG CLI_IMAGE -FROM ${CLI_IMAGE} AS cli - -FROM uselagoon/php-8.3-fpm:latest - -COPY --from=cli /app /app diff --git a/.lagoon/scripts/refresh-components b/.lagoon/scripts/refresh-components deleted file mode 100755 index 18fd748..0000000 --- a/.lagoon/scripts/refresh-components +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env sh -# -# Adds all Drupal CMS components as globally available path repositories. -# -composer config --global --unset repositories - -for path in $(find $PWD -maxdepth 2 -type d -name 'drupal_cms*'); do - composer config --global repositories.$(basename $path) path $path -done diff --git a/TESTING_dockercompose.md b/TESTING_dockercompose.md new file mode 100644 index 0000000..13cf50c --- /dev/null +++ b/TESTING_dockercompose.md @@ -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 +``` diff --git a/composer.json b/composer.json index 4ca996e..92153df 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/docker-compose.yml b/docker-compose.yml index 72c4d6e..84dac95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 @@ -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