File tree Expand file tree Collapse file tree 10 files changed +191
-0
lines changed
Expand file tree Collapse file tree 10 files changed +191
-0
lines changed Original file line number Diff line number Diff line change 1+ /vendor
Original file line number Diff line number Diff line change 1+ # Laravel Docker Build
2+
3+ ## Installation
4+
5+ ``` shell
6+ composer require --dev blamebutton/laravel-docker-builder
7+ ```
8+
9+ ## Usage
10+
11+ Add ` DOCKER_IMAGE_TAG ` to your ` .env ` and run:
12+
13+ ``` shell
14+ vendor/bin/docker/build
15+ ```
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ source .env
4+
5+ PACKAGE=" $( dirname " ${BASH_SOURCE[0]} " ) /.."
6+
7+ if ! [[ -f " ${PWD} /public/index.php" ]]; then
8+ echo " Missing [/public/index.php], please run from Laravel base directory." ;
9+ exit 1
10+ fi
11+
12+ if ! [[ -f " ${PWD} /.dockerignore" ]]; then
13+ echo " Missing [/.dockerignore], copying..." ;
14+ cp " ${PACKAGE} /docker/.dockerignore" " ${PWD} /.dockerignore"
15+ fi
16+
17+ TAG=" ${DOCKER_IMAGE_TAG} "
18+
19+ if [[ -z " ${TAG} " ]]; then
20+ echo " Environment variable [DOCKER_IMAGE_TAG] not found."
21+ exit 2
22+ fi
23+
24+ echo " Building [${TAG} :nginx]"
25+ docker build \
26+ --tag " ${TAG} :nginx" \
27+ --build-arg " PACKAGE=${PACKAGE} " \
28+ --file " ${PACKAGE} /docker/nginx.Dockerfile" \
29+ " ${PWD} "
30+
31+ echo " Building [${TAG} :php]"
32+ docker build \
33+ --tag " ${TAG} :php" \
34+ --build-arg " PACKAGE=${PACKAGE} " \
35+ --file " ${PACKAGE} /docker/php.Dockerfile" \
36+ " ${PWD} "
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ php artisan config:cache
4+ php artisan route:cache
5+ php artisan view:cache
6+
7+ php-fpm
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " blamebutton/laravel-docker-builder" ,
3+ "description" : " Production ready Docker files for Laravel" ,
4+ "type" : " library" ,
5+ "license" : " MIT" ,
6+ "autoload" : {
7+ "psr-4" : {
8+ "BlameButton\\ LaravelDockerBuilder\\ " : " src/"
9+ }
10+ },
11+ "authors" : [
12+ {
13+ "name" : " Bram Ceulemans" ,
14+ "email" : " bram@ceulemans.dev"
15+ }
16+ ],
17+ "bin" : [
18+ " bin/docker-build" ,
19+ " bin/docker-php-entrypoint"
20+ ],
21+ "require" : {}
22+ }
Original file line number Diff line number Diff line change 1+ services :
2+ nginx :
3+ image : laravel-docker:nginx
4+ volumes :
5+ - ./nginx/app.conf:/etc/nginx/conf.d/default.conf
6+ ports :
7+ - 127.0.0.1:80:80
8+ php :
9+ image : laravel-docker:php
10+ environment :
11+ APP_KEY : " base64:Avm4zs1yLfogxHpwBZRZhKZJ0EC6/7IX0FcVSyQQlLU="
12+ LOG_CHANNEL : " stderr"
Original file line number Diff line number Diff line change 1+ server {
2+ listen 80;
3+ listen [::]:80;
4+ root /app/public;
5+
6+ add_header X-Frame-Options "SAMEORIGIN";
7+ add_header X-Content-Type-Options "nosniff";
8+
9+ index index.php;
10+
11+ charset utf-8;
12+
13+ location / {
14+ try_files $uri $uri/ /index.php?$query_string;
15+ }
16+
17+ location = /favicon.ico { access_log off; log_not_found off; }
18+ location = /robots.txt { access_log off; log_not_found off; }
19+
20+ error_page 404 /index.php;
21+
22+ location ~ \.php$ {
23+ fastcgi_pass php:9000;
24+ fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
25+ include fastcgi_params;
26+ }
27+
28+ location ~ /\.(?!well-known).* {
29+ deny all;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ /*
2+
3+ /node_modules
4+ /vendor
5+
6+ ! /app
7+ ! /bootstrap /cache /.gitignore
8+ ! /bootstrap /app.php
9+ ! /config
10+ ! /database
11+ ! /lang
12+ ! /public
13+ ! /resources
14+ ! /routes
15+ ! /storage
16+
17+ ! /artisan
18+ ! /composer.json
19+ ! /composer.lock
20+ ! /package.json
21+ ! /package-lock.json
22+ ! /vite.config.js
Original file line number Diff line number Diff line change 1+ FROM nginx:1-alpine
2+
3+ WORKDIR /app/public
4+
5+ COPY public/ /app/public/
Original file line number Diff line number Diff line change 1+ ARG PACKAGE
2+
3+ # Composer installation
4+ FROM php:8.2-fpm AS composer
5+
6+ WORKDIR /app
7+
8+ COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
9+ RUN install-php-extensions @composer
10+
11+ COPY / /app
12+ RUN composer install --optimize-autoloader --no-dev
13+
14+ # Vite.js build
15+ FROM node:lts-alpine AS node
16+
17+ WORKDIR /app
18+
19+ # Cache layer for "npm ci"
20+ COPY /package.json /package-lock.json /app/
21+ RUN npm ci
22+ # Copy JavaScript
23+ COPY /vite.config.js /app/
24+ COPY /resources/ /app/resources/
25+ # Build using Vite.js
26+ RUN npm run build
27+
28+ FROM php:8.2-fpm
29+
30+ WORKDIR /app
31+
32+ COPY / /app
33+ COPY --from=node /app/public/build /app/public/build
34+ COPY --from=composer /app/vendor/ /app/vendor
35+
36+ RUN chown --recursive www-data:www-data /app/storage
37+
38+ RUN ls -la /app/vendor/bin
39+
40+ CMD ["bash" , "/app/vendor/bin/docker-php-entrypoint" ]
You can’t perform that action at this time.
0 commit comments