Skip to content

Commit

Permalink
Add tests for Dockerfile instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Apr 19, 2022
1 parent 8a46dfd commit e285b7c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/Dockerfile-basics
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions tests/Dockerfile-production
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e285b7c

Please sign in to comment.