11# !/usr/bin/env bash
22
3- # syntax = docker/dockerfile:experimental
3+ # syntax= docker/dockerfile:experimental
44
5- # Default to PHP 8.2, but we attempt to match
6- # the PHP version from the user (wherever `flyctl launch` is run)
7- # Valid version values are PHP 7.4+
85ARG PHP_VERSION=8.2
96ARG NODE_VERSION=18
10- FROM --platform=linux/amd64 mychidarko/leaf-fly-fpm:${PHP_VERSION} as base
7+ FROM ubuntu:22.04 as base
118LABEL fly_launch_runtime="leaf"
129
13- # PHP_VERSION needs to be repeated here
14- # See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
1510ARG PHP_VERSION
1611ENV DEBIAN_FRONTEND=noninteractive \
1712 COMPOSER_ALLOW_SUPERUSER=1 \
@@ -27,30 +22,20 @@ ENV DEBIAN_FRONTEND=noninteractive \
2722 PHP_MEMORY_LIMIT=256M \
2823 PHP_MAX_EXECUTION_TIME=90 \
2924 PHP_POST_MAX_SIZE=100M \
30- PHP_UPLOAD_MAX_FILE_SIZE=100M \
25+ PHP_UPLOAD_MAX_FILE_SIZE=500M \
3126 PHP_ALLOW_URL_FOPEN=Off
3227
33- # Prepare base container:
34- # 1. Install PHP, Composer
28+ # Install system packages
3529COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
3630COPY .fly/php/ondrej_ubuntu_php.gpg /etc/apt/trusted.gpg.d/ondrej_ubuntu_php.gpg
3731ADD .fly/php/packages/${PHP_VERSION}.txt /tmp/php-packages.txt
3832
39- RUN apt-get update
40- RUN apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip \
41- rsync vim-tiny htop sqlite3 nginx supervisor cron mysql-server postgresql postgresql-client \
42- libpq-dev libzip-dev libpng-dev libjpeg-dev libfreetype6-dev libxml2-dev
43-
44- RUN ln -sf /usr/bin/vim.tiny /etc/alternatives/vim \
45- && ln -sf /etc/alternatives/vim /usr/bin/vim
46-
47- RUN apt-get update && apt-get install -y wget gnupg && \
48- echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
49- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
50-
51- RUN apt-get update && apt-get install -y libpq-dev postgresql-client
52-
53- RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list \
33+ RUN apt-get update \
34+ && apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip \
35+ rsync vim-tiny htop sqlite3 nginx supervisor cron \
36+ && ln -sf /usr/bin/vim.tiny /etc/alternatives/vim \
37+ && ln -sf /etc/alternatives/vim /usr/bin/vim \
38+ && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list \
5439 && apt-get update \
5540 && apt-get -y --no-install-recommends install $(cat /tmp/php-packages.txt) \
5641 && ln -sf /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
@@ -66,77 +51,41 @@ COPY .fly/entrypoint.sh /entrypoint
6651COPY .fly/start-nginx.sh /usr/local/bin/start-nginx
6752RUN chmod 754 /usr/local/bin/start-nginx
6853
69- # copy application code, skipping files based on .dockerignore
54+ # 3. Copy application code, skipping files based on .dockerignore
7055COPY . /var/www/html
7156WORKDIR /var/www/html
7257
73- RUN composer install --optimize-autoloader --no-dev \
74- # && mkdir -p storage/logs \
75- && chown -R www-data:www-data /var/www/html \
76- # && sed -i 's/protected \$proxies/protected \$proxies = "*"/g' app/Http/Middleware/TrustProxies.php \
77- # && echo "MAILTO=\"\"\n* * * * * www-data /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel \
78- && cp .fly/entrypoint.sh /entrypoint \
79- && chmod +x /entrypoint \
80- && touch .env
81- # \
82- # && supervisorctl reread \
83- # && supervisorctl update \
84- # && supervisorctl start redis
58+ RUN composer install --optimize-autoloader --no-dev && \
59+ chown -R www-data:www-data /var/www/html && \
60+ chmod +x /entrypoint && touch .env; \
61+ if [ -d .fly ]; then cp .fly/entrypoint.sh /entrypoint; chmod +x /entrypoint; fi;
8562
86- # Multi-stage build: Build static assets
87- # This allows us to not include Node within the final container
63+ # Node asset builder
8864FROM node:${NODE_VERSION} as node_modules_go_brrr
8965
90- RUN mkdir /app
91-
92- RUN mkdir -p /app
66+ RUN mkdir -p /app
9367WORKDIR /app
9468COPY . .
9569COPY --from=base /var/www/html/vendor /app/vendor
9670
97- # Use yarn or npm depending on what type of
98- # lock file we might find. Defaults to
99- # NPM if no lock file is found.
10071RUN if [ -f "yarn.lock" ]; then \
101- yarn install --frozen-lockfile; \
102- yarn build; \
72+ yarn install --frozen-lockfile && yarn build; \
10373 elif [ -f "pnpm-lock.yaml" ]; then \
104- corepack enable && corepack prepare pnpm@latest-7 --activate; \
105- pnpm install --frozen-lockfile; \
106- pnpm run build; \
74+ corepack enable && corepack prepare pnpm@latest-7 --activate && \
75+ pnpm install --frozen-lockfile && pnpm run build; \
10776 elif [ -f "package-lock.json" ]; then \
108- npm ci --no-audit; \
109- npm run build; \
110- else \
111- # if no lock file is found, we check if we have a package.json
112- # and if so, we run npm install
113- if [ -f "package.json" ]; then \
114- npm install --force; \
115- npm run build; \
116- fi; \
117- fi;
77+ npm ci --no-audit && npm run build; \
78+ elif [ -f "package.json" ]; then \
79+ npm install --force && npm run build; \
80+ fi
11881
119- # From our base container created above, we
120- # create our final image, adding in static
121- # assets that we generated above
82+ # Final image
12283FROM base
123-
124- # Packages like Laravel Nova may have added assets to the public directory
125- # or maybe some custom assets were added manually! Either way, we merge
126- # in the assets we generated above rather than overwrite them
12784COPY --from=node_modules_go_brrr /app/public /var/www/html/public-npm
128- RUN rsync -ar /var/www/html/public-npm/ /var/www/html/public/ \
129- && rm -rf /var/www/html/public-npm \
130- && chown -R www-data:www-data /var/www/html/public \
131- # && php leaf db:migrate \
132- && php leaf link \
133- && rm -rf public/hot
134-
135- # RUN rm -rf /etc/nginx/sites-enabled/default
136- # RUN unlink /etc/nginx/sites-enabled/default
137-
138- # COPY --from=base /var/www/html/default /etc/nginx/sites-enabled/default
139- # RUN ln -s /var/www/html/default /etc/nginx/sites-enabled/
85+ RUN rsync -ar /var/www/html/public-npm/ /var/www/html/public/ && \
86+ rm -rf /var/www/html/public-npm && \
87+ chown -R www-data:www-data /var/www/html/public && \
88+ php leaf link && rm -rf public/hot
14089
14190EXPOSE 8080
14291
0 commit comments