fix: ensure permissions are set and storage dir is scaffolded
This commit is contained in:
+1
-1
@@ -13,4 +13,4 @@ storage/framework/cache/*
|
|||||||
storage/framework/sessions/*
|
storage/framework/sessions/*
|
||||||
storage/framework/testing/*
|
storage/framework/testing/*
|
||||||
storage/framework/views/*
|
storage/framework/views/*
|
||||||
storage/framework/logs/*
|
storage/logs/*
|
||||||
+9
-10
@@ -3,8 +3,6 @@ FROM php:8.3-fpm
|
|||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
ENV APP_NAME=Investbrain
|
ENV APP_NAME=Investbrain
|
||||||
ENV VITE_APP_NAME=Investbrain
|
ENV VITE_APP_NAME=Investbrain
|
||||||
ENV APP_DEBUG=true
|
|
||||||
ENV SELF_HOSTED=true
|
|
||||||
|
|
||||||
# Set the working directory
|
# Set the working directory
|
||||||
COPY . /var/app
|
COPY . /var/app
|
||||||
@@ -39,21 +37,23 @@ RUN rm /etc/nginx/sites-enabled/default \
|
|||||||
&& rm -rf /var/www/html \
|
&& rm -rf /var/www/html \
|
||||||
&& ln -s /var/app /var/www/app
|
&& ln -s /var/app /var/www/app
|
||||||
|
|
||||||
# Set permissions and ensure www-data has a shell available
|
|
||||||
RUN chown -R www-data:www-data . \
|
|
||||||
&& chmod -R 775 ./storage \
|
|
||||||
&& chmod +x ./docker/entrypoint.sh \
|
|
||||||
&& usermod -s /bin/bash www-data
|
|
||||||
|
|
||||||
# Install Composer and Node.js Install PHP dependencies and build front end assets
|
# Install Composer and Node.js Install PHP dependencies and build front end assets
|
||||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
|
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
|
||||||
&& composer install --no-scripts --optimize-autoloader \
|
&& composer install --no-scripts --optimize-autoloader \
|
||||||
&& npm install && npm run build
|
&& npm install && npm run build \
|
||||||
|
&& rm -rf node_modules
|
||||||
|
|
||||||
# Copy over configs
|
# Copy over configs
|
||||||
COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf
|
COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
|
||||||
|
# Set permissions and ensure www-data has a shell available
|
||||||
|
RUN chown -R www-data:www-data . \
|
||||||
|
&& chmod -R 775 ./storage \
|
||||||
|
&& chmod +x ./docker/entrypoint.sh
|
||||||
|
|
||||||
|
# && usermod -s /bin/bash www-data
|
||||||
|
|
||||||
# Serve on port 80
|
# Serve on port 80
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
@@ -62,4 +62,3 @@ HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD curl -f http://localhos
|
|||||||
|
|
||||||
# Run everything else
|
# Run everything else
|
||||||
ENTRYPOINT ["/bin/bash", "./docker/entrypoint.sh"]
|
ENTRYPOINT ["/bin/bash", "./docker/entrypoint.sh"]
|
||||||
|
|
||||||
|
|||||||
+40
-20
@@ -2,25 +2,32 @@
|
|||||||
|
|
||||||
cd /var/app
|
cd /var/app
|
||||||
|
|
||||||
echo -e "\n====================== Validating environment... ====================== "
|
# Starting Investbrain
|
||||||
for dir in storage/framework/cache storage/framework/sessions storage/framework/views; do
|
echo "CiAgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICAqICBJSUkgICBOICAgTiAgViAgIFYgIEVFRUVFICBTU1NTICBUVFRUVCAgQkJCQkIgICBSUlJSICAgIEFBQUFBICBJSUkgICBOICAgTiAgKgogICogICBJICAgIE5OICBOICBWICAgViAgRSAgICAgIFMgICAgICAgVCAgICBCICAgIEIgIFIgICBSICAgQSAgIEEgICBJICAgIE5OICBOICAqCiAgKiAgIEkgICAgTiBOIE4gIFYgICBWICBFRUVFICAgU1NTUyAgICBUICAgIEJCQkJCICAgUlJSUiAgICBBQUFBQSAgIEkgICAgTiBOIE4gICoKICAqICAgSSAgICBOICBOTiAgViAgIFYgIEUgICAgICAgICAgUyAgIFQgICAgQiAgICBCICBSICBSICAgIEEgICBBICAgSSAgICBOICBOTiAgKgogICogIElJSSAgIE4gICBOICAgVlZWICAgRUVFRUUgIFNTU1MgICAgVCAgICBCQkJCQiAgIFIgICBSICAgQSAgIEEgIElJSSAgIE4gICBOICAqCiAgKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICA=" | base64 -d
|
||||||
if [ ! -d "$dir" ]; then
|
|
||||||
echo -e "\n > $dir is missing. Creating scaffold for storage directory... "
|
|
||||||
mkdir -p storage/framework/{cache,sessions,views}
|
|
||||||
chmod -R 775 storage
|
|
||||||
chown -R www-data:www-data storage
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ! -L "public/storage" ]; then
|
echo -e "\n====================== Validating environment... ====================== "
|
||||||
|
|
||||||
|
# Ensure app storage directory is scaffolded
|
||||||
|
mkdir -p storage/{{framework/cache,framework/sessions,framework/views},app,logs}
|
||||||
|
|
||||||
|
# Ensure storage directory is permissioned for www-data
|
||||||
|
chmod -R 775 storage
|
||||||
|
chown -R www-data:www-data storage
|
||||||
|
|
||||||
|
echo -e "\n > Storage directory scaffolding is OK... "
|
||||||
|
|
||||||
|
# Ensure storage symlink exists
|
||||||
|
if [[ ! -L "public/storage" ]]; then
|
||||||
echo -e "\n > Creating symbolic link for app public storage... "
|
echo -e "\n > Creating symbolic link for app public storage... "
|
||||||
|
|
||||||
php artisan storage:link
|
php artisan storage:link
|
||||||
|
else
|
||||||
|
echo -e "\n > Storage linked... "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Ensure app key is generated
|
||||||
if [[ -z "$APP_KEY" ]]; then
|
if [[ -z "$APP_KEY" ]]; then
|
||||||
echo -e "\n > Oops! The required APP_KEY configuration is missing in your environment! "
|
echo -e "\n > Oops! The required APP_KEY configuration is missing in your environment! "
|
||||||
echo -e "\n > You should set this APP_KEY in your .env file! "
|
|
||||||
|
|
||||||
draw_box() {
|
draw_box() {
|
||||||
local text="$1"
|
local text="$1"
|
||||||
@@ -34,23 +41,36 @@ if [[ -z "$APP_KEY" ]]; then
|
|||||||
|
|
||||||
export APP_KEY=$(php artisan key:generate --show)
|
export APP_KEY=$(php artisan key:generate --show)
|
||||||
draw_box $APP_KEY
|
draw_box $APP_KEY
|
||||||
|
else
|
||||||
|
echo -e "\n > APP_KEY is OK... "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\n====================== Running migrations... ====================== "
|
echo -e "\n====================== Running migrations... ====================== "
|
||||||
run_migrations() {
|
|
||||||
php artisan migrate --force
|
# Wait 60 seconds for database to be ready
|
||||||
}
|
RETRIES=12
|
||||||
RETRIES=12 # wait 60 seconds for database to be ready
|
|
||||||
DELAY=5
|
DELAY=5
|
||||||
|
run_migrations() {
|
||||||
|
sleep $DELAY
|
||||||
|
# php artisan migrate --force
|
||||||
|
output=$(php artisan migrate --force 2>/dev/null)
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
echo "$output"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
until run_migrations; do
|
until run_migrations; do
|
||||||
RETRIES=$((RETRIES-1))
|
RETRIES=$((RETRIES-1))
|
||||||
if [ $RETRIES -le 0 ]; then
|
if [[ $RETRIES -le 0 ]]; then
|
||||||
echo -e "\n > Database is not ready after $RETRIES attempts. Exiting... "
|
echo -e "\n > Database is not ready after one minute. Exiting... \n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo -e "\n > Waiting for database to be ready... retrying in $DELAY seconds. "
|
echo -e "\n > Waiting for database to be ready... retrying in $DELAY seconds. \n"
|
||||||
sleep $DELAY
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "\n====================== Spinning up Supervisor daemon... ====================== \n"
|
echo -e "\n====================== Spinning up Supervisor daemon... ====================== \n"
|
||||||
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
|
||||||
|
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
|
||||||
|
|||||||
+10
-5
@@ -2,33 +2,38 @@
|
|||||||
nodaemon=true
|
nodaemon=true
|
||||||
user=root
|
user=root
|
||||||
pidfile=/var/run/supervisord.pid
|
pidfile=/var/run/supervisord.pid
|
||||||
|
logfile=/var/log/supervisor/supervisord.log
|
||||||
|
|
||||||
[program:nginx]
|
[program:nginx]
|
||||||
command=nginx -g 'daemon off;'
|
command=nginx -g 'daemon off;'
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
redirect_stdout=true
|
|
||||||
|
|
||||||
[program:php]
|
[program:php]
|
||||||
command=php-fpm -F
|
command=php-fpm -F
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
redirect_stdout=true
|
|
||||||
|
|
||||||
[program:scheduler]
|
[program:scheduler]
|
||||||
command=php artisan schedule:work
|
command=php artisan schedule:work
|
||||||
|
user=www-data
|
||||||
autorestart=true
|
autorestart=true
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
redirect_stdout=true
|
stdout_logfile=/dev/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
|
||||||
[program:queue-worker]
|
[program:queue-worker]
|
||||||
command=php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600
|
|
||||||
process_name=%(program_name)s_%(process_num)02d
|
process_name=%(program_name)s_%(process_num)02d
|
||||||
|
command=php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600
|
||||||
|
user=www-data
|
||||||
autorestart=true
|
autorestart=true
|
||||||
redirect_stderr=true
|
redirect_stderr=true
|
||||||
redirect_stdout=true
|
stdout_logfile=/dev/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
numprocs=2
|
numprocs=2
|
||||||
|
stopasgroup=true
|
||||||
|
killasgroup=true
|
||||||
|
|
||||||
[supervisorctl]
|
[supervisorctl]
|
||||||
Reference in New Issue
Block a user