Skip to content

Commit

Permalink
Merge pull request #999 from City-of-Helsinki/UHF-11137
Browse files Browse the repository at this point in the history
UHF-11137: Run CI pipelines using Docker compose setup
  • Loading branch information
tuutti authored Dec 13, 2024
2 parents 0373cb8 + e37dea3 commit 49b64cc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 66 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ name: Build artifacts
jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-web:8.3

services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306

steps:
- uses: actions/checkout@v4

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: composer install --no-interaction
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Setup drupal and save database dump
run: |
drush si -y && drush cr
drush si --existing-config -y
drush cim -y
drush sql-dump --result-file=${GITHUB_WORKSPACE}/latest.sql
docker compose exec app bash -c "drush si -y && drush cr"
docker compose exec app bash -c "drush si --existing-config -y"
docker compose exec app bash -c "drush cr"
docker compose exec app bash -c "drush cim -y"
docker compose exec app bash -c "drush sql-dump --result-file=/app/latest.sql"
- name: Upload latest database dump
uses: actions/upload-artifact@v4
Expand Down
75 changes: 33 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,12 @@ on:
push:
branches: ['main', 'dev']
name: CI
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
jobs:
tests:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-web:8.3
options: --hostname app --user 1001

services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306
steps:
- uses: actions/checkout@v4

# Actions worker overrides the default entrypoint with "tail -f /dev/null", so
# we have to start services manually.
- name: Start services
env:
WEBROOT: ${{ github.workspace }}/public
run: entrypoint &

- name: Set browsertest output folder
run: |
echo "BROWSERTEST_OUTPUT_DIRECTORY=$GITHUB_WORKSPACE/public/sites/simpletest" >> $GITHUB_ENV
- name: Make sure configuration was exported in correct language (en or und)
run: |
OUTPUT=$(grep -oP '^langcode: \b(?!(?:en|und)\b)\w+' conf -R || true)
Expand All @@ -46,22 +19,36 @@ jobs:
exit 1
fi
- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
echo "COMPOSE_PROFILES=" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: composer install --no-interaction
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Scan security updates
run: composer audit
run: docker compose exec app bash -c "composer audit"

- name: Check that subtheme is not built with dev mode
run: if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi
run: docker compose exec app bash -c "if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi"

- name: Run PHPCS
run: |
vendor/bin/phpcs public/modules/custom/
vendor/bin/phpcs public/themes/custom/
docker compose exec app bash -c "vendor/bin/phpcs public/modules/custom/"
docker compose exec app bash -c "vendor/bin/phpcs public/themes/custom/"
- name: Run phpstan
run: vendor/bin/phpstan analyze
run: docker compose exec app bash -c "vendor/bin/phpstan analyze"

- name: Download latest dump
env:
Expand All @@ -70,22 +57,26 @@ jobs:

- name: Install Drupal
run: |
mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql
drush deploy
- name: Start services
run: |
for i in {1..5}; do RESPONSE_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" "$SIMPLETEST_BASE_URL" || true); if [ "$RESPONSE_CODE" -gt "301" ] || [ "$RESPONSE_CODE" -lt "200" ]; then sleep 2; fi; done
docker compose exec app bash -c "mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql"
docker compose exec app bash -c "drush deploy"
- name: Run PHPUnit tests
run: |
composer test-php public/modules/custom
if [ -d "tests/" ]; then composer test-php tests/; else echo "No DTT tests found. Ignoring..."; fi
docker compose exec app bash -c "mkdir -p /app/results"
if [ -d "tests/" ]; then
docker compose exec app bash -c "composer test-php tests/"
fi
docker compose exec app bash -c "composer test-php public/modules/custom"
- name: Export logs
if: always()
run: docker compose logs app > results/service.log

- name: Create an artifact from test report
uses: actions/upload-artifact@v4
if: always()
with:
name: results
path: ${{ env.BROWSERTEST_OUTPUT_DIRECTORY }}
path: results/
retention-days: 1
6 changes: 6 additions & 0 deletions compose.ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
app:
user: "1001:1001"
environment:
SYMFONY_DEPRECATIONS_HELPER: disabled
BROWSERTEST_OUTPUT_DIRECTORY: /app/results
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ services:
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}-varnish.tls=true"
- "traefik.http.services.${COMPOSE_PROJECT_NAME}-varnish.loadbalancer.server.port=6081"
- "traefik.docker.network=stonehenge-network"
profiles:
- varnish
elastic-proxy:
container_name: "${COMPOSE_PROJECT_NAME}-elastic-proxy"
image: nginxinc/nginx-unprivileged:alpine-perl
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49b64cc

Please sign in to comment.