From 8e1346844d32968c8f43f3940f30a82cc52d93de Mon Sep 17 00:00:00 2001 From: Valentin Sickert <17144397+Lapotor@users.noreply.github.com> Date: Sun, 26 Nov 2023 01:18:31 +0100 Subject: [PATCH] feat: add docker build Signed-off-by: Valentin Sickert <17144397+Lapotor@users.noreply.github.com> --- .docker/apache/vhost.conf | 14 +++++++++++ .docker/entrypoint.sh | 12 +++++++++ .docker/php/conf.d/opcache.ini | 9 +++++++ .dockerignore | 11 ++++++++ .editorconfig | 3 +++ Dockerfile | 46 ++++++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 .docker/apache/vhost.conf create mode 100644 .docker/entrypoint.sh create mode 100644 .docker/php/conf.d/opcache.ini create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.docker/apache/vhost.conf b/.docker/apache/vhost.conf new file mode 100644 index 00000000..c6e747e8 --- /dev/null +++ b/.docker/apache/vhost.conf @@ -0,0 +1,14 @@ + + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html/public/ + + + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100644 index 00000000..d23857b2 --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e; # Exit immediately if a command exits with a non-zero status. + +if [ "$APP_ENV" = "production" ]; then + /usr/local/bin/php /var/www/html/artisan migrate --force; +else + /usr/local/bin/php /var/www/html/artisan migrate; +fi + +/usr/local/bin/php /var/www/html/artisan optimize; + +exec apache2-foreground; diff --git a/.docker/php/conf.d/opcache.ini b/.docker/php/conf.d/opcache.ini new file mode 100644 index 00000000..88cb7ce9 --- /dev/null +++ b/.docker/php/conf.d/opcache.ini @@ -0,0 +1,9 @@ +[opcache] +opcache.enable=1 +opcache.revalidate_freq=0 +opcache.validate_timestamps=0 +opcache.max_accelerated_files=10000 +opcache.memory_consumption=192 +opcache.max_wasted_percentage=10 +opcache.interned_strings_buffer=16 +opcache.jit_buffer_size=100M diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..acd64dcf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.env +.idea +.vscode +node_modules +vendor +storage/framework/cache/** +storage/framework/sessions/** +storage/framework/testing/** +storage/framework/views/** +storage/logs/** diff --git a/.editorconfig b/.editorconfig index 1a59eae8..1482b612 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ indent_size = 2 [docker-compose.yml] indent_size = 4 + +[*.sh] +end_of_line = lf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7b3b8a66 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# Stage 1: Build +FROM composer:lts as build + +WORKDIR /app + +COPY . /app/ + +# Install dependencies +RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction --no-progress + +# Stage 2: Production +FROM php:8.1-apache as production + +ENV APP_ENV=production +ENV APP_DEBUG=false + +# Install Postgres driver +RUN apt-get update && \ + apt-get install -y libpq-dev + +# Install PHP extensions +RUN docker-php-ext-configure opcache --enable-opcache && \ + docker-php-ext-install pdo pdo_mysql pdo_pgsql + +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +# Copy opcache config +COPY .docker/php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini + +# Copy application +COPY --from=build /app /var/www/html + +# Copy apache config +COPY .docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf + +# Copy entrypoint +COPY .docker/entrypoint.sh /entrypoint.sh + +# Copy configure script +RUN chown -R www-data:www-data /var/www/ && \ + a2enmod rewrite + +EXPOSE 80 + +# Run Entrypoint +ENTRYPOINT [ "/entrypoint.sh" ]