diff --git a/Dockerfile b/Dockerfile index 3fd39a7..dde9798 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,62 +1,49 @@ -FROM php:8.3-fpm +# Build stage +FROM node:18-alpine AS node-builder -# build arguments -ARG APP_URL http://localhost +WORKDIR /app -# Update to Debian Trixie -RUN cat <> /etc/apt/sources.list - deb http://deb.debian.org/debian trixie main contrib non-free - deb http://deb.debian.org/debian trixie-updates main contrib non-free - deb http://security.debian.org/debian-security trixie-security main contrib non-free -EOF +COPY . . +RUN npm run build -# Install system dependencies -RUN apt-get update && \ - apt-get upgrade -y +# PHP stage +FROM php:8.3-fpm-alpine -# Install apps -RUN apt-get install -y --no-install-recommends \ +# Install system packages +RUN apk add --no-cache \ nginx \ - rsyslog \ supervisor \ curl \ - wget \ npm \ nano \ cmake \ - gettext \ - unzip + gettext -# Install PHP dependencies -RUN apt-get install -y --no-install-recommends \ +# Install PHP modules +RUN apk add --no-cache --virtual .build-deps \ libzip-dev \ - libfreetype6=2.12.1+dfsg-5+deb12u3 \ - libfreetype-dev=2.12.1+dfsg-5+deb12u3 \ + freetype-dev \ libpng-dev \ - libjpeg62-turbo-dev \ + libjpeg-turbo-dev \ libwebp-dev \ - libmcrypt-dev \ - libbz2-dev \ - libcurl4-openssl-dev \ - libtidy-dev \ + bzip2-dev \ + curl-dev \ + tidyhtml-dev \ libxslt-dev \ - libonig-dev \ - libc-client-dev \ - libpq-dev \ - libkrb5-dev \ - libsqlite3-dev \ - freetds-dev \ - freetds-bin - -# Cleanup APT -RUN rm -rf \ - /var/lib/apt/lists/* \ - /usr/share/man/* \ - /usr/share/doc/* \ - /etc/nginx/sites-enabled - -# Install PHP extensions -RUN docker-php-ext-install \ + oniguruma-dev \ + postgresql-dev \ + sqlite-dev \ + libzip \ + freetype \ + libpng \ + libjpeg-turbo \ + libwebp \ + bzip2 \ + libxslt \ + oniguruma \ + sqlite-libs \ + && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ + && docker-php-ext-install -j$(nproc) \ mbstring \ xml \ dom \ @@ -66,7 +53,8 @@ RUN docker-php-ext-install \ curl \ calendar \ pdo_sqlite \ - bcmath + bcmath \ + && apk del .build-deps # Configure php-fpm RUN sed -i 's/listen = 127.0.0.1:9000/listen = \/run\/php\/php-fpm.sock/' /usr/local/etc/php-fpm.d/www.conf \ @@ -77,27 +65,23 @@ RUN sed -i 's/listen = 127.0.0.1:9000/listen = \/run\/php\/php-fpm.sock/' /usr/l && sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/' /usr/local/etc/php/php.ini \ && sed -i 's/post_max_size = 8M/post_max_size = 200M/' /usr/local/etc/php/php.ini -# Install Node.js -RUN npm install -g n && n 18 - -# Apply configs +# Copy configurations COPY ./docker/conf/etc /etc -# Configure project -WORKDIR /tmp +# Copy built application from node stage +COPY --from=node-builder /app/dist /var/www/html +COPY --from=node-builder /app/api /var/www/html/api -# Install project -COPY . . +# Set permissions +RUN chown -R www-data:www-data /var/www/html -RUN npm install \ - && npm run build \ - && chown www-data:www-data . -R \ - && rm -r /var/www/html/* \ - && mv /tmp/dist/* /tmp/api /var/www/html \ - && rm -r /tmp/* - -WORKDIR /var/www/html +# Create system dirs +RUN mkdir -p /var/run && \ + mkdir -p /run/php +# Copy and set entrypoint COPY ./entrypoint.sh / -CMD ["/bin/bash", "/entrypoint.sh"] +CMD ["/bin/sh", "/entrypoint.sh"] + +EXPOSE 80 \ No newline at end of file diff --git a/docker/conf/etc/nginx/sites-enabled/default.conf b/docker/conf/etc/nginx/http.d/default.conf similarity index 100% rename from docker/conf/etc/nginx/sites-enabled/default.conf rename to docker/conf/etc/nginx/http.d/default.conf diff --git a/docker/conf/etc/supervisor/supervisord.conf b/docker/conf/etc/supervisor/supervisord.conf index ea4c1e5..969e272 100644 --- a/docker/conf/etc/supervisor/supervisord.conf +++ b/docker/conf/etc/supervisor/supervisord.conf @@ -1,20 +1,12 @@ [supervisord] -logfile=/var/log/supervisord.log -logfile_maxbytes=50MB -childlogdir=/var/log -pidfile=/var/run/supervisord.pid nodaemon=true user=root +logfile=/dev/stdout +logfile_maxbytes=0 +pidfile=/var/run/supervisord.pid [supervisorctl] -[program:misc-rsyslog] -command=/usr/sbin/rsyslogd -n -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/%(program_name)s.log -stderr_logfile=/var/log/supervisor/%(program_name)s.log - [group:webserver] programs=webserver-nginx,webserver-phpfpm @@ -22,8 +14,16 @@ programs=webserver-nginx,webserver-phpfpm command=/usr/sbin/nginx -g 'daemon off;' autostart=true autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 [program:webserver-phpfpm] command=/usr/local/sbin/php-fpm --nodaemonize --fpm-config /usr/local/etc/php-fpm.d/www.conf autostart=true autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 \ No newline at end of file