From b87838502e1b20a70ef590aac18b345cce2d16e1 Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 13 Dec 2024 09:59:12 +0200 Subject: [PATCH 1/2] UHF-11137: Use docker compose in automations --- .github/workflows/artifact.yml | 38 +++++++++--------- .github/workflows/test.yml | 70 ++++++++++++++++------------------ compose.ci.yaml | 6 +++ compose.yaml | 18 +++++++-- 4 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 compose.ci.yaml diff --git a/.github/workflows/artifact.yml b/.github/workflows/artifact.yml index 535dc82bb..969bfa81d 100644 --- a/.github/workflows/artifact.yml +++ b/.github/workflows/artifact.yml @@ -8,32 +8,32 @@ name: Build artifacts jobs: build: runs-on: ubuntu-latest - container: - image: ghcr.io/city-of-helsinki/drupal-php-docker:8.3-alpine - - 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7eb84b92..232aff579 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,33 +3,12 @@ on: push: branches: ['main', 'dev'] name: CI -env: - SYMFONY_DEPRECATIONS_HELPER: disabled - SIMPLETEST_BASE_URL: http://app:8888 jobs: tests: runs-on: ubuntu-latest - container: - image: ghcr.io/city-of-helsinki/drupal-php-docker:8.3-alpine - options: --hostname app - - 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: 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) @@ -40,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: @@ -64,25 +57,26 @@ jobs: - name: Install Drupal run: | - mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql - drush deploy + 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: Start services + - name: Run PHPUnit tests run: | - drush runserver $SIMPLETEST_BASE_URL --dns > /dev/null 2>&1 & + docker compose exec app bash -c "mkdir -p /app/results" - # Wait for drush server to start. - for i in {1..5}; do RESPONSE_CODE=$(curl -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 + 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: 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 + - 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 diff --git a/compose.ci.yaml b/compose.ci.yaml new file mode 100644 index 000000000..20999387c --- /dev/null +++ b/compose.ci.yaml @@ -0,0 +1,6 @@ +services: + app: + user: "1001:1001" + environment: + SYMFONY_DEPRECATIONS_HELPER: disabled + BROWSERTEST_OUTPUT_DIRECTORY: /app/results diff --git a/compose.yaml b/compose.yaml index 703a8d29d..cdf6ca7db 100644 --- a/compose.yaml +++ b/compose.yaml @@ -8,6 +8,7 @@ services: depends_on: - db environment: + WEBROOT: /app/public STAGE_FILE_PROXY_ORIGIN: "${STAGE_FILE_PROXY_ORIGIN}" STAGE_FILE_PROXY_ORIGIN_DIR: "${STAGE_FILE_PROXY_ORIGIN_DIR}" APP_ENV: "${APP_ENV:-local}" @@ -24,7 +25,6 @@ services: # DOCKERHOST: host.docker.internal # Use drush server to run functional tests, so we don't have to care about # permission or SSL issues. - SIMPLETEST_BASE_URL: "http://app:8888" BROWSERTEST_OUTPUT_BASE_URL: "https://${DRUPAL_HOSTNAME}" BROWSERTEST_OUTPUT_DIRECTORY: "/app/public/sites/default/files/simpletest" DRUPAL_VARNISH_HOST: "${COMPOSE_PROJECT_NAME}-varnish" @@ -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 @@ -160,13 +162,21 @@ services: profiles: - queue chromium: - # @todo Update this to newer version once minkphp supports Selenium 4. - # @see https://github.com/minkphp/MinkSelenium2Driver/pull/372 - image: seleniarm/standalone-chromium:106.0 + image: selenium/standalone-chromium + environment: + SE_NODE_OVERRIDE_MAX_SESSIONS: "true" + SE_NODE_MAX_SESSIONS: "16" + SE_START_XVFB: "false" + SE_START_VNC: "false" + SE_SESSION_RETRY_INTERVAL: "1" + SE_SESSION_REQUEST_TIMEOUT: "10" + depends_on: + - app networks: - internal profiles: - testing + networks: internal: external: false From f90bef2e5690bc2d87a69ff366a95ab081e64f33 Mon Sep 17 00:00:00 2001 From: tuutti Date: Fri, 13 Dec 2024 10:02:57 +0200 Subject: [PATCH 2/2] UHF-11137: Updated phpunit.dist.xml --- phpunit.xml.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 22d88d297..7c1efa6e2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,11 +15,11 @@ - - + + - +