Skip to content

Commit

Permalink
chore: setup install laravel octane package
Browse files Browse the repository at this point in the history
  • Loading branch information
muco-rolle committed Dec 6, 2024
1 parent c9139a0 commit f59ce0e
Show file tree
Hide file tree
Showing 31 changed files with 2,120 additions and 591 deletions.
1 change: 1 addition & 0 deletions .fly/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

88 changes: 44 additions & 44 deletions .fly/nginx/sites-available/default
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
server {
listen 8080 default_server;
listen [::]:8080 default_server;
listen 8080 default_server;
listen [::]:8080 default_server;

root /var/www/html/public;
root /var/www/html/public;

index index.html index.htm index.php;
index index.html index.htm index.php;

server_name _;
server_name _;

charset utf-8;
charset utf-8;

client_max_body_size 2048M;
client_max_body_size 2048M;

access_log /dev/stdout fly;
access_log /dev/stdout fly;

location / {
try_files $uri $uri/ /index.php?$query_string;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_X_FORWARDED_FOR $http_fly_client_ip;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param HTTP_X_FORWARDED_FOR $http_fly_client_ip;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}

location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}

location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
log_not_found off;
# Pass to PHP to ensure PHP apps can handle routes that end in these filetypes
try_files $uri /index.php?$query_string;
}
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
log_not_found off;
# Pass to PHP to ensure PHP apps can handle routes that end in these filetypes
try_files $uri /index.php?$query_string;
}

location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}

location ~ /\.(?!well-known) {
deny all;
}
location ~ /\.(?!well-known) {
deny all;
}

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
}
12 changes: 0 additions & 12 deletions .fly/scripts/caches.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#!/usr/bin/env bash

set -e # Exit immediately if a command exits with a non-zero status

echo "Caching config..."
/usr/bin/php /var/www/html/artisan config:cache --no-ansi -q

echo "Caching routes..."
/usr/bin/php /var/www/html/artisan route:cache --no-ansi -q

echo "Caching views..."
/usr/bin/php /var/www/html/artisan view:cache --no-ansi -q

echo "Running database migrations..."
/usr/bin/php /var/www/html/artisan migrate --force --no-ansi -q

echo "Deployment script completed successfully."
12 changes: 12 additions & 0 deletions .fly/supervisor/octane-swoole.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[program:octane]
priority=5
command=php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port=8000
user=www-data
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ yarn-error.log
/.zed
/database/backups/*.sql
debugbar

**/caddy
frankenphp
frankenphp-worker.php
21 changes: 13 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# syntax = docker/dockerfile:experimental

ARG PHP_VERSION=8.4
ARG NODE_VERSION=22.12
ARG PHP_VERSION=8.2
ARG NODE_VERSION=18
FROM ubuntu:22.04 as base
LABEL fly_launch_runtime="laravel"

# Re-define PHP_VERSION after FROM
# PHP_VERSION needs to be repeated here
# See https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION
ENV DEBIAN_FRONTEND=noninteractive \
COMPOSER_ALLOW_SUPERUSER=1 \
Expand All @@ -31,26 +32,27 @@ COPY .fly/php/ondrej_ubuntu_php.gpg /etc/apt/trusted.gpg.d/ondrej_ubuntu_php.gpg
ADD .fly/php/packages/${PHP_VERSION}.txt /tmp/php-packages.txt

RUN apt-get update \
&& apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip rsync vim-tiny htop sqlite3 nginx supervisor cron \
&& apt-get install -y --no-install-recommends gnupg2 ca-certificates git-core curl zip unzip \
rsync vim-tiny htop sqlite3 nginx supervisor cron \
&& ln -sf /usr/bin/vim.tiny /etc/alternatives/vim \
&& ln -sf /etc/alternatives/vim /usr/bin/vim \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-ubuntu-php.list \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list \
&& apt-get update \
&& apt-get -y --no-install-recommends install $(cat /tmp/php-packages.txt) \
&& ln -sf /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm \
&& mkdir -p /var/www/html/public && echo "index" > /var/www/html/public/index.php \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# 2. Copy config files
# 2. Copy config files to proper locations
COPY .fly/nginx/ /etc/nginx/
COPY .fly/fpm/ /etc/php/${PHP_VERSION}/fpm/
COPY .fly/supervisor/ /etc/supervisor/
COPY .fly/entrypoint.sh /entrypoint
COPY .fly/start-nginx.sh /usr/local/bin/start-nginx
RUN chmod 754 /usr/local/bin/start-nginx

# 3. Copy application code
# 3. Copy application code, skipping files based on .dockerignore
COPY . /var/www/html
WORKDIR /var/www/html

Expand All @@ -61,7 +63,7 @@ RUN composer install --optimize-autoloader --no-dev \
&& chown -R www-data:www-data /var/www/html \
&& echo "MAILTO=\"\"\n* * * * * www-data /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel \
&& sed -i='' '/->withMiddleware(function (Middleware \$middleware) {/a\
$middleware->trustProxies(at: "*");\
\$middleware->trustProxies(at: "*");\
' bootstrap/app.php; \
if [ -d .fly ]; then cp .fly/entrypoint.sh /entrypoint; chmod +x /entrypoint; fi;

Expand All @@ -71,6 +73,7 @@ RUN rm -rf /etc/supervisor/conf.d/fpm.conf; \
ln -sf /etc/nginx/sites-available/default-octane /etc/nginx/sites-enabled/default;



##############################################
# Multi-stage build: Use Bun for JS packages #
##############################################
Expand Down Expand Up @@ -109,5 +112,7 @@ RUN rsync -ar /var/www/html/public-bun/ /var/www/html/public/ \
&& rm -rf /var/www/html/public-bun \
&& chown -R www-data:www-data /var/www/html/public

# 5. Setup Entrypoint
EXPOSE 8080

ENTRYPOINT ["/entrypoint"]
Binary file modified bun.lockb
Binary file not shown.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"license": "MIT",
"require": {
"php": "^8.2",
"inertiajs/inertia-laravel": "^1.0",
"inertiajs/inertia-laravel": "2.x-dev",
"laravel/framework": "^11.9",
"laravel/octane": "^2.6",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"nunomaduro/laravel-optimize-database": "^1.0",
"pinkary-project/type-guard": "^0.1.0",
"resend/resend-laravel": "^0.14.0",
"spatie/laravel-data": "^4.10",
"spatie/laravel-data": "^4.11.1",
"spatie/laravel-typescript-transformer": "^2.5",
"tightenco/ziggy": "^2.0"
},
Expand All @@ -34,7 +35,8 @@
"nunomaduro/collision": "^8.1",
"pestphp/pest": "^3.4",
"pestphp/pest-plugin-laravel": "^3.0",
"spatie/laravel-error-solutions": "^1.0"
"spatie/laravel-error-solutions": "^1.0",
"swoole/ide-helper": "~5.0.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit f59ce0e

Please sign in to comment.