Skip to content

Modular logistics and supply chain operating system (LSOS)

configured and setup to run api using frankenphp/Caddyserver

Ronald A. Richardson6a68c85d944b
diff --git a/Caddyfile b/Caddyfile
new file mode 100644
index 00000000..f2ca916b
--- /dev/null
+++ b/Caddyfile
@@ -0,0 +1,18 @@
+{
+ # 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
+ encode zstd gzip
+ # Execute PHP files in the current directory and serve assets
+ php_server {
+ # Required for the public/storage/ dir
+ resolve_root_symlink
+ }
+}
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 255e766e..9d71baea 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -54,15 +54,4 @@ services:
LOG_CHANNEL: daily
depends_on:
- database
- - cache
-
- httpd:
- volumes:
- - ./api/storage:/var/www/html/api/storage
- build:
- context: .
- dockerfile: docker/httpd/Dockerfile
- ports:
- - "8000:80"
- depends_on:
- - application
\ No newline at end of file
+ - cache
\ No newline at end of file
diff --git a/docker/Dockerfile b/docker/Dockerfile
index cc461b20..e8a8006b 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,27 +1,23 @@
# syntax = docker/dockerfile:1.2
# Base stage
-FROM php:7.4-fpm-bullseye as base
-
-# Download and install GEOS PHP bindings
-RUN mkdir -p /usr/src/php/ext \
- && curl -L https://git.osgeo.org/gitea/geos/php-geos/archive/1.0.0.tar.gz > /tmp/php-geos.tar.gz \
- && tar -C /usr/src/php/ext -xzvf /tmp/php-geos.tar.gz
-
-# Install required packages and PHP extensions
-RUN apt-get update \
- && apt-get install -y nano git unzip libzip-dev libgd-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
- imagemagick libmagickwand-dev --no-install-recommends libmemcached-dev libgeos-dev libgmp-dev \
- default-mysql-client libicu-dev tmux nginx dnsutils mycli redis-tools \
- && pecl install imagick \
- && docker-php-ext-enable imagick \
- && docker-php-ext-configure gd --with-external-gd \
- && docker-php-ext-configure php-geos \
- && docker-php-ext-install -j$(nproc) gmp php-geos gd zip pdo_mysql sockets intl bcmath \
- && pecl install redis-4.3.0 memcached-3.1.3 \
- && docker-php-ext-enable redis memcached opcache bcmath
-
-# Clear cache
-RUN apt-get clean && rm -rf /var/lib/apt/lists/*
+FROM dunglas/frankenphp:sha-7454826-php8.2-alpine as base
+
+# Install PHP Extensions
+RUN install-php-extensions \
+ pdo_mysql \
+ gd \
+ bcmath \
+ redis \
+ intl \
+ zip \
+ gmp \
+ apcu \
+ opcache \
+ memcached \
+ imagick \
+ geos \
+ sockets \
+ @composer
# Update PHP configurations
RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production" > "$PHP_INI_DIR/php.ini" \
@@ -31,57 +27,46 @@ RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production"
# Install ssm-parent
COPY --from=ghcr.io/springload/ssm-parent:1.8 /usr/bin/ssm-parent /sbin/ssm-parent
-# Install Composer
-COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
-
# Set some build ENV variables
ENV LOG_CHANNEL=stdout
ENV CACHE_DRIVER=null
ENV BROADCAST_DRIVER=socketcluster
ENV QUEUE_CONNECTION=redis
-# For development only
-WORKDIR /var/www/html
-COPY --chown=www-data:nogroup ./packages ./packages
+# Set environment
+ARG ENVIRONMENT=production
+ENV APP_ENV=$ENVIRONMENT
-# Setup application
-WORKDIR /var/www/html/api
-COPY --chown=www-data:nogroup ./api ./
-RUN chown -R www-data:www-data /var/www/html/api
+# Copy Caddyfile
+COPY --chown=www-data:www-data ./Caddyfile /etc/caddy/Caddyfile
-# Setup composer root directory
-RUN mkdir -p /root/.composer
-RUN mkdir -p /var/www/.composer && chown www-data:www-data /var/www/.composer
+# Create /app directory and set correct permissions
+RUN mkdir -p /app && chown -R www-data:www-data /app
-# Setup logging
-RUN mkdir -p ./storage/logs/ && touch ./storage/logs/laravel-$(date +'%Y-%m-%d').log
-RUN chown -R www-data:www-data ./storage
-RUN chmod -R 755 ./storage
+# Set working directory
+WORKDIR /app
# Load the secret into the auth.json file if exists, and install dependencies
-COPY composer-auth.jso[n] /root/.composer/auth.json
-RUN --mount=type=secret,id=composer_auth,target=/root/.composer/auth.json \
- if [ -f "/root/.composer/auth.json" ]; then \
- mkdir -p /var/www/.composer/ && \
- cp /root/.composer/auth.json /var/www/.composer/auth.json && \
- chown www-data:www-data /var/www/.composer/auth.json && \
- su www-data -s /bin/sh -c "composer install && composer dumpautoload"; \
- fi; \
- su www-data -s /bin/sh -c "composer install && composer dumpautoload"
-
-# Continue
-USER root
-WORKDIR /
-
-# Create unique instance ID
-RUN echo $(cat /proc/sys/kernel/random/uuid) > /.fleetbase
+COPY composer-auth.jso[n] /app/auth.json
+RUN --mount=type=secret,id=composer_auth,target=/app/auth.json
-# Set environment
-ARG ENVIRONMENT=production
-ENV APP_ENV=$ENVIRONMENT
+# Optimize Composer Dependency Installation
+COPY --chown=www-data:www-data ./api/composer.json /app/
-# Set workdir to application
-WORKDIR /var/www/html/api
+# Pre-install Composer dependencies
+RUN su www-data -s /bin/sh -c "composer install --no-scripts --no-autoloader"
+
+# Setup application
+COPY --chown=www-data:www-data ./api /app
+
+# Setup composer root directory
+RUN mkdir -p /root/.composer
+RUN mkdir -p /app/.composer && chown www-data:www-data /app/.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
# Scheduler base stage
FROM base as scheduler-base
@@ -101,17 +86,22 @@ FROM scheduler-base as scheduler
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--"]
CMD ["go-crond", "--verbose", "--no-auto", "root:./crontab"]
-# Application dev stage
-FROM base as app-dev
-ENTRYPOINT ["docker-php-entrypoint"]
-CMD ["php-fpm"]
-
# Events stage
FROM base as events
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php", "artisan", "queue:work", "sqs"]
+CMD ["php", "artisan", "queue:work"]
+
+# Events stage
+FROM base as events-dev
+ENTRYPOINT []
+CMD ["php", "artisan", "queue:work"]
+
+# Application dev stage
+FROM base as app-dev
+ENTRYPOINT ["docker-php-entrypoint"]
+CMD ["frankenphp", "run"]
# Application stage
FROM base as app
ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php-fpm"]
\ No newline at end of file
+CMD ["frankenphp", "run"]
\ No newline at end of file
diff --git a/docker/Dockerfile-php8 b/docker/Dockerfile-php8
deleted file mode 100644
index 0f91a2b1..00000000
--- a/docker/Dockerfile-php8
+++ /dev/null
@@ -1,125 +0,0 @@
-# Build stage
-FROM php:8.2.4-fpm-alpine3.17 as build
-
-# download and install geos php bindings
-# need to run docker-php-ext-configure to create /usr/src/php/ext dir
-RUN mkdir -p /usr/src/php/ext && curl -L https://git.osgeo.org/gitea/geos/php-geos/archive/1.0.0.tar.gz > /tmp/php-geos.tar.gz && tar -C /usr/src/php/ext -xzvf /tmp/php-geos.tar.gz
-
-# Update package repositories
-RUN apk update
-
-# Install dependencies
-RUN apk add --no-cache autoconf g++ gcc make build-base linux-headers git unzip geos-dev libzip-dev libgd gd-dev libpng-dev imagemagick imagemagick-libs imagemagick-dev libmemcached-dev libmemcached-libs gmp-dev icu-dev icu icu-libs tmux
-
-# Install PHP extensions
-RUN docker-php-ext-install -j$(nproc) gmp gd zip pdo_mysql sockets intl
-RUN pecl install imagick redis-5.3.7 memcached-3.2.0
-RUN docker-php-ext-enable imagick redis memcached opcache
-RUN docker-php-ext-configure gd --enable-gd --with-external-gd
-RUN docker-php-ext-configure php-geos
-
-# Configure PHP ini settings
-RUN sed -e 's/^expose_php.*/expose_php = Off/' "$PHP_INI_DIR/php.ini-production" > "$PHP_INI_DIR/php.ini"
-RUN 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"
-
-# set recommended PHP.ini settings
-# see https://secure.php.net/manual/en/opcache.installation.php
-RUN { \
- echo 'opcache.memory_consumption=128'; \
- echo 'opcache.interned_strings_buffer=8'; \
- echo 'opcache.max_accelerated_files=4000'; \
- echo 'opcache.revalidate_freq=2'; \
- echo 'opcache.fast_shutdown=1'; \
- echo 'opcache.enable_cli=1'; \
- } > /usr/local/etc/php/conf.d/opcache-recommended.ini
-
-# Get springload ssm-parent
-RUN curl -L https://github.com/springload/ssm-parent/releases/download/v1.4.3/ssm-parent_1.4.3_linux_amd64.tar.gz > /tmp/ssm-parent.tar.gz && tar -C /sbin -xvf /tmp/ssm-parent.tar.gz ssm-parent && rm /tmp/ssm-parent.tar.gz
-
-# Install composer
-WORKDIR /var/www
-COPY docker/composer-install.sh ./
-RUN chmod +x ./composer-install.sh && ./composer-install.sh
-
-# Copy application files
-WORKDIR /var/www/html
-USER www-data
-COPY . .
-
-# Install dependencies
-RUN composer install --no-dev --no-scripts --no-autoloader --working-dir=/var/www/html/api
-COPY --chown=www-data:nogroup . ./
-RUN composer dumpautoload /var/www/html/api
-
-# Use root user
-USER root
-
-# Set environment variables
-ARG ENVIRONMENT=production
-ENV APP_ENV=$ENVIRONMENT
-
-# Final stage
-FROM php:8.2.4-fpm-alpine as final
-
-# Install dependencies
-RUN apk add --no-cache autoconf g++ gcc make build-base linux-headers git unzip geos-dev libzip-dev libgd gd-dev libpng-dev imagemagick imagemagick-libs imagemagick-dev libmemcached-dev libmemcached-libs gmp-dev icu-dev icu icu-libs tmux
-
-# Copy application files
-WORKDIR /var/www/html
-COPY --from=build /var/www/html .
-
-# Set ownership and permissions
-RUN chown -R www-data:www-data /var/www/html \
- && chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
-
-# Set entrypoint and command
-ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php-fpm"]
-
-# Scheduler stages
-FROM alpine:3.14 as scheduler
-
-RUN apk add --no-cache curl
-
-# Install go-crond
-RUN curl -L https://github.com/webdevops/go-crond/releases/download/0.6.1/go-crond-64-linux-dynamic > /usr/local/bin/go-crond \
- && chmod +x /usr/local/bin/go-crond
-
-# Copy application files
-WORKDIR /var/www/html
-COPY --chown=www-data:nogroup . ./
-
-# Copy crontab file and set permissions
-COPY --chown=www-data:nogroup docker/crontab ./crontab
-RUN chmod 0600 ./crontab
-
-# Set ownership and permissions
-RUN chown -R www-data:www-data /var/www/html
-
-# Set entrypoint and command
-ENTRYPOINT []
-CMD ["go-crond", "--verbose", "--no-auto", "root:./crontab"]
-
-# Application stages
-FROM final as app-dev
-
-# Set entrypoint and command
-ENTRYPOINT ["docker-php-entrypoint"]
-CMD ["php-fpm"]
-
-# Application stage
-FROM final as app
-ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php-fpm"]
-
-FROM final as events
-
-# Set entrypoint and command
-ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php", "api/artisan", "queue:work", "events"]
-
-FROM final as jobs
-
-# Set entrypoint and command
-ENTRYPOINT ["/sbin/ssm-parent", "-c", ".ssm-parent.yaml", "run", "--", "docker-php-entrypoint"]
-CMD ["php", "api/artisan", "queue:work", "sqs"]
\ No newline at end of file
diff --git a/docker/composer-install.sh b/docker/composer-install.sh
deleted file mode 100644
index 24c007eb..00000000
--- a/docker/composer-install.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-EXPECTED_SIGNATURE="$(curl https://composer.github.io/installer.sig)"
-php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
-ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
-
-if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
-then
- >&2 echo 'ERROR: Invalid installer signature'
- rm composer-setup.php
- exit 1
-fi
-
-php composer-setup.php --install-dir=/usr/bin/ --filename=composer
-RESULT=$?
-rm composer-setup.php
-exit $RESULT
diff --git a/docker/httpd/Dockerfile b/docker/httpd/Dockerfile
deleted file mode 100644
index 3aa9424c..00000000
--- a/docker/httpd/Dockerfile
+++ /dev/null
@@ -1,7 +0,0 @@
-# alpine is more secure
-FROM nginx:stable-alpine
-
-ENV NGINX_APPLICATION_HOSTNAME application
-
-COPY docker/httpd/vhost.conf /etc/nginx/templates/default.conf.template
-COPY api/public/ /var/www/html/api/public/
diff --git a/docker/httpd/vhost.conf b/docker/httpd/vhost.conf
deleted file mode 100644
index 561c66e4..00000000
--- a/docker/httpd/vhost.conf
+++ /dev/null
@@ -1,45 +0,0 @@
-server {
- listen 80;
- server_name localhost;
- root /var/www/html/api/public;
- # hide nginx version for security purposes
- server_tokens off;
- access_log /var/log/nginx/access.log;
- error_log /var/log/nginx/error_log;
- proxy_connect_timeout 600;
- proxy_send_timeout 600;
- proxy_read_timeout 600;
- send_timeout 600;
- index index.php;
-
- location / {
- try_files $uri $uri/ /index.php?$args;
- }
-
- location /uploads {
- alias /var/www/html/api/storage/app/uploads;
- autoindex on;
- try_files $uri $uri/ /index.php?$query_string;
- }
-
- location /storage {
- alias /var/www/html/api/storage/app/public;
- autoindex on;
- try_files $uri $uri/ /index.php?$query_string;
- }
-
- location ~ [^/]\.php(/|$) {
- fastcgi_split_path_info ^(.+?\.php)(/.*)$;
- if (!-f $document_root$fastcgi_script_name) {
- return 404;
- }
-
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param PATH_INFO $fastcgi_path_info;
- fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
-
- fastcgi_pass ${NGINX_APPLICATION_HOSTNAME}:9000;
- fastcgi_index index.php;
- }
-}
diff --git a/docker/laravel.conf b/docker/laravel.conf
deleted file mode 100644
index 33de346b..00000000
--- a/docker/laravel.conf
+++ /dev/null
@@ -1,14 +0,0 @@
-<VirtualHost *:80>
- ServerAdmin webmaster@localhost
- DocumentRoot /var/www/html/api/public
-
- <Directory /var/www/html/api/public>
- AllowOverride All
- </Directory>
-
- ErrorLog ${APACHE_LOG_DIR}/error.log
- CustomLog ${APACHE_LOG_DIR}/access.log combined
-
-</VirtualHost>
-
-# vim: syntax=apache ts=4 sw=4 sts=4 sr noet