working with laravel octane

This commit is contained in:
Ronald A. Richardson
2024-01-30 20:07:22 +08:00
parent 6a68c85d94
commit 8628695b0b
4 changed files with 42 additions and 26 deletions

View File

@@ -1,18 +1,12 @@
{
# Enable FrankenPHP
frankenphp
# Configure when the directive must be executed
order php_server before file_server
}
http://localhost:8080 {
# Set the webroot to the public/ dir
root * /app/public
# Enable compression
http://localhost:8000 {
root * /fleetbase/api/public
encode zstd gzip
# Execute PHP files in the current directory and serve assets
php_server {
# Required for the public/storage/ dir
resolve_root_symlink
}
}
}

5
api/.gitignore vendored
View File

@@ -13,4 +13,7 @@ npm-debug.log
yarn-error.log
/.idea
/.vscode
.composer.dev.json
.composer.dev.json
/caddy
frankenphp
frankenphp-worker.php

View File

@@ -16,7 +16,7 @@ class Kernel extends HttpKernel
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,

View File

@@ -2,6 +2,11 @@
# Base stage
FROM dunglas/frankenphp:sha-7454826-php8.2-alpine as base
# Install packages
RUN apk update && apk add git openssh bind-tools mycli nodejs npm \
&& mkdir -p /root/.ssh \
&& ssh-keyscan github.com >> /root/.ssh/known_hosts
# Install PHP Extensions
RUN install-php-extensions \
pdo_mysql \
@@ -17,6 +22,7 @@ RUN install-php-extensions \
imagick \
geos \
sockets \
pcntl \
@composer
# Update PHP configurations
@@ -24,6 +30,9 @@ RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production"
&& 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
# Install ssm-parent
COPY --from=ghcr.io/springload/ssm-parent:1.8 /usr/bin/ssm-parent /sbin/ssm-parent
@@ -32,41 +41,48 @@ ENV LOG_CHANNEL=stdout
ENV CACHE_DRIVER=null
ENV BROADCAST_DRIVER=socketcluster
ENV QUEUE_CONNECTION=redis
ENV CADDYFILE_PATH=/fleetbase/Caddyfile
ENV OCTANE_SERVER=frankenphp
# Set environment
ARG ENVIRONMENT=production
ENV APP_ENV=$ENVIRONMENT
# Copy Caddyfile
COPY --chown=www-data:www-data ./Caddyfile /etc/caddy/Caddyfile
COPY --chown=www-data:www-data ./Caddyfile $CADDYFILE_PATH
# Create /app directory and set correct permissions
RUN mkdir -p /app && chown -R www-data:www-data /app
# Create /fleetbase directory and set correct permissions
RUN mkdir -p /fleetbase/api && chown -R www-data:www-data /fleetbase
# Copy packages
COPY --chown=www-data:www-data ./packages/core-api /fleetbase/packages/core-api
COPY --chown=www-data:www-data ./packages/fleetops /fleetbase/packages/fleetops
COPY --chown=www-data:www-data ./packages/storefront /fleetbase/packages/storefront
# Set working directory
WORKDIR /app
WORKDIR /fleetbase/api
# Load the secret into the auth.json file if exists, and install dependencies
COPY composer-auth.jso[n] /app/auth.json
RUN --mount=type=secret,id=composer_auth,target=/app/auth.json
COPY composer-auth.jso[n] /fleetbase/api/auth.json
RUN --mount=type=secret,id=composer_auth,target=/fleetbase/api/auth.json
# Optimize Composer Dependency Installation
COPY --chown=www-data:www-data ./api/composer.json /app/
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 --no-autoloader"
RUN su www-data -s /bin/sh -c "composer install --no-scripts --no-autoloader --optimize-autoloader --no-dev"
# Setup application
COPY --chown=www-data:www-data ./api /app
COPY --chown=www-data:www-data ./api /fleetbase/api
# Setup composer root directory
RUN mkdir -p /root/.composer
RUN mkdir -p /app/.composer && chown www-data:www-data /app/.composer
RUN mkdir -p /fleetbase/api/.composer && chown www-data:www-data /fleetbase/api/.composer
# Setup logging
RUN mkdir -p /app/storage/logs/ && touch /app/storage/logs/laravel-$(date +'%Y-%m-%d').log
RUN chown -R www-data:www-data /app/storage
RUN chmod -R 755 /app/storage
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
# Scheduler base stage
FROM base as scheduler-base
@@ -99,9 +115,12 @@ CMD ["php", "artisan", "queue:work"]
# Application dev stage
FROM base as app-dev
ENTRYPOINT ["docker-php-entrypoint"]
CMD ["frankenphp", "run"]
# add --watch flag later
CMD ["sh", "-c", "php artisan octane:frankenphp --port=8000 --host=0.0.0.0 --caddyfile $CADDYFILE_PATH"]
# CMD ["sh", "-c", "frankenphp run --config $CADDYFILE_PATH"]
# Application stage
FROM base as app
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
CMD ["frankenphp", "run"]
CMD ["sh", "-c", "php artisan octane:frankenphp --port=8000 --host=0.0.0.0 --https --http-redirect --caddyfile $CADDYFILE_PATH"]
# CMD ["sh", "-c", "frankenphp run --config $CADDYFILE_PATH"]