Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the local docker development experience #107

Merged
merged 17 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .docker/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions .docker/docker-compose.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ jobs:
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer install --prefer-dist --no-progress

- name: Prepare unittests configuration
run: sed -i 's/{MYVERSION}/${{ matrix.php.unittest-version }}/g' phpunit.ci.xml

- name: Ensure source code is linted
run: ./vendor/bin/phpcs src
run: composer exec phpcs -- src/

- name: PHPUnit
run: ./vendor/bin/phpunit -c phpunit.ci.xml --coverage-xml ./.coverage
run: composer exec phpunit -- -c phpunit.ci.xml --coverage-xml ./.coverage
env:
XDEBUG_MODE: coverage

Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
.phpunit.result.cache
.idea
dist/
composer.lock
phpunit.xml
.phpunit.cache/
.phpunit.cache/
composer.lock
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG PHP_VERSION

FROM composer:2 as composer
FROM php:${PHP_VERSION}-fpm

ENV DEBIAN_FRONTEND noninteractive

# Install dependencies
RUN apt update && \
apt install -y --no-install-recommends \
git \
zip \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

RUN mkdir -p /app/vendor && chown -R www-data:www-data /app

USER www-data
WORKDIR /app

COPY --link .docker/php.ini /usr/local/etc/php/php.ini

COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY --link composer.json ./
RUN composer install --prefer-dist --no-progress
35 changes: 35 additions & 0 deletions Dockerfile.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG PHP_VERSION

FROM composer:1 as composer
FROM php:${PHP_VERSION}-fpm

ENV DEBIAN_FRONTEND noninteractive

# Update sources.list to outdated Debian archives
RUN sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list && \
sed -i s/security.debian.org/archive.debian.org/g /etc/apt/sources.list && \
sed -i s/stretch-updates/stretch/g /etc/apt/sources.list

# Install dependencies
RUN apt update && \
apt install -y --no-install-recommends \
git \
zip \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

RUN mkdir -p /app/vendor && chown -R www-data:www-data /app

USER www-data
WORKDIR /app

COPY --link .docker/php.ini /usr/local/etc/php/php.ini

COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY --link composer.json ./
RUN composer install --prefer-dist --no-progress
35 changes: 0 additions & 35 deletions Makefile

This file was deleted.

43 changes: 43 additions & 0 deletions Taskfile.php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: 3

vars:
# Required variables
PHP_VERSION: '{{ .PHP_VERSION }}'
PHPUNIT_VERSION: '{{ .PHPUNIT_VERSION }}'
# Defaulted variable
COMPOSE_SERVICE: '{{ .COMPOSE_SERVICE | default "php" }}'
PHPUNIT_FILE: '{{ .PHPUNIT_FILE | default "phpunit.dist.xml" }}'

env:
PHP_VERSION: '{{ .PHP_VERSION }}'

tasks:
docker:build:
internal: true
desc: Build the PHP test container
cmds:
- docker compose build --pull {{ .COMPOSE_SERVICE }}

tests:
desc: Execute PHPUnit tests on PHP {{ .PHP_VERSION }}
deps:
- docker:build
cmds:
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml
- docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Unit Test Suite"

tests:integration:
desc: Execute intregration tests
deps:
- docker:build
cmds:
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml
- docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --testsuite "Alma PHP Client Integration Test Suite"

shell:
desc: Connect to PHP container
deps:
- docker:build
cmds:
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml
- docker compose run {{ .COMPOSE_SERVICE }} bash
94 changes: 94 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: 3

env:
UID:
sh: id -u
GID:
sh: id -g

includes:
"5.6":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "5.6"
COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration
PHPUNIT_VERSION: Legacy
PHPUNIT_FILE: phpunit.dist.legacy.xml
"7.0":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "7.0"
COMPOSE_SERVICE: php-legacy # Dockerfile needs specific APT configuration
PHPUNIT_VERSION: PHP7_0
"7.1":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "7.1"
PHPUNIT_VERSION: PHP7_0
"7.2":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "7.2"
PHPUNIT_VERSION: PHP7_2
"7.3":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "7.3"
PHPUNIT_VERSION: PHP7_2
"7.4":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "7.4"
PHPUNIT_VERSION: PHP7_2
"8.0":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.0"
PHPUNIT_VERSION: PHP7_2
"8.1":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.1"
PHPUNIT_VERSION: PHP8_1
"8.2":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.2"
PHPUNIT_VERSION: PHP8_1
"8.3":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.3"
PHPUNIT_VERSION: PHP8_1

tasks:
default:
cmds:
- cmd: task -l
silent: true

docker:down:
desc: Clean up the docker environment
cmds:
- docker compose down --volumes --remove-orphans

lint:
desc: Lint the php code
deps:
- 8.3:docker:build
cmds:
- docker compose run php composer exec phpcs -- src/

lint:fix:
desc: Lint fix the php code
deps:
- 8.3:docker:build
cmds:
- docker compose run php composer exec phpcbf -- src/ tests/

build:
desc: Build zip dist package using Docker
deps:
- 8.3:docker:build
cmds:
- docker compose run php ./build.sh
18 changes: 3 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/usr/bin/env bash

DIR=`pwd`

rm -rf ./dist/
rm -rf /tmp/alma-php-client
mkdir -p /tmp/alma-php-client

cp -r ./* /tmp/alma-php-client/

mkdir ./dist

cd /tmp/alma-php-client/ || exit
rm -rf vendor
rm -rf dist/ vendor/
mkdir -p ./dist
composer install --no-dev
zip -9 -r "$DIR/dist/alma-php-client.zip" . --exclude \*dist\* \*.git\* \*.idea\* \*.DS_Store

rm -rf /tmp/alma-php-client
zip -9 -r "dist/alma-php-client.zip" src/ README.md CHANGELOG.md LICENSE composer.json
26 changes: 26 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
php:
user: ${UID:-1000}:${GID:-1000}
build:
context: ./
dockerfile: Dockerfile
args:
PHP_VERSION: ${PHP_VERSION}
ports:
- "8080:80"
volumes:
- ./:/app
- /app/vendor

php-legacy:
user: ${UID:-1000}:${GID:-1000}
build:
context: ./
dockerfile: Dockerfile.legacy
args:
PHP_VERSION: ${PHP_VERSION}
ports:
- "8080:80"
volumes:
- ./:/app
- /app/vendor
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"lock": false
}
}
4 changes: 2 additions & 2 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit/PHP8_1</directory>
<directory>tests/Unit/{MYVERSION}</directory>
</testsuite>
<testsuite name="Alma PHP Client Integration Test Suite">
<directory>tests/Integration/PHP8_1</directory>
<directory>tests/Integration/{MYVERSION}</directory>
</testsuite>
</testsuites>
<php>
Expand Down
Loading
Loading