Skip to content

Commit

Permalink
Merge pull request #143 from DaveLiddament/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
DaveLiddament authored Oct 4, 2024
2 parents 94c30a9 + 9ac67fd commit 3546b98
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}cli

# Increase memory limit
RUN echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini

# install Composer
COPY ./docker/composer.sh /root/

RUN <<EOF
set -eux;
apt-get update;
apt-get install -y \
git \
zip;
rm -rf /var/lib/apt/lists/*;
cd /root/;
chmod 755 composer.sh;
/root/composer.sh;
mv /root/composer.phar /usr/local/bin/composer;
rm /root/composer.sh;
EOF

# install Xdebug
ARG XDEBUG_ENABLED=1

RUN <<EOF
if [ $XDEBUG_ENABLED -eq 1 ]; then
pecl install xdebug;
docker-php-ext-enable xdebug;
fi
EOF

WORKDIR /app/
39 changes: 39 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
services:
latest:
build:
args:
PHP_VERSION: ""
tty: true
volumes:
- .:/app/:delegated
php80:
build:
args:
PHP_VERSION: "8.0-"
extends:
service: latest
php81:
build:
args:
PHP_VERSION: "8.1-"
extends:
service: latest
php82:
build:
args:
PHP_VERSION: "8.2-"
extends:
service: latest
php83:
build:
args:
PHP_VERSION: "8.3-"
extends:
service: latest
php84:
build:
args:
PHP_VERSION: "8.4-rc-"
XDEBUG_ENABLED: 0
extends:
service: latest
19 changes: 19 additions & 0 deletions docker/composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

# copied from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md

EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
30 changes: 30 additions & 0 deletions docs/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,35 @@ composer ci-8.1
In addition to the above code coverage needs to 100%.
Documented usage of `@codeCoverageIgnore` is allowed for the cases for lines of code where it is impossible to get test coverage.

## Docker

A docker file has been provided to help with development.

#### Build
Build the image:

```shell
docker compose build
```

#### Run the services

Start the services
```shell
docker compose up -d
```

You can run composer command. E.g. To run `composer cs-fix` on PHP 8.2

```shell
docker compose exec php82 composer cs-fix
```

See the composer scripts section for all scripts available.

You can also get shell access. E.g. to get shell access on PHP 8.3:

```shell
docker compose exec php82 bash
```

0 comments on commit 3546b98

Please sign in to comment.