feat(deploy): add docker app+mysql stack for coolify

This commit is contained in:
Dwindi Ramadhana
2026-02-04 21:05:59 +07:00
parent 0c45435db9
commit 0d5e1a4aa1
6 changed files with 182 additions and 0 deletions

12
app/.dockerignore Normal file
View File

@@ -0,0 +1,12 @@
.git
.gitignore
.env
.env.*
node_modules
vendor
tests
storage/logs/*
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
coverage

51
app/Dockerfile Normal file
View File

@@ -0,0 +1,51 @@
# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS frontend
WORKDIR /var/www/html
COPY package.json ./
RUN npm install
COPY resources ./resources
COPY public ./public
COPY vite.config.js ./
RUN npm run build
FROM composer:2 AS vendor
WORKDIR /var/www/html
COPY composer.json composer.lock ./
RUN composer install \
--no-dev \
--no-interaction \
--no-progress \
--prefer-dist \
--optimize-autoloader
FROM php:8.2-apache
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
libzip-dev \
libicu-dev \
unzip \
curl \
default-mysql-client \
&& docker-php-ext-install pdo_mysql bcmath exif intl zip \
&& a2enmod rewrite headers expires \
&& rm -rf /var/lib/apt/lists/*
COPY . .
COPY --from=vendor /var/www/html/vendor ./vendor
COPY --from=frontend /var/www/html/public/build ./public/build
COPY docker/apache-vhost.conf /etc/apache2/sites-available/000-default.conf
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh \
&& chown -R www-data:www-data storage bootstrap/cache \
&& chmod -R ug+rwx storage bootstrap/cache
EXPOSE 80
ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]

View File

@@ -0,0 +1,12 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

27
app/docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env sh
set -eu
cd /var/www/html
php artisan config:clear >/dev/null 2>&1 || true
if [ "${DB_CONNECTION:-}" = "mysql" ] && [ "${WAIT_FOR_DB:-true}" = "true" ]; then
echo "Waiting for MySQL at ${DB_HOST:-mysql}:${DB_PORT:-3306}..."
i=0
while [ "$i" -lt 60 ]; do
if php -r 'try { new PDO("mysql:host=".getenv("DB_HOST").";port=".getenv("DB_PORT").";dbname=".getenv("DB_DATABASE"), getenv("DB_USERNAME"), getenv("DB_PASSWORD"), [PDO::ATTR_TIMEOUT => 3]); exit(0);} catch (Throwable $e) { exit(1);}'; then
echo "MySQL is reachable."
break
fi
i=$((i + 1))
sleep 2
done
fi
if [ "${RUN_MIGRATIONS:-true}" = "true" ]; then
php artisan migrate --force
fi
php artisan storage:link >/dev/null 2>&1 || true
exec "$@"