Last active
June 23, 2022 22:04
-
-
Save oliverservin/b83b165cadbda9e112e8c80e3f00bc6c to your computer and use it in GitHub Desktop.
Fly.io: PHP 8.1 Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# syntax = docker/dockerfile:experimental | |
FROM alpine:edge as base | |
LABEL fly_launch_runtime="laravel" | |
RUN apk update \ | |
&& apk add curl zip unzip tzdata supervisor nginx htop vim ca-certificates \ | |
php81 php81-cli \ | |
php81-soap php81-openssl php81-gmp \ | |
php81-pdo_odbc php81-json php81-dom \ | |
php81-pdo php81-zip php81-pdo_mysql \ | |
php81-sqlite3 php81-pdo_pgsql php81-bcmath \ | |
php81-gd php81-odbc php81-pdo_sqlite \ | |
php81-gettext php81-xmlreader php81-bz2 \ | |
php81-iconv php81-pdo_dblib php81-curl \ | |
php81-ctype php81-phar php81-xml \ | |
php81-common php81-mbstring php81-tokenizer \ | |
php81-xmlwriter php81-fileinfo php81-opcache \ | |
php81-simplexml php81-pecl-redis php81-sockets \ | |
php81-pcntl php81-posix php81-pecl-swoole \ | |
php81-fpm \ | |
&& ln -s /usr/bin/php81 /usr/bin/php \ | |
&& cp /etc/nginx/nginx.conf /etc/nginx/nginx.old.conf \ | |
&& rm -rf /etc/nginx/http.d/default.conf \ | |
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ | |
&& adduser -D -u 1000 -g 'app' app \ | |
&& addgroup nginx app \ | |
&& mkdir -p /var/run/php \ | |
&& chown -R app:app /var/run/php \ | |
&& mkdir -p /var/www/html | |
WORKDIR /var/www/html | |
# copy application code, skipping files based on .dockerignore | |
COPY . /var/www/html | |
# Install dependencies, configure server | |
RUN composer update && composer install --optimize-autoloader --no-dev \ | |
&& mkdir -p storage/logs \ | |
&& chown -R app:app /var/www/html \ | |
&& /usr/bin/crontab docker/crontab \ | |
&& mv docker/supervisor.conf /etc/supervisord.conf \ | |
&& mv docker/nginx.conf /etc/nginx/nginx.conf \ | |
&& mv docker/server.conf /etc/nginx/server.conf \ | |
&& mv docker/php.ini /etc/php81/conf.d/php.ini | |
# If we're not using Octane, configure php-fpm | |
RUN if ! grep -Fq "laravel/octane" /var/www/html/composer.json; then \ | |
rm -rf /etc/php81/php-fpm.conf; \ | |
rm -rf /etc/php81/php-fpm.d/www.conf; \ | |
mv docker/php-fpm.conf /etc/php81/php-fpm.conf; \ | |
mv docker/app.conf /etc/php81/php-fpm.d/app.conf; \ | |
elif grep -Fq "spiral/roadrunner" /var/www/html/composer.json; then \ | |
if [ -f ./vendor/bin/rr ]; then ./vendor/bin/rr get-binary; fi; \ | |
rm -f .rr.yaml; \ | |
fi | |
# clear Laravel cache that may be left over | |
RUN composer dump-autoload \ | |
&& php artisan optimize:clear \ | |
&& chmod -R ug+w /var/www/html/storage \ | |
&& chmod -R 755 /var/www/html | |
# Multi-stage build: Build static assets | |
FROM node:14 as node_modules_go_brrr | |
RUN mkdir /app | |
RUN mkdir -p /app | |
WORKDIR /app | |
COPY . . | |
RUN if [ -f "yarn.lock" ]; then \ | |
yarn install; \ | |
elif [ -f "package-lock.json" ]; then \ | |
npm ci --no-audit; \ | |
else \ | |
npm install; \ | |
fi | |
# Create final container, adding in static assets | |
FROM base | |
COPY --from=node_modules_go_brrr /app/public /var/www/html/public | |
# The same port nginx.conf is set to listen on and fly.toml references (standard is 8080) | |
EXPOSE 8080 | |
ENTRYPOINT ["/var/www/html/docker/run.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment