From 6c4f0b62cc186011aa55ca5935598854fd7e8bb8 Mon Sep 17 00:00:00 2001 From: Matt Burchett Date: Tue, 6 Apr 2021 22:06:48 -0700 Subject: [PATCH] Adding Docker --- .gitignore | 1 + Dockerfile | 69 +++++++++++++++++++++++++++++++++++++++++++++++ deploy/local.ini | 4 +++ deploy/nginx.conf | 44 ++++++++++++++++++++++++++++++ post_deploy.sh | 8 ++++++ 5 files changed, 126 insertions(+) create mode 100644 Dockerfile create mode 100644 deploy/local.ini create mode 100644 deploy/nginx.conf create mode 100644 post_deploy.sh diff --git a/.gitignore b/.gitignore index 0ae59f0..273bad3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Homestead.json Homestead.yaml npm-debug.log yarn-error.log +*.sqlite diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd23dcb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +FROM php:7.4-fpm + +USER root + +WORKDIR /var/www + +# Install dependencies +RUN apt-get update \ + # gd + && apt-get install -y --no-install-recommends build-essential openssl nginx libfreetype6-dev libjpeg-dev libpng-dev libwebp-dev zlib1g-dev libzip-dev gcc g++ make vim unzip curl git jpegoptim optipng pngquant gifsicle locales libonig-dev nodejs npm \ + && docker-php-ext-configure gd \ + && docker-php-ext-install gd \ + # gmp + && apt-get install -y --no-install-recommends libgmp-dev \ + && docker-php-ext-install gmp \ + # pdo_mysql + && docker-php-ext-install pdo_mysql mbstring \ + # pdo + && docker-php-ext-install pdo \ + # opcache + && docker-php-ext-enable opcache \ + # zip + && docker-php-ext-install zip \ + && apt-get autoclean -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /tmp/pear/ + +# Copy files +COPY . /var/www + +COPY ./deploy/local.ini /usr/local/etc/php/local.ini + +COPY ./deploy/conf.d/nginx.conf /etc/nginx/nginx.conf + +RUN chmod +rwx /var/www + +RUN chmod -R 777 /var/www + +# setup npm +RUN npm install -g npm@latest + +RUN npm install + +# include your other npm run scripts e.g npm rebuild node-sass + +# run your default build command here mine is npm run prod +RUN npm run prod + +# setup composer and laravel +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +RUN composer install --working-dir="/var/www" + +RUN composer dump-autoload --working-dir="/var/www" + +RUN php artisan route:clear + +RUN php artisan route:cache + +RUN php artisan config:clear + +RUN php artisan config:cache + +EXPOSE 80 + +RUN ["chmod", "+x", "post_deploy.sh"] + +CMD [ "sh", "./post_deploy.sh" ] +# CMD php artisan serve --host=127.0.0.1 --port=9000 diff --git a/deploy/local.ini b/deploy/local.ini new file mode 100644 index 0000000..499fb7e --- /dev/null +++ b/deploy/local.ini @@ -0,0 +1,4 @@ +upload_max_filesize=40M +post_max_size=40M +max_execution_time=180 +memory_limit=-1 diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..f199206 --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,44 @@ +user root; +worker_processes auto; + +events { + worker_connections 1024; +} + +http { + access_log /dev/stdout; + include mime.types; + default_type application/octet-stream; + + server { + # we use port 80 here to work with our docker config but you can configure it to any port you want, just remember to update the dockerfile accordingly + listen 80; + + index index.php index.html; + + # your application here + server_name _; + + error_log /var/log/nginx/error.log; + + access_log /var/log/nginx/access.log; + + # this should be the path of your public folder in laravel which from our dockerfile it would be /var/www/public + root /var/www/public; + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + location / { + try_files $uri $uri/ /index.php?$query_string; + gzip_static on; + } +} +} diff --git a/post_deploy.sh b/post_deploy.sh new file mode 100644 index 0000000..ec3ad01 --- /dev/null +++ b/post_deploy.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# update application cache +php artisan optimize + +# start the application + +php-fpm -D && nginx -g "daemon off;"