From 16d5b806572ffdce37b46be3ee9e11228214f983 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sat, 25 Jan 2025 18:09:02 -0600 Subject: [PATCH] wip --- docker-compose.yml | 23 +++++------------------ docker/Dockerfile | 33 ++++++++++++++++++++++----------- docker/entrypoint.sh | 12 ------------ docker/nginx.conf | 2 +- docker/supervisord.conf | 7 +++++++ 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6ea3f59..fd49e6c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,15 +7,16 @@ services: container_name: investbrain-app restart: unless-stopped tty: true - expose: - - "9000" - volumes: - - .:/var/www/app:delegated + ports: + - "${APP_PORT:-8000}:80" depends_on: - mysql - redis networks: - investbrain-network + volumes: + - ./storage:/var/www/app/storage + - .env:/var/www/app/.env redis: image: redis:alpine container_name: investbrain-redis @@ -25,20 +26,6 @@ services: - investbrain-network volumes: - investbrain-redis:/data - nginx: - image: nginx:alpine - container_name: investbrain-nginx - restart: unless-stopped - tty: true - ports: - - "${APP_PORT:-8000}:80" - volumes: - - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf - - .:/var/www/app:delegated - depends_on: - - app - networks: - - investbrain-network mysql: image: mysql:8.0 container_name: investbrain-mysql diff --git a/docker/Dockerfile b/docker/Dockerfile index dcd7733..ff9a70c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,40 +6,51 @@ ENV DEBIAN_FRONTEND=noninteractive COPY . /var/www/app WORKDIR /var/www/app +# Install Composer and Node.js +RUN apt-get update && apt-get install -y \ + curl \ + unzip \ + git \ + nodejs \ + npm \ + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# Install PHP dependencies +RUN composer install --no-scripts --optimize-autoloader + +# Install Node dependencies and build assets +RUN npm install && npm run build + # Set permissions RUN chown -R www-data:www-data . \ - && chmod -R 775 ./storage \ && chmod +x ./docker/entrypoint.sh \ # Install common php extension dependencies && apt-get update && apt-get install -y \ + nginx \ libfreetype-dev \ libjpeg62-turbo-dev \ libpng-dev \ zlib1g-dev \ libzip-dev \ - unzip \ libicu-dev \ - git \ - curl \ supervisor \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-configure zip \ && docker-php-ext-install -j$(nproc) \ gd \ zip \ pdo_mysql \ mysqli \ intl \ -# Install Node.js and npm - && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ - && apt-get install -y nodejs \ - && npm install -g npm@latest +# remove default nginx config + && rm /etc/nginx/sites-enabled/default + +# Copy the custom Nginx configuration +COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf # Copy over supervisor configuration COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf -# Install composer -COPY --from=composer:2.6.5 /usr/bin/composer /usr/local/bin/composer - # Serve on port 80 EXPOSE 80 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ffdc0ca..84148f3 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,15 +9,7 @@ if [ ! -f ".env" ]; then cp .env.example .env fi -echo -e "\n====================== Installing Composer dependencies... ====================== " -/usr/local/bin/composer install - echo -e "\n====================== Validating environment... ====================== " -if [ $(stat -c '%U' .) != "www-data" ]; then - echo " > Setting correct permissions for pwd..." - chown -R www-data:www-data . -fi - if ( ! grep -q "^APP_KEY=" ".env" || grep -q "^APP_KEY=$" ".env"); then echo " > Ah, APP_KEY is missing in .env file. Generating a new key!" @@ -30,10 +22,6 @@ if [ ! -L "public/storage" ]; then /usr/local/bin/php artisan storage:link fi -echo -e "\n====================== Installing NPM dependencies and building frontend... ====================== " -/usr/bin/npm install -/usr/bin/npm run build - echo -e "\n====================== Running migrations... ====================== " run_migrations() { /usr/local/bin/php artisan migrate --force diff --git a/docker/nginx.conf b/docker/nginx.conf index 9e2fdca..93bf2c1 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -14,7 +14,7 @@ server { fastcgi_param HTTPS $http_x_forwarded_proto; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_pass investbrain-app:9000; + fastcgi_pass 127.0.0.1:9000; } location ~ /\.ht { diff --git a/docker/supervisord.conf b/docker/supervisord.conf index 726bff0..44a392c 100644 --- a/docker/supervisord.conf +++ b/docker/supervisord.conf @@ -4,6 +4,13 @@ user=root logfile=/var/log/supervisor/supervisord.log pidfile=/var/run/supervisord.pid +[program:nginx] +command=nginx -g 'daemon off;' +autostart=true +autorestart=true +stderr_logfile=/var/log/nginx/error.log +stdout_logfile=/var/log/nginx/access.log + [program:php] command=php-fpm -F autostart=true