From b5923169a637bc58eb2464c205fe95ecc26332a4 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Mon, 28 Dec 2020 16:46:03 +0100 Subject: [PATCH] Automated acceptance tests Includes a Dockerfile that can be used to build the ghcr.io/e107inc/e107/e107-dev container --- .github/workflows/test-acceptance.yml | 53 +++++++++++++++++++++++ .github/workflows/test-unit.yml | 4 +- e107_tests/lib/ci/Dockerfile | 27 ++++++++++++ e107_tests/lib/ci/config.ci.yml | 10 ++++- e107_tests/lib/deployers/SFTPDeployer.php | 3 +- 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test-acceptance.yml create mode 100644 e107_tests/lib/ci/Dockerfile diff --git a/.github/workflows/test-acceptance.yml b/.github/workflows/test-acceptance.yml new file mode 100644 index 000000000..fa125678a --- /dev/null +++ b/.github/workflows/test-acceptance.yml @@ -0,0 +1,53 @@ +name: Acceptance Tests + +on: + push: + pull_request: + +jobs: + test-acceptance: + runs-on: ubuntu-latest + container: + image: php:latest + services: + target: + image: ghcr.io/e107inc/e107/e107-dev:latest + ports: + - 22 + - 80 + - 3306 + options: >- + --tmpfs /tmp + --tmpfs /run + --tmpfs /run/lock + --volume /sys/fs/cgroup:/sys/fs/cgroup:ro + + steps: + - name: Install system dependencies + run: | + apt-get update + apt-get install -y git zip libzip-dev sshpass rsync + + - name: Install necessary PHP extensions + run: docker-php-ext-install -j "$(nproc)" zip pdo_mysql mysqli + + - uses: actions/checkout@v2 + + - name: Install Composer + run: curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer + + - name: Install test dependencies + run: composer update --prefer-dist --no-progress + working-directory: ./e107_tests/ + + - name: Download Git submodule dependencies + run: git submodule update --init --recursive --remote + + - name: Install the CI test configuration file + run: | + cp ./e107_tests/lib/ci/config.ci.yml ./e107_tests/config.yml + sed -i "s/host: 'db'/host: 'target'/" ./e107_tests/config.yml + + - name: Run acceptance tests + run: php ./vendor/bin/codecept run acceptance --steps --debug + working-directory: ./e107_tests/ \ No newline at end of file diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index d83cd343e..78c62bbb9 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -11,7 +11,7 @@ env: CC_TEST_REPORTER_ID: 8948074581c1ffe7f4e47995c65d7d303882310256edd73536723d7c92adb1e3 jobs: - test: + test-unit: strategy: fail-fast: false matrix: @@ -105,7 +105,7 @@ jobs: - name: Install Composer run: curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer - - name: Install dependencies + - name: Install test dependencies run: composer update --prefer-dist --no-progress working-directory: ./e107_tests/ diff --git a/e107_tests/lib/ci/Dockerfile b/e107_tests/lib/ci/Dockerfile new file mode 100644 index 000000000..13a09cce2 --- /dev/null +++ b/e107_tests/lib/ci/Dockerfile @@ -0,0 +1,27 @@ +FROM ubuntu:20.04 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get install -y wget gnupg +RUN wget -O - https://repo.saltstack.com/py3/ubuntu/20.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add - +RUN mkdir -pv /etc/apt/sources.list.d/ +RUN echo 'deb http://repo.saltstack.com/py3/ubuntu/20.04/amd64/latest focal main' |\ + tee /etc/apt/sources.list.d/saltstack.list +RUN apt-get update +RUN apt-get install -y systemd-sysv salt-minion openssh-server rsync +RUN systemctl disable salt-minion.service +RUN mkdir -pv /etc/salt/ + +COPY salt /var/tmp/salt +COPY config.ci.yml /var/tmp/salt/pillars/config-local.sls +RUN rm -fv /var/tmp/salt/pillars/config.sls && touch /var/tmp/salt/pillars/config.sls +RUN rm -fv /var/tmp/salt/pillars/config-sample.sls && touch /var/tmp/salt/pillars/config-sample.sls +RUN cp -fv /var/tmp/salt/master /etc/salt/minion + +WORKDIR /var/tmp/salt +RUN salt-call -l debug --id=e107-dev --local state.apply e107-dev +WORKDIR / + +VOLUME ["/sys/fs/cgroup"] +ENTRYPOINT ["/usr/sbin/init"] \ No newline at end of file diff --git a/e107_tests/lib/ci/config.ci.yml b/e107_tests/lib/ci/config.ci.yml index ce6018476..8e1402715 100644 --- a/e107_tests/lib/ci/config.ci.yml +++ b/e107_tests/lib/ci/config.ci.yml @@ -1,9 +1,15 @@ --- -deployer: 'local' -url: 'http://set-this-to-your-acceptance-test-url.local/' +deployer: 'sftp' +url: 'http://target/e107/' db: host: 'db' dbname: 'app' user: 'root' password: 'Database Password for Continuous Integration' populate: true +fs: + host: 'target' + user: 'www-data' + port: '22' + password: 'UNIX Password for Continuous Integration' + path: '/var/www/html/e107/' \ No newline at end of file diff --git a/e107_tests/lib/deployers/SFTPDeployer.php b/e107_tests/lib/deployers/SFTPDeployer.php index c836ded5b..e72f5597a 100644 --- a/e107_tests/lib/deployers/SFTPDeployer.php +++ b/e107_tests/lib/deployers/SFTPDeployer.php @@ -34,7 +34,8 @@ class SFTPDeployer extends Deployer private function generateRsyncRemoteShell() { - $prefix = 'ssh -p '.escapeshellarg($this->getFsParam('port')); + $prefix = 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p '. + escapeshellarg($this->getFsParam('port')); if (!empty($this->getFsParam('privkey_path'))) return $prefix.' -i ' . escapeshellarg($this->getFsParam('privkey_path')); else