Fix Dockerfile and docker-compose.yml

1. Generate a testing SQLite db on build
2. Optimize image layer caching
3. Fix permissions
4. Simplify nginx configuration
5. Fix nginx infinite redirect loop (couldn't access app folder)
This commit is contained in:
Birkhoff Lee
2019-12-04 14:49:57 +08:00
parent 7b697a477e
commit 7fe9a4c2a2
2 changed files with 26 additions and 29 deletions

View File

@ -1,12 +1,22 @@
##### STAGE 1 #####
FROM composer as composer FROM composer as composer
# Copy composer files from project root into composer container's working dir
COPY composer.* /app/
# Copy database directory for autoloader optimization
COPY database /app/database
# Run composer to build dependencies in vendor folder
RUN composer install --no-scripts --no-suggest --no-interaction --prefer-dist --optimize-autoloader
# Copy everything from project root into composer container's working dir # Copy everything from project root into composer container's working dir
COPY . /app COPY . /app
# Run composer to build dependencies in vendor folder RUN composer dump-autoload --optimize --classmap-authoritative
RUN set -xe \
&& composer install --no-scripts --no-suggest --no-interaction --prefer-dist --optimize-autoloader \ ##### STAGE 2 #####
&& composer dump-autoload --optimize --classmap-authoritative
FROM php:7.4.0-fpm-alpine FROM php:7.4.0-fpm-alpine
@ -25,10 +35,18 @@ COPY . /app
# Copy vendor folder from composer container into php container # Copy vendor folder from composer container into php container
COPY --from=composer /app/vendor /app/vendor COPY --from=composer /app/vendor /app/vendor
RUN php artisan config:cache && \ RUN touch database/database.sqlite && \
chmod -R 755 storage bootstrap/cache && \ php artisan migrate && \
chown -R www-data:www-data storage php artisan config:cache && \
php artisan passport:install && \
php artisan key:generate && \
chown -R www-data:www-data . && \
chmod -R 755 . && \
chmod -R 775 storage/framework/ && \
chmod -R 775 storage/logs/ && \
chmod -R 775 bootstrap/cache/
EXPOSE 9000 EXPOSE 9000
CMD ["php-fpm", "--nodaemonize"] CMD ["php-fpm", "--nodaemonize"]

View File

@ -34,41 +34,20 @@ http {
try_files $uri $uri/ /index.php?$query_string; try_files $uri $uri/ /index.php?$query_string;
} }
client_max_body_size 100m;
client_body_timeout 120s;
location = /favicon.ico { access_log off; log_not_found off; } location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; }
sendfile off;
add_header X-Content-Type-Options nosniff; add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block"; add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none; add_header X-Robots-Tag none;
add_header Content-Security-Policy "frame-ancestors 'self'"; add_header Content-Security-Policy "frame-ancestors 'self'";
location ~ \.php$ { location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000; fastcgi_pass php:9000;
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
include /etc/nginx/fastcgi_params; include /etc/nginx/fastcgi_params;
} }
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
} }
} }