Fullstack docker image

This commit is contained in:
Ronald A. Richardson
2025-05-01 08:55:26 +08:00
parent 313b5ea3ba
commit 62a69b2dcc
2 changed files with 201 additions and 0 deletions

154
docker/Dockerfile.fullstack Normal file
View File

@@ -0,0 +1,154 @@
# syntax = docker/dockerfile:1.2
# Base stage
FROM dunglas/frankenphp:1.5.0-php8.2-bookworm AS base
# Install packages
RUN apt-get update && apt-get install -y git bind9-utils mycli nodejs npm nano mariadb-server redis-server \
&& mkdir -p /root/.ssh \
&& ssh-keyscan github.com >> /root/.ssh/known_hosts
# Install PHP Extensions
RUN install-php-extensions \
pdo_mysql \
gd \
bcmath \
redis \
intl \
zip \
gmp \
apcu \
opcache \
memcached \
imagick \
# geos \
sockets \
pcntl \
@composer
# Install build dependencies for GEOS
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
pkg-config \
libgeos-dev \
libgeos++-dev \
autoconf \
build-essential \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Download, extract, compile, and enable the php-geos extension
RUN curl -fsSL -o php-geos.zip \
https://github.com/libgeos/php-geos/archive/dfe1ab17b0f155cc315bc13c75689371676e02e1.zip \
&& unzip php-geos.zip \
&& rm php-geos.zip \
&& cd php-geos-* \
&& ./autogen.sh \
&& ./configure \
&& make -j"$(nproc)" install \
&& docker-php-ext-enable geos \
&& cd .. \
&& rm -rf php-geos-*
# Update PHP configurations
RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production" > "$PHP_INI_DIR/php.ini" \
&& sed -i -e 's/^upload_max_filesize.*/upload_max_filesize = 600M/' -e 's/^post_max_size.*/post_max_size = 0/' \
-e 's/^memory_limit.*/memory_limit = 600M/' "$PHP_INI_DIR/php.ini"
# Install global node modules
RUN npm install -g chokidar pnpm socketcluster ember-cli npm-cli-login
# Create application directory
RUN mkdir -p /fleetbase
# Setup Console
COPY --chown=www-data:www-data ./console /fleetbase/console
WORKDIR /fleetbase/console
RUN pnpm install && pnpm build
# Setup SocketCluster
RUN socketcluster create /fleetbase/socketcluster
# Install ssm-parent
COPY --from=ghcr.io/springload/ssm-parent:1.8 /usr/bin/ssm-parent /sbin/ssm-parent
# Create the pnpm directory and set the PNPM_HOME environment variable
RUN mkdir -p ~/.pnpm
ENV PNPM_HOME=/root/.pnpm
# Add the pnpm global bin to the PATH
ENV PATH=/root/.pnpm/bin:$PATH
# Set some build ENV variables
ENV LOG_CHANNEL=stdout
ENV CACHE_DRIVER=null
ENV BROADCAST_DRIVER=socketcluster
ENV QUEUE_CONNECTION=redis
ENV CADDYFILE_PATH=/fleetbase/Caddyfile
ENV CONSOLE_PATH=/fleetbase/console
ENV OCTANE_SERVER=frankenphp
ENV DB_CONNECTION=mysql
ENV DB_HOST=127.0.0.1
ENV DB_PORT=3306
ENV DB_DATABASE=fleetbase
ENV DB_USERNAME=root
ENV DB_PASSWORD=secret
ENV REDIS_HOST=127.0.0.1
ENV REDIS_PORT=6379
ENV REDIS_CLIENT=phpredis
# Set environment
ARG ENVIRONMENT=production
ENV APP_ENV=$ENVIRONMENT
# Setup github auth
ARG GITHUB_AUTH_KEY
# Copy Caddyfile
COPY --chown=www-data:www-data ./Caddyfile $CADDYFILE_PATH
# Create /fleetbase directory and set correct permissions
RUN mkdir -p /fleetbase/api && mkdir -p /fleetbase/console && chown -R www-data:www-data /fleetbase
# Set working directory
WORKDIR /fleetbase/api
# Prepare composer cache directory
RUN mkdir -p /var/www/.cache/composer && chown -R www-data:www-data /var/www/.cache/composer
# Optimize Composer Dependency Installation
COPY --chown=www-data:www-data ./api/composer.json ./api/composer.lock /fleetbase/api/
# Pre-install Composer dependencies
RUN su www-data -s /bin/sh -c "composer install --no-scripts --optimize-autoloader --no-dev --no-cache"
# Setup application
COPY --chown=www-data:www-data ./api /fleetbase/api
# Dump autoload
RUN su www-data -s /bin/sh -c "composer dumpautoload"
# Setup composer root directory
RUN mkdir -p /root/.composer
RUN mkdir -p /fleetbase/api/.composer && chown www-data:www-data /fleetbase/api/.composer
# Setup logging
RUN mkdir -p /fleetbase/api/storage/logs/ && touch /fleetbase/api/storage/logs/laravel-$(date +'%Y-%m-%d').log
RUN chown -R www-data:www-data /fleetbase/api/storage
RUN chmod -R 755 /fleetbase/api/storage
# Set permissions and run deploy script
RUN chmod +x /fleetbase/api/deploy.sh
# RUN sh ./fleetbase/api/deploy.sh
# Install go-crond
RUN curl -L https://github.com/webdevops/go-crond/releases/download/23.12.0/go-crond.linux.amd64 > /usr/local/bin/go-crond && chmod +x /usr/local/bin/go-crond
COPY docker/crontab ./crontab
RUN chmod 0600 ./crontab
# Expose ports
EXPOSE 8000 4200 3800 3306 6379
# Execute
COPY ./docker/fullstack-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -e
echo "🚀 Fleetbase Fullstack Container Starting..."
# Graceful shutdown handler
trap 'echo "🛑 Caught termination signal, shutting down..."; kill $(jobs -p); wait' SIGTERM SIGINT
echo "🔧 Starting MySQL service..."
service mysql start
echo "🗄️ Configuring MySQL database and user..."
mysql --user=root <<-EOSQL
CREATE DATABASE IF NOT EXISTS fleetbase;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret';
FLUSH PRIVILEGES;
EOSQL
echo "🧠 Waiting for MySQL to become ready..."
until mysqladmin ping --silent; do
echo "⏳ Waiting for MySQL..."
sleep 1
done
echo "✅ MySQL is ready."
echo "🔧 Starting Redis service..."
service redis-server start
echo "🧠 Waiting for Redis to become ready..."
until redis-cli ping | grep -q PONG; do
echo "⏳ Waiting for Redis..."
sleep 1
done
echo "✅ Redis is ready."
echo "📡 Launching SocketCluster on port 3800..."
node /fleetbase/socketcluster/index.js &
echo "🖥️ Serving Ember frontend on port 4200..."
npx serve -l 4200 /fleetbase/console/dist &
echo "📦 Running Fleetbase deploy script..."
sh /fleetbase/api/deploy.sh
echo "🧬 Starting Laravel API (FrankenPHP Octane) on port 8000..."
cd /fleetbase/api
exec php artisan octane:frankenphp --port=8000 --host=0.0.0.0