Skip to content

Commit

Permalink
feat: add docker build
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Sickert <[email protected]>
  • Loading branch information
Lapotor committed Nov 26, 2023
1 parent 1cfa3b5 commit 8e13468
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .docker/apache/vhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<VirtualHost *:80>

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public/

<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
12 changes: 12 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions .docker/php/conf.d/opcache.ini
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/**
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ indent_size = 2

[docker-compose.yml]
indent_size = 4

[*.sh]
end_of_line = lf
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]

0 comments on commit 8e13468

Please sign in to comment.