From: William Desportes Date: Tue, 17 Aug 2021 13:27:38 +0000 (+0200) Subject: Add tests X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=190a6c0e99c71ea51480298c51ee4e8b6a61536d;p=roundcube-roundcubemail-docker.git Add tests --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 563d04b..e538b47 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,13 +3,16 @@ name: Build Docker image on: [push] jobs: - build-variants: - name: Build image variants + build-and-testvariants: + name: Build image variants and run tests runs-on: ubuntu-latest strategy: fail-fast: false matrix: - variants: ["apache", "fpm", "fpm-alpine"] + include: + - { variant: 'apache', test-files: ['apache-postgres'], docker-tag: 'roundcube-test-apache' } + - { variant: 'fpm', test-files: ['fpm-postgres'], docker-tag: 'roundcube-test-fpm' } + - { variant: 'fpm-alpine', test-files: ['fpm-postgres'], docker-tag: 'roundcube-test-fpm-alpine' } steps: - name: Checkout repository uses: actions/checkout@v2 @@ -22,5 +25,15 @@ jobs: with: username: ${{ secrets.DOCKER_PULL_USERNAME }} password: ${{ secrets.DOCKER_PULL_PASSWORD }} - - name: Build image variant "${{ matrix.variants }}" - run: cd ${{ matrix.variants }} && docker build ./ + - name: Build image variant "${{ matrix.variant }}" + run: cd ${{ matrix.variant }} && docker build ./ -t ${{ matrix.docker-tag }} + - name: Run tests + env: + ROUNDCUBEMAIL_TEST_IMAGE: ${{ matrix.docker-tag }} + run: | + set -exu; + for testFile in ${{ join(matrix.test-files, ' ') }}; + do + docker-compose -f ./tests/docker-compose.test-${testFile}.yml \ + up --exit-code-from=sut --abort-on-container-exit + done diff --git a/tests/docker-compose.test-apache-postgres.yml b/tests/docker-compose.test-apache-postgres.yml new file mode 100644 index 0000000..ac2fc33 --- /dev/null +++ b/tests/docker-compose.test-apache-postgres.yml @@ -0,0 +1,61 @@ +version: "2" + +services: + roundcubemail: + image: ${ROUNDCUBEMAIL_TEST_IMAGE:-roundcube-test-apache} + healthcheck: + # To make it obvious in logs "ping=ping" is added + test: ["CMD", "curl", "--fail", "http://localhost/?ping=ping"] + interval: 2s + timeout: 3s + retries: 30 + start_period: 10s + depends_on: + roundcubedb: + condition: service_healthy + networks: + roundcube_test_net: + aliases: + - roundcubemail + environment: + - ROUNDCUBEMAIL_DB_TYPE=pgsql + - ROUNDCUBEMAIL_DB_HOST=roundcubedb # same as pgsql container name + - ROUNDCUBEMAIL_DB_NAME=roundcube # same as pgsql POSTGRES_DB env name + - ROUNDCUBEMAIL_DB_USER=roundcube # same as pgsql POSTGRES_USER env name + - ROUNDCUBEMAIL_DB_PASSWORD=roundcube # same as pgsql POSTGRES_PASSWORD env name + + roundcubedb: + image: postgres:alpine + healthcheck: + # "roundcube" is the POSTGRES_USER value + test: ["CMD-SHELL", "pg_isready -U roundcube"] + interval: 2s + timeout: 3s + retries: 30 + start_period: 10s + networks: + roundcube_test_net: + aliases: + - roundcubedb + environment: + - POSTGRES_DB=roundcube + - POSTGRES_USER=roundcube + - POSTGRES_PASSWORD=roundcube + + # A name that matches Docker auto test naming, you want a name here is one + # Source: https://docs.docker.com/docker-hub/builds/automated-testing/#set-up-automated-test-files + sut: + image: alpine:3.14 + networks: + roundcube_test_net: + depends_on: + roundcubemail: + condition: service_healthy + roundcubedb: + condition: service_healthy + command: /tests/run.sh + volumes: + - ./run.sh:/tests/run.sh:ro + working_dir: /tests +networks: + roundcube_test_net: diff --git a/tests/docker-compose.test-fpm-postgres.yml b/tests/docker-compose.test-fpm-postgres.yml new file mode 100644 index 0000000..94b52ca --- /dev/null +++ b/tests/docker-compose.test-fpm-postgres.yml @@ -0,0 +1,92 @@ +version: "2" + +services: + roundcubemail-fpm: + image: ${ROUNDCUBEMAIL_TEST_IMAGE:-roundcube-test-fpm} + healthcheck: + # Check until the FPM port is in in the LISTEN list + test: ["CMD-SHELL", "netstat -an | grep -q -F \":9000\""] + interval: 2s + timeout: 3s + retries: 30 + start_period: 10s + depends_on: + roundcubedb: + condition: service_healthy + networks: + roundcube_test_net: + aliases: + - roundcubemail-fpm + volumes: + - www-vol:/var/www/html + environment: + - ROUNDCUBEMAIL_DB_TYPE=pgsql + - ROUNDCUBEMAIL_DB_HOST=roundcubedb # same as pgsql container name + - ROUNDCUBEMAIL_DB_NAME=roundcube # same as pgsql POSTGRES_DB env name + - ROUNDCUBEMAIL_DB_USER=roundcube # same as pgsql POSTGRES_USER env name + - ROUNDCUBEMAIL_DB_PASSWORD=roundcube # same as pgsql POSTGRES_PASSWORD env name + + roundcubedb: + image: postgres:alpine + healthcheck: + # "roundcube" is the POSTGRES_USER value + test: ["CMD-SHELL", "pg_isready -U roundcube"] + interval: 2s + timeout: 3s + retries: 30 + start_period: 10s + networks: + roundcube_test_net: + aliases: + - roundcubedb + environment: + - POSTGRES_DB=roundcube + - POSTGRES_USER=roundcube + - POSTGRES_PASSWORD=roundcube + + roundcubenginx: + image: nginx:alpine + healthcheck: + # To make it obvious in logs "ping=ping" is added + test: ["CMD", "curl", "--fail", "http://localhost/?ping=ping"] + interval: 2s + timeout: 3s + retries: 30 + start_period: 10s + networks: + roundcube_test_net: + aliases: + - roundcubenginx + depends_on: + roundcubemail-fpm: + condition: service_healthy + volumes: + - www-vol:/var/www/html + - ./nginx-default.conf:/etc/nginx/conf.d/default.conf + environment: + - NGINX_HOST=localhost # set your local domain or your live domain + + # A name that matches Docker auto test naming, you want a name here is one + # Source: https://docs.docker.com/docker-hub/builds/automated-testing/#set-up-automated-test-files + sut: + image: alpine:3.14 + networks: + roundcube_test_net: + depends_on: + roundcubenginx: + condition: service_healthy + roundcubemail-fpm: + condition: service_healthy + roundcubedb: + condition: service_healthy + command: /tests/run.sh + volumes: + - ./run.sh:/tests/run.sh:ro + working_dir: /tests + environment: + ROUNDCUBE_URL: http://roundcubenginx/ +networks: + roundcube_test_net: + +volumes: + www-vol: \ No newline at end of file diff --git a/tests/nginx-default.conf b/tests/nginx-default.conf new file mode 100644 index 0000000..80f2f0d --- /dev/null +++ b/tests/nginx-default.conf @@ -0,0 +1,29 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + server_tokens off; + autoindex off; + + root /var/www/html; + + location / { + index index.php; + } + + location ~ \.php$ { + fastcgi_pass roundcubemail-fpm:9000; + # regex to split $uri to $fastcgi_script_name and $fastcgi_path + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + + # Bypass the fact that try_files resets $fastcgi_path_info + # see: https://trac.nginx.org/nginx/ticket/321 + set $path_info $fastcgi_path_info; + fastcgi_param PATH_INFO $path_info; + + fastcgi_index index.php; + include fastcgi.conf; + } +} diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..09df47f --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -eu + +# findText needle haystack +findText () { + # avoid grep exit code 1 on non match using cat + NBR="$(echo "${2}" | grep -c -F "${1}" | cat)" + if [ $NBR -gt 0 ]; then + echo "[OK] Found \"${1}\" ${NBR} time(s) in the input" > /dev/stdout + return 0 + fi + echo "[FAIL] \"${1}\" was not found in the input \"${2}\"" > /dev/stderr + return 1 +} + +echo 'Installing pckages' + +apk add --no-cache --update html2text curl + +echo 'Starting tests...' +ROUNDCUBE_URL="${ROUNDCUBE_URL:-"http://roundcubemail/"}" +echo 'Fetching homepage' +HOMEPAGE_TEXT=$(curl -s --fail "${ROUNDCUBE_URL}" | html2text) +echo 'Checking homepage' +findText 'Roundcube' "${HOMEPAGE_TEXT}" +findText 'Roundcube Webmail' "${HOMEPAGE_TEXT}" +findText 'Username [_user ]' "${HOMEPAGE_TEXT}" +findText 'Password [********************]' "${HOMEPAGE_TEXT}" +findText 'Login' "${HOMEPAGE_TEXT}" +findText 'Warning: This webmail service requires Javascript!' "${HOMEPAGE_TEXT}" +echo 'Homepage is okay' + +echo 'End.' \ No newline at end of file