|
| 1 | +# This Dockerfile builds the main stochastix image. |
| 2 | +# It contains the PHP environment and the pre-built UI, but NO Symfony source code. |
| 3 | + |
| 4 | +# Stage 1: Fetch the latest UI release assets |
| 5 | +FROM alpine:latest AS ui-fetcher |
| 6 | + |
| 7 | +ARG UI_REPO="phpquant/stochastix-ui" |
| 8 | +ARG UI_VERSION="latest" |
| 9 | + |
| 10 | +WORKDIR /downloads |
| 11 | + |
| 12 | +RUN apk add --no-cache curl jq |
| 13 | + |
| 14 | +# Use the GitHub API to get the download URL for the .tar.gz asset |
| 15 | +RUN ASSET_URL=$(curl -sL https://api.github.com/repos/${UI_REPO}/releases/${UI_VERSION} | jq -r '.assets[] | select(.name | endswith(".tar.gz")) | .browser_download_url') && \ |
| 16 | + if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then echo "Error: Could not find UI release asset." >&2; exit 1; fi && \ |
| 17 | + curl -L -o stochastix-ui.tar.gz "${ASSET_URL}" && \ |
| 18 | + mkdir -p /ui_assets && \ |
| 19 | + tar -xzf stochastix-ui.tar.gz -C /ui_assets |
| 20 | + |
| 21 | +# Stage 2: Prepare the final application environment image |
| 22 | +# Versions |
| 23 | +FROM dunglas/frankenphp:1-php8.4 AS frankenphp_upstream |
| 24 | + |
| 25 | +# The different stages of this Dockerfile are meant to be built into separate images |
| 26 | +# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage |
| 27 | +# https://docs.docker.com/compose/compose-file/#target |
| 28 | + |
| 29 | + |
| 30 | +# Base FrankenPHP image |
| 31 | +FROM frankenphp_upstream AS frankenphp_base |
| 32 | + |
| 33 | +WORKDIR /app |
| 34 | + |
| 35 | +VOLUME /app/var/ |
| 36 | + |
| 37 | +# persistent / runtime deps |
| 38 | +# hadolint ignore=DL3008 |
| 39 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 40 | + libgmp-dev \ |
| 41 | + acl \ |
| 42 | + file \ |
| 43 | + gettext \ |
| 44 | + git \ |
| 45 | + && rm -rf /var/lib/apt/lists/* |
| 46 | + |
| 47 | +RUN set -eux; \ |
| 48 | + install-php-extensions \ |
| 49 | + @composer \ |
| 50 | + apcu \ |
| 51 | + intl \ |
| 52 | + opcache \ |
| 53 | + zip \ |
| 54 | + bcmath \ |
| 55 | + gmp \ |
| 56 | + pdo \ |
| 57 | + pdo_sqlite \ |
| 58 | + ; \ |
| 59 | + pecl install \ |
| 60 | + trader \ |
| 61 | + ds \ |
| 62 | + ; \ |
| 63 | + docker-php-ext-enable \ |
| 64 | + bcmath \ |
| 65 | + gmp \ |
| 66 | + trader \ |
| 67 | + ds \ |
| 68 | + ; |
| 69 | + |
| 70 | +RUN git config --global --add safe.directory /app && git config --global --add safe.directory /repos/core |
| 71 | + |
| 72 | +# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser |
| 73 | +ENV COMPOSER_ALLOW_SUPERUSER=1 |
| 74 | + |
| 75 | +# Transport to use by Mercure (default to Bolt) |
| 76 | +ENV MERCURE_TRANSPORT_URL=bolt:///data/mercure.db |
| 77 | + |
| 78 | +ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d" |
| 79 | + |
| 80 | +COPY --link templates/frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/ |
| 81 | +COPY --link --chmod=755 templates/frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint |
| 82 | +COPY --link templates/frankenphp/Caddyfile /etc/caddy/Caddyfile |
| 83 | + |
| 84 | +COPY --from=ui-fetcher /ui_assets/ /srv/ui/ |
| 85 | +RUN chown -R www-data:www-data /srv/ui |
| 86 | + |
| 87 | +ENTRYPOINT ["docker-entrypoint"] |
| 88 | + |
| 89 | +HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1 |
| 90 | +CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ] |
| 91 | + |
| 92 | +# Dev FrankenPHP image |
| 93 | +FROM frankenphp_base AS frankenphp_dev |
| 94 | + |
| 95 | +ENV APP_ENV=dev |
| 96 | +ENV XDEBUG_MODE=off |
| 97 | +ENV FRANKENPHP_WORKER_CONFIG=watch |
| 98 | + |
| 99 | +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" |
| 100 | + |
| 101 | +RUN set -eux; \ |
| 102 | + install-php-extensions \ |
| 103 | + xdebug \ |
| 104 | + ; |
| 105 | + |
| 106 | +COPY --link templates/frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/ |
| 107 | + |
| 108 | +CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ] |
| 109 | + |
| 110 | +# Prod FrankenPHP image |
| 111 | +FROM frankenphp_base AS frankenphp_prod |
| 112 | + |
| 113 | +ENV APP_ENV=prod |
| 114 | + |
| 115 | +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" |
| 116 | + |
| 117 | +COPY --link templates/frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/ |
| 118 | + |
| 119 | +# prevent the reinstallation of vendors at every changes in the source code |
| 120 | +COPY --link composer.* symfony.* ./ |
| 121 | +RUN set -eux; \ |
| 122 | + composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress |
| 123 | + |
| 124 | +# copy sources |
| 125 | +COPY --link . ./ |
| 126 | +RUN rm -Rf frankenphp/ |
| 127 | + |
| 128 | +RUN set -eux; \ |
| 129 | + mkdir -p var/cache var/log; \ |
| 130 | + composer dump-autoload --classmap-authoritative --no-dev; \ |
| 131 | + composer dump-env prod; \ |
| 132 | + composer run-script --no-dev post-install-cmd; \ |
| 133 | + chmod +x bin/console; sync; |
0 commit comments