Skip to content

Commit f0b5368

Browse files
committed
docker configuration
1 parent f0e3dca commit f0b5368

17 files changed

+287
-71643
lines changed

docker/nginx/nginx.conf renamed to .docker/nginx/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ server {
88
location ~ \.php$ {
99
try_files $uri =404;
1010
fastcgi_split_path_info ^(.+\.php)(/.+)$;
11-
fastcgi_pass php-fpm:9000;
11+
fastcgi_pass backend:9000;
1212
fastcgi_index index.php;
1313
include fastcgi_params;
1414
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

.docker/php-fpm/install.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
3+
apk add bzip2 file re2c freetds freetype icu libintl libldap libjpeg libmcrypt libpng libpq libwebp libzip nodejs npm
4+
5+
TMP="autoconf \
6+
bzip2-dev \
7+
freetds-dev \
8+
freetype-dev \
9+
g++ \
10+
gcc \
11+
gettext-dev \
12+
icu-dev \
13+
jpeg-dev \
14+
libmcrypt-dev \
15+
libpng-dev \
16+
libwebp-dev \
17+
libxml2-dev \
18+
libzip-dev \
19+
make \
20+
openldap-dev \
21+
postgresql-dev"
22+
23+
apk add $TMP
24+
25+
# Configure extensions
26+
docker-php-ext-configure gd --with-jpeg-dir=usr/ --with-freetype-dir=usr/ --with-webp-dir=usr/
27+
docker-php-ext-configure ldap --with-libdir=lib/
28+
docker-php-ext-configure pdo_dblib --with-libdir=lib/
29+
30+
docker-php-ext-install \
31+
bz2 \
32+
exif \
33+
gd \
34+
gettext \
35+
intl \
36+
ldap \
37+
pdo_dblib \
38+
pdo_pgsql \
39+
xmlrpc \
40+
zip \
41+
mysqli \
42+
pdo_mysql
43+
44+
# Install Xdebug
45+
pecl install xdebug \
46+
&& docker-php-ext-enable xdebug \
47+
&& echo "remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
48+
&& echo "remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
49+
&& echo "remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
50+
&& echo "idekey=IDE_DEBUG" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
51+
&& echo "error_reporting=E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
52+
&& echo "display_startup_errors=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
53+
&& echo "display_errors=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
54+
55+
# Install composer
56+
cd /tmp && php -r "readfile('https://getcomposer.org/installer');" | php && \
57+
mv composer.phar /usr/bin/composer && \
58+
chmod +x /usr/bin/composer
59+
60+
apk del $TMP
61+
62+
# Install PHPUnit
63+
curl -sSL -o /usr/bin/phpunit https://phar.phpunit.de/phpunit.phar && chmod +x /usr/bin/phpunit
64+
65+
# Set timezone
66+
#RUN echo Asia/Karachi > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
File renamed without changes.

.dockerignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/node_modules
2-
/vendor
1+
./node_modules
2+
./vendor

.env.example

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1+
# Define Application Specific Keys
12
APP_NAME=Laravel
23
APP_ENV=local
34
APP_KEY=
45
APP_DEBUG=true
56
APP_URL=http://localhost
67
APP_API=http://localhost/api
78

9+
# Log Channel Variables
810
LOG_CHANNEL=stack
9-
LOG_DEPRECATIONS_CHANNEL=null
1011
LOG_LEVEL=debug
1112

12-
DB_CONNECTION=mysql
13-
DB_HOST=127.0.0.1
14-
DB_PORT=3306
15-
DB_DATABASE=laravel
16-
DB_USERNAME=root
17-
DB_PASSWORD=
13+
# Database Variables
14+
DB_CONNECTION=pgsql
15+
DB_HOST=database
16+
DB_PORT=5432
17+
DB_DATABASE=database
18+
DB_USERNAME=database_user
19+
DB_PASSWORD=database_pass
20+
DB_ROOT_PASSWORD=database_pass
1821

22+
# Nginx Variables
23+
HTTP_PORT=80:80
24+
HTTPS_PORT=443:443
25+
26+
# BroadCast, Queue, Session Variables
1927
BROADCAST_DRIVER=log
20-
CACHE_DRIVER=file
2128
FILESYSTEM_DRIVER=local
2229
QUEUE_CONNECTION=sync
2330
SESSION_DRIVER=file
2431
SESSION_LIFETIME=120
2532

26-
MEMCACHED_HOST=127.0.0.1
27-
28-
REDIS_HOST=127.0.0.1
29-
REDIS_PASSWORD=null
30-
REDIS_PORT=6379
31-
33+
# Mail Variables
3234
MAIL_MAILER=smtp
3335
MAIL_HOST=mailhog
3436
MAIL_PORT=1025
@@ -38,16 +40,10 @@ MAIL_ENCRYPTION=null
3840
MAIL_FROM_ADDRESS=null
3941
MAIL_FROM_NAME="${APP_NAME}"
4042

41-
AWS_ACCESS_KEY_ID=
42-
AWS_SECRET_ACCESS_KEY=
43-
AWS_DEFAULT_REGION=us-east-1
44-
AWS_BUCKET=
45-
AWS_USE_PATH_STYLE_ENDPOINT=false
46-
43+
# Pusher Server Variables
4744
PUSHER_APP_ID=
4845
PUSHER_APP_KEY=
4946
PUSHER_APP_SECRET=
5047
PUSHER_APP_CLUSTER=mt1
51-
5248
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
53-
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
49+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

docker-compose.yml

+54-34
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,71 @@
1-
version: '3'
1+
# ! Docker-Compose Specification
2+
version: '3.8'
3+
4+
# ! Define Project Network
5+
networks:
6+
app-network:
7+
8+
# ! Define Project Volume
9+
volumes:
10+
pgdata:
11+
12+
# ? App Stack
213
services:
3-
php-fpm:
4-
build:
5-
context: .
6-
dockerfile: php.dockerfile
7-
container_name: php-fpm
8-
working_dir: /var/www/
9-
volumes:
14+
# ? Bring up Nginx After Backend and Link Volumes
15+
webserver:
16+
image: nginx:1.21-alpine
17+
container_name: webserver
18+
restart: unless-stopped
19+
ports:
20+
- "${HTTP_PORT}"
21+
volumes:
1022
- ./:/var/www
11-
- ./docker/php-fpm/php.ini:/usr/local/etc/php/conf.d/local.ini
23+
- .docker/nginx:/etc/nginx/conf.d
1224
networks:
1325
- app-network
1426

15-
nginx:
16-
image: nginx:1.21-alpine
17-
container_name: server-nginx
18-
volumes:
19-
- ./:/var/www
20-
- ./docker/nginx:/etc/nginx/conf.d/
27+
# ? Bring up Postgres and configure the Database
28+
database:
29+
image: postgres:14-alpine
30+
container_name: database
31+
restart: unless-stopped
32+
tty: true
2133
ports:
22-
- "80:80"
34+
- "5432:5432"
35+
environment:
36+
- POSTGRES_USER=${DB_USERNAME}
37+
- POSTGRES_PASSWORD=${DB_PASSWORD}
38+
- POSTGRES_DB=${DB_DATABASE}
39+
- PGDATA=/var/lib/postgresql/data
40+
volumes:
41+
- pgdata:/var/lib/postgresql/data
2342
networks:
2443
- app-network
2544

26-
react:
45+
# ? Build, Bring up Backend Container
46+
backend:
2747
build:
2848
context: .
29-
dockerfile: npm.dockerfile
30-
container_name: react
49+
dockerfile: php.dockerfile
50+
container_name: backend
51+
volumes:
52+
- .:/var/www
53+
- .docker/php-fpm/php.ini:/usr/local/etc/php/conf.d/local.ini
54+
depends_on:
55+
- database
3156
networks:
3257
- app-network
3358

34-
postgres:
35-
image: postgres:14-alpine
36-
container_name: db-postgres
59+
# ? Bring Up Client UI
60+
client:
61+
build:
62+
context: .
63+
dockerfile: npm.dockerfile
64+
container_name: client
65+
tty: true
3766
volumes:
38-
- ./docker/postgresql:/var/lib/postgresql/data
39-
environment:
40-
- POSTGRES_USER=${DB_USERNAME}
41-
- POSTGRES_PASSWORD=${DB_PASSWORD}
42-
- POSTGRES_DB=${DB_DATABASE}
43-
- PGDATA=/var/lib/postgresql/data
44-
ports:
45-
- "5432:5432"
67+
- ./:/app
68+
depends_on:
69+
- backend
4670
networks:
4771
- app-network
48-
49-
networks:
50-
app-network:
51-
driver: bridge

init.sh

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
#?###################################################################################################
4+
#? #
5+
#? Output Helper Methods #
6+
#? #
7+
#?###################################################################################################
8+
9+
trap "exit" INT
10+
11+
function blue_text_box()
12+
{
13+
echo " "
14+
local s="$*"
15+
tput setaf 3
16+
echo " -${s//?/-}-
17+
| ${s//?/ } |
18+
| $(tput setaf 4)$s$(tput setaf 3) |
19+
| ${s//?/ } |
20+
-${s//?/-}-"
21+
tput sgr 0
22+
echo " "
23+
}
24+
25+
function red_text_box()
26+
{
27+
echo " "
28+
local s="$*"
29+
tput setaf 3
30+
echo " -${s//?/-}-
31+
| ${s//?/ } |
32+
| $(tput setaf 1)$s$(tput setaf 3) |
33+
| ${s//?/ } |
34+
-${s//?/-}-"
35+
tput sgr 0
36+
echo " "
37+
}
38+
39+
function green_text_box()
40+
{
41+
echo " "
42+
local s="$*"
43+
tput setaf 3
44+
echo " -${s//?/-}-
45+
| ${s//?/ } |
46+
| $(tput setaf 2)$s$(tput setaf 3) |
47+
| ${s//?/ } |
48+
-${s//?/-}-"
49+
tput sgr 0
50+
echo " "
51+
}
52+
53+
#!###################################################################################################
54+
#! #
55+
#! Script Start #
56+
#! #
57+
#!###################################################################################################
58+
59+
# ! bring down any service instance if it exists
60+
red_text_box 'Removing Old Stack if It Exists'
61+
docker-compose down
62+
63+
# ? Change Permissions for Artisan
64+
chmod +x artisan
65+
66+
# ? Remove everything in the storage/database & bootstrap/cache directory
67+
sudo rm -rf storage/database/*
68+
sudo rm -rf bootstrap/cache/*.php
69+
70+
# Start & Build Container Stack
71+
blue_text_box 'Rebuilding the docker images & Starting them'
72+
docker-compose up -d --build
73+
74+
# * Install Laravel Dependencies
75+
green_text_box 'Installing Laravel Dependencies'
76+
docker exec -i backend composer install
77+
78+
# * Install Front-end Dependencies & Build
79+
green_text_box 'Installing Dependencies & Build for User UI'
80+
docker exec -i client npm i
81+
docker exec -i client npm run prod
82+
83+
# ! Generate Key & Caching/Optimizing Config
84+
red_text_box 'Generating Laravel'
85+
docker exec -i backend php artisan key:generate
86+
87+
# ! Migrate and Generate Passport Encryption Key
88+
red_text_box 'Migrating & Seeding'
89+
sleep 10
90+
docker exec -i backend composer dump-autoload
91+
docker exec -i backend php artisan migrate:fresh --seed
92+
docker exec -i backend chmod o+w ./storage/ -R

npm.dockerfile

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
FROM node:alpine
1+
FROM node:14-alpine
22

3-
WORKDIR /app
4-
5-
RUN addgroup app && adduser -S -G app app && chown -R app /app
6-
7-
USER app
3+
ENV USER=node
84

9-
COPY --chown=app:node package*.json ./
10-
11-
RUN npm install
12-
13-
COPY --chown=app:node . .
5+
# RUN addgroup ${USER} && adduser -S -G ${USER} ${USER}
6+
RUN mkdir -p /app && chown -R ${USER}:${USER} /app
7+
USER ${USER}
8+
WORKDIR /app
149

15-
CMD ["npm", "run", "prod"]
10+
COPY --chown=${USER}:${USER} . .

0 commit comments

Comments
 (0)