Skip to content

Commit

Permalink
maint/update-docker (#7)
Browse files Browse the repository at this point in the history
* maint/update-docker Created `.env.example`.

* maint/update-docker Updated `.gitattributes`.

* maint/update-docker Updated `.gitignore`.

* maint/update-docker Updated `dock`.

* maint/update-docker Updated `docker-compose.yml`.

* maint/update-docker Created `docker/8.1/.gitignore`.

* maint/update-docker Updated `docker/8.1/phpunit.xml`.

* maint/update-docker Created `docker/8.2/.gitignore`.

* maint/update-docker Updated `docker/8.2/phpunit.xml`.

* maint/update-docker Created `docker/8.3/.gitignore`.

* maint/update-docker Updated `docker/8.3/phpunit.xml`.

* maint/update-docker Created `docker/8.4/.gitignore`.

* maint/update-docker Updated `docker/8.4/phpunit.xml`.

* maint/update-docker Updated `test.sh`.

* Delete files

---------

Co-authored-by: david_smith <[email protected]>
  • Loading branch information
zero-to-prod and david_smith authored Jan 10, 2025
1 parent 9fbefa7 commit 1471128
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHP_VERSION=8.1
PHP_DEBUG=8.1
PHP_COMPOSER=8.1
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/test.sh export-ignore
/dock export-ignore
/art/ export-ignore
/.env.example export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ composer.lock
/.phpunit.cache/test-results
/.env
/.phpunit.cache/
.vendor/
.env
52 changes: 48 additions & 4 deletions dock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@

set -e

PHP_VERSION=$(grep "^PHP_VERSION=" .env | cut -d '=' -f2-)
usage() {
cat <<EOF
Usage: $0 <command> [options]
Commands:
init Initialize the .env file from .env.example if it doesn't exist.
test Run PHPUnit tests using the specified PHP version.
composer Run Composer commands using the specified PHP version.
<service> Run a specified Docker service with optional arguments.
Examples:
$0 init
$0 test --filter=MyTest
$0 composer install
$0 php8.1 bash
EOF
exit 1
}

if [ "$#" -lt 1 ]; then
usage
fi

run_service() {
local service=$1
Expand All @@ -12,16 +33,39 @@ run_service() {
fi
}

case "$1" in
init)
if [ ! -f ".env" ]; then
cp ".env.example" ".env"
echo "cp '.env.example' '.env'"
fi
exit 0;
;;
esac

if [ ! -f ".env" ]; then
echo "Project does not have a .env file. Please provide one or run: dock init"
exit 0
fi

PHP_VERSION=$(grep "^PHP_VERSION=" .env | cut -d '=' -f2-)

case "$1" in
test)
shift
run_service "php${PHP_VERSION}" vendor/bin/phpunit --configuration "docker/${PHP_VERSION}/phpunit.xml" "$@"
;;
;;
build)
shift
docker compose build "php${PHP_VERSION}" "$@"
docker compose build "debug${PHP_VERSION}" "$@"
docker compose build "composer${PHP_VERSION}" "$@"
;;
composer)
shift
run_service "composer${PHP_VERSION}" composer "$@"
;;
;;
*)
run_service "$@"
;;
;;
esac
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ services:
service: php8.1
volumes:
- ./:/app:delegated
- ./.vendor/php8.1:/app/vendor
- ./docker/8.1:/usr/local/etc/php
- ./.vendor/php8.1:/app/vendor
build:
target: debug

Expand All @@ -39,8 +39,8 @@ services:
service: php8.2
volumes:
- ./:/app:delegated
- ./.vendor/php8.2:/app/vendor
- ./docker/8.2:/usr/local/etc/php
- ./.vendor/php8.2:/app/vendor
build:
target: debug

Expand All @@ -66,8 +66,8 @@ services:
service: php8.3
volumes:
- ./:/app:delegated
- ./.vendor/php8.3:/app/vendor
- ./docker/8.3:/usr/local/etc/php
- ./.vendor/php8.3:/app/vendor
build:
target: debug

Expand All @@ -93,8 +93,8 @@ services:
service: php8.4
volumes:
- ./:/app:delegated
- ./.vendor/php8.4:/app/vendor
- ./docker/8.4:/usr/local/etc/php
- ./.vendor/php8.4:/app/vendor
build:
target: debug

Expand Down
1 change: 1 addition & 0 deletions docker/8.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phpunit.result.cache
8 changes: 1 addition & 7 deletions docker/8.1/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="/app/vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
colors="true"
>
<phpunit colors="true">
<testsuites>
<testsuite name="default">
<directory>/app/tests</directory>
Expand Down
1 change: 1 addition & 0 deletions docker/8.2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phpunit.result.cache
8 changes: 1 addition & 7 deletions docker/8.2/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="/app/vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
colors="true"
>
<phpunit colors="true">
<testsuites>
<testsuite name="default">
<directory>/app/tests</directory>
Expand Down
1 change: 1 addition & 0 deletions docker/8.3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phpunit.result.cache
8 changes: 1 addition & 7 deletions docker/8.3/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="/app/vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
colors="true"
>
<phpunit colors="true">
<testsuites>
<testsuite name="default">
<directory>/app/tests</directory>
Expand Down
1 change: 1 addition & 0 deletions docker/8.4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.phpunit.result.cache
8 changes: 1 addition & 7 deletions docker/8.4/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="/app/vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
colors="true"
>
<phpunit colors="true">
<testsuites>
<testsuite name="default">
<directory>/app/tests</directory>
Expand Down
31 changes: 0 additions & 31 deletions phpunit.xml

This file was deleted.

8 changes: 4 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e

PHP_VERSIONS=("8.4" "8.3" "8.2" "8.1")
PHP_VERSIONS=("8.4" "8.3" "8.2" "8.1" "8.0" "7.4" "7.3" "7.2" "7.1")

for version in "${PHP_VERSIONS[@]}"; do
for PHP_VERSION in "${PHP_VERSIONS[@]}"; do

docker compose run --rm "composer${version}" composer update
sh dock "composer${PHP_VERSION}" composer update

if ! docker compose run --rm "php${version}" ./vendor/bin/phpunit
if ! sh dock "php${PHP_VERSION}" ./vendor/bin/phpunit --configuration "docker/${PHP_VERSION}/phpunit.xml"
then
exit 1
fi
Expand Down

0 comments on commit 1471128

Please sign in to comment.