Revamp Docker setup
ADD
.env.docker
+APP_NAME=Budget
+APP_ENV=production
+APP_KEY=
+APP_DEBUG=false
+APP_LOG_LEVEL=debug
+APP_URL=http://localhost:8080
+
+DB_CONNECTION=mysql
+DB_HOST=database
+DB_PORT=3306
+DB_DATABASE=budget
+DB_USERNAME=budget
+DB_PASSWORD=test
+
+BROADCAST_DRIVER=log
+CACHE_DRIVER=file
+SESSION_DRIVER=file
+QUEUE_CONNECTION=database
+
+REDIS_HOST=127.0.0.1
+REDIS_PASSWORD=null
+REDIS_PORT=6379
+
+MAIL_DRIVER=smtp
+MAIL_HOST=smtp.mailtrap.io
+MAIL_PORT=2525
+MAIL_USERNAME=null
+MAIL_PASSWORD=null
+MAIL_ENCRYPTION=null
+
+PUSHER_APP_ID=
+PUSHER_APP_KEY=
+PUSHER_APP_SECRET=
+
+SUGGESTION_BOX_ENABLED=false
+
+PLANS_ENABLED=false
+PLANS_STANDARD_MAXIMUM_SPACES=2
+PLANS_PREMIUM_MAXIMUM_SPACES=null
+
+STRIPE_KEY=
+STRIPE_SECRET=
+STRIPE_PREMIUM_PLAN_PRICE_ID=

MODIFY
Dockerfile
Dockerfile
FROM php:7.2-fpm
-# Install system packages (Git, packages for archives, Node.js)
-RUN apt-get update \
- && apt-get install -y git libzip-dev zlib1g-dev unzip \
- && curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt-get install -y nodejs \
- && rm -rf /var/lib/apt/lists/*
+# Grab magical script that brings back balance throughout earth
+COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
-# Install PHP extensions
-RUN docker-php-ext-install pdo_mysql && docker-php-ext-install zip && docker-php-ext-install calendar
-
-# Ensure commands are running successfully before continuing
-SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+# Install NGINX and other packages
+RUN apt-get update && \
+ apt-get install -y \
+ nginx \
+ cron \
+ supervisor
-# Install Composer
-RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+# Configure NGINX
+COPY nginx.conf /etc/nginx/sites-enabled/default
-# Install Yarn
-RUN npm install -g yarn
+# Configure cron
+COPY cron.conf /etc/cron.d/budget
-WORKDIR /usr/share/nginx/budget
-COPY . .
+# Configure Supervisor
+COPY supervisord.conf /etc/supervisor/conf.d/budget.conf
-# Required before we're able to run any "php artisan" commands
-RUN composer install
+# Install PHP extensions
+RUN install-php-extensions pdo_mysql zip calendar gd
-RUN php artisan budget:install
+# Install Composer
+RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-RUN chown -R www-data:www-data /usr/share/nginx/budget
+# Install Node.js and Yarn
+RUN curl -sL https://deb.nodesource.com/setup_15.x | bash - && \
+ apt-get install -y nodejs && \
+ npm install -g yarn
-CMD ./docker_boot.sh
+WORKDIR /var/www

ADD
cron.conf
+* * * * * www-data cd /var/www && /usr/local/bin/php artisan schedule:run

MODIFY
docker-compose.yml
docker-compose.yml
@@ -2,37 +2,25 @@ version: '3'
volumes:
database2: {}
- built_app: {}
services:
- # Named "database2" because "database" conflicts with directory inside project
- database2:
- image: mysql:8
+ database:
+ image: mysql:5.7
environment:
- MYSQL_DATABASE: budget
- MYSQL_USER: budget
- MYSQL_PASSWORD: test
- MYSQL_RANDOM_ROOT_PASSWORD: 'true'
+ MYSQL_DATABASE: 'budget'
+ MYSQL_USER: 'budget'
+ MYSQL_PASSWORD: 'test'
+ MYSQL_RANDOM_ROOT_PASSWORD: 1
+ ports:
+ - 3306:3306
command: --default-authentication-plugin=mysql_native_password
- volumes:
- - database2:/var/lib/mysql
- php:
+ app:
build: ./
environment:
- DB_HOST: database2
- DB_DATABASE: budget
- DB_USERNAME: budget
- DB_PASSWORD: test
- volumes:
- - built_app:/usr/share/nginx/budget
-
- nginx:
- image: nginx:latest
- depends_on:
- - php # To ensure that "built_app" volume gets filled by "php" service
+ - BUDGET_SETUP
volumes:
- - built_app:/usr/share/nginx/budget
- - ./nginx.conf:/etc/nginx/conf.d/default.conf
+ - .:/var/www
ports:
- 8080:80
+ command: ./docker_boot.sh

MODIFY
docker_boot.sh
docker_boot.sh
-#!/usr/bin/env bash
+#!/bin/bash
-./wait-for-it.sh database2:3306 -- php artisan migrate
+chown -R www-data:www-data /var/www/storage
-php-fpm
+if [ ! -z $BUDGET_SETUP ]; then
+ composer install
+ cp .env.docker .env
+ php artisan key:generate
+ php artisan storage:link
+
+ yarn install
+ yarn production
+
+ php artisan migrate --force
+fi
+
+supervisord -n -c supervisord.conf

MODIFY
nginx.conf
nginx.conf
server {
listen 80;
- index index.php index.html index.htm;
- root /usr/share/nginx/budget/public;
+ index index.php;
+ root /var/www/public;
location / {
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;
+ include snippets/fastcgi-php.conf;
- fastcgi_pass php:9000;
- fastcgi_index index.php;
+ fastcgi_pass 127.0.0.1:9000;
}
}

ADD
supervisord.conf
+[supervisord]
+user = root
+
+[program:php-fpm]
+command = php-fpm -F
+stdout_logfile=/dev/stdout
+stderr_logfile=/dev/stderr
+
+[program:nginx]
+command = nginx -g 'daemon off;'
+stdout_logfile=/dev/stdout
+stderr_logfile=/dev/stderr
+
+[program:cron]
+command = cron -f
+stdout_logfile=/dev/stdout
+stderr_logfile=/dev/stderr
+
+[program:queue-worker]
+command = php /var/www/artisan queue:work --tries=3
+stdout_logfile=/dev/stdout
+stderr_logfile=/dev/stderr

Revamp Docker setup