From e285b7ce0db56a6f70fe0661e2692cc66793105e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 24 Mar 2022 08:32:28 +0100 Subject: [PATCH] Add tests for `Dockerfile` instructions --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ tests/Dockerfile-basics | 11 +++++++++++ tests/Dockerfile-production | 29 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/Dockerfile-basics create mode 100644 tests/Dockerfile-production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b631bf..5da8aa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,28 @@ jobs: - run: bash tests/await.sh - run: bash tests/acceptance.sh + Docker: + name: Docker (${{ matrix.dockerfile }}) + runs-on: ubuntu-20.04 + strategy: + matrix: + dockerfile: + - "Dockerfile-basics" + - "Dockerfile-production" + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + - run: composer install -d tests/install-as-dep/ + - run: docker build -f tests/${{ matrix.dockerfile }} tests/install-as-dep/ + - run: docker run -d -p 8080:8080 -v "$PWD/examples/index.php":/app/public/index.php -v "$PWD/composer.json":/app/composer.json -v "$PWD/LICENSE":/app/LICENSE -v "$PWD/tests/":/app/tests/ $(docker images -q | head -n1) + - run: bash tests/await.sh + - run: bash tests/acceptance.sh + - run: docker stop $(docker ps -qn1) + - run: docker logs $(docker ps -qn1) + if: ${{ always() }} + nginx-webserver: name: nginx + PHP-FPM (PHP ${{ matrix.php }}) runs-on: ubuntu-20.04 diff --git a/tests/Dockerfile-basics b/tests/Dockerfile-basics new file mode 100644 index 0000000..dfdb3b8 --- /dev/null +++ b/tests/Dockerfile-basics @@ -0,0 +1,11 @@ +# syntax=docker/dockerfile:1 +FROM php:8.1-cli + +WORKDIR /app/ +COPY public/ public/ +COPY vendor/ vendor/ + +ENV X_LISTEN 0.0.0.0:8080 +EXPOSE 8080 + +ENTRYPOINT php public/index.php diff --git a/tests/Dockerfile-production b/tests/Dockerfile-production new file mode 100644 index 0000000..f6c4452 --- /dev/null +++ b/tests/Dockerfile-production @@ -0,0 +1,29 @@ +# syntax=docker/dockerfile:1 +FROM composer:2 AS build + +WORKDIR /app/ +COPY composer.json composer.lock ./ +# production environment should install optimized dependencies: +# RUN composer install --no-dev --ignore-platform-reqs --optimize-autoloader +# dev environment already has dependencies installed: +COPY vendor/ vendor/ + +FROM php:8.1-alpine + +# recommended: install optional extensions ext-ev and ext-sockets +RUN apk --no-cache add ${PHPIZE_DEPS} libev \ + && pecl install ev \ + && docker-php-ext-enable ev \ + && docker-php-ext-install sockets \ + && apk del ${PHPIZE_DEPS} + +WORKDIR /app/ +COPY public/ public/ +# COPY src/ src/ +COPY --from=build /app/vendor/ vendor/ + +ENV X_LISTEN 0.0.0.0:8080 +EXPOSE 8080 + +USER nobody:nobody +ENTRYPOINT php public/index.php