|
1 | | -FROM php:8.3.12-cli |
| 1 | +FROM php:8.3.12-cli AS base |
2 | 2 | RUN apt-get update \ |
3 | | - && apt-get install -y libmagickwand-dev tesseract-ocr \ |
| 3 | + && apt-get install -y libmagickwand-dev tesseract-ocr unzip \ |
4 | 4 | && pecl install imagick \ |
5 | 5 | && docker-php-ext-enable imagick |
6 | | -COPY ./classes /usr/src/watermeter/classes |
7 | | -COPY ./log /usr/src/watermeter/log |
8 | | -COPY ./public /usr/src/watermeter/public |
9 | | -COPY ./src /usr/src/watermeter/src |
10 | | -COPY ./vendor /usr/src/watermeter/vendor |
| 6 | + |
| 7 | +FROM base AS build |
| 8 | +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer |
| 9 | +WORKDIR /usr/src/watermeter |
| 10 | +COPY composer.json ./ |
| 11 | +RUN composer install --no-ansi --no-interaction --no-progress |
| 12 | +COPY . . |
| 13 | + |
| 14 | +# Run Static Analysis |
| 15 | +RUN vendor/bin/phpstan analyse src classes |
| 16 | +# Run Unit Tests |
| 17 | +RUN vendor/bin/phpunit tests |
| 18 | + |
| 19 | +FROM base AS final |
| 20 | +WORKDIR /usr/src/watermeter |
| 21 | + |
| 22 | +# Ensure that the build stage (tests and PHPStan) has been executed successfully |
| 23 | +# by copying a file from it. This creates a dependency so Docker won't skip it. |
| 24 | +COPY --from=build /usr/src/watermeter/composer.json /usr/src/watermeter/composer.json |
| 25 | +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer |
| 26 | +COPY composer.json ./ |
| 27 | + |
| 28 | +# Do not install dev dependencies on final build |
| 29 | +RUN composer install --no-dev --optimize-autoloader --no-ansi --no-interaction --no-progress |
| 30 | + |
| 31 | +# Create necessary directories and set permissions |
| 32 | +RUN mkdir -p log/debug log/error tmp \ |
| 33 | + && chmod -R 777 log tmp |
| 34 | + |
| 35 | +COPY classes/ ./classes/ |
| 36 | +COPY public/ ./public/ |
| 37 | +COPY src/ ./src/ |
| 38 | +COPY LICENSE README.md ./ |
| 39 | + |
11 | 40 | WORKDIR /usr/src/watermeter/public |
12 | 41 | CMD [ "php", "-S", "0.0.0.0:3000" ] |
0 commit comments