Skip to content

Commit 9c66428

Browse files
committed
Add docker config file for production
1 parent 664910d commit 9c66428

File tree

8 files changed

+134
-21
lines changed

8 files changed

+134
-21
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ PUSHER_APP_SECRET=
4444
PUSHER_APP_CLUSTER=mt1
4545

4646
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
47-
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
47+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
48+
49+
HTTP_PORT=80
50+
MYSQL_PORT=3307

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/node_modules
22
/public/hot
3+
/public/js
34
/public/storage
45
/storage/*.key
56
/vendor

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ RUN composer install
3232

3333
RUN php artisan key:generate --ansi
3434

35-
COPY ./script/php_script.sh /tmp
35+
COPY ./script/php_script.sh /tmp
3636

3737
RUN chmod +x /tmp/php_script.sh
3838

3939
ENTRYPOINT ["sh","/tmp/php_script.sh"]
4040

41-
EXPOSE 8000
41+
EXPOSE 8000

Dockerfile.production

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# PHP dependencies
3+
#
4+
FROM composer:2.0.7 as vendor
5+
6+
WORKDIR /app
7+
8+
COPY database/ ./database/
9+
10+
COPY composer.json composer.json
11+
COPY composer.lock composer.lock
12+
13+
RUN composer install \
14+
--ignore-platform-reqs \
15+
--no-interaction \
16+
--no-plugins \
17+
--no-scripts \
18+
--prefer-dist
19+
20+
#
21+
# Fronend
22+
#
23+
FROM node:14.15.1-stretch-slim as client
24+
25+
WORKDIR /app
26+
27+
COPY package.json .
28+
29+
RUN npm install
30+
31+
COPY . .
32+
33+
RUN npm run production
34+
35+
36+
#
37+
# Main application
38+
#
39+
FROM php:7.3-fpm as base
40+
RUN apt-get update && apt-get install -y \
41+
build-essential \
42+
libpng-dev \
43+
libjpeg62-turbo-dev \
44+
libfreetype6-dev \
45+
locales \
46+
libzip-dev \
47+
zip \
48+
jpegoptim optipng pngquant gifsicle \
49+
unzip \
50+
&& apt clean && rm -rf /var/lib/apt/lists/*
51+
52+
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
53+
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
54+
55+
WORKDIR /var/www
56+
57+
58+
COPY . .
59+
COPY --from=vendor /app/vendor/ /var/www/vendor/
60+
COPY --from=client /app/public/js/ /var/www/public/js/
61+
COPY --from=client /app/public/css/ /var/www/public/css/
62+
# COPY --from=client /app/mix-manifest.json ./mix-manifest.json
63+
64+
RUN ls -la
65+
66+
RUN php artisan key:generate --ansi
67+
68+
COPY ./script/php_script.sh /tmp
69+
70+
71+
RUN chmod +x /tmp/php_script.sh
72+
73+
ENTRYPOINT ["sh","/tmp/php_script.sh"]
74+
75+
EXPOSE 8000

docker-compose.production.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: "3.8"
2+
services:
3+
server:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.production
7+
target: base
8+
container_name: server
9+
env_file:
10+
- ./.env
11+
ports:
12+
- "${HTTP_PORT}:8000"
13+
volumes:
14+
- ./:/var/www/
15+
- /var/www/vendor
16+
depends_on:
17+
- mysql
18+
links:
19+
- mysql
20+
mysql:
21+
image: mysql
22+
container_name: mysql
23+
command: --default-authentication-plugin=mysql_native_password
24+
restart: always
25+
environment:
26+
MYSQL_DATABASE: ${DB_DATABASE}
27+
MYSQL_USER: ${DB_USERNAME}
28+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
29+
ports:
30+
- ${MYSQL_PORT}:3306
31+
volumes:
32+
- ./mysql/init.sql:/data/application/init.sql
33+
- mysql_data:/var/lib/mysql
34+
volumes:
35+
mysql_data:

docker-compose.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
version: "3.8"
22
services:
3-
back-end:
3+
server:
44
build: .
55
command: npm run watch
6-
container_name: back-end
6+
container_name: server
77
ports:
8-
- "5000:8000"
8+
- "${HTTP_PORT}:8000"
99
volumes:
1010
- ./:/var/www/
1111
- /var/www/vendor
1212
depends_on:
1313
- mysql
14-
links:
14+
links:
1515
- mysql
1616
mysql:
1717
image: mysql
1818
container_name: mysql
1919
command: --default-authentication-plugin=mysql_native_password
2020
restart: always
2121
environment:
22-
MYSQL_DATABASE: "laravel"
23-
# MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
24-
MYSQL_DATABASE: 'laravel'
25-
MYSQL_USER: 'rooot'
26-
MYSQL_ROOT_PASSWORD: 'pass'
27-
ports:
28-
- 3307:3306
29-
volumes:
22+
MYSQL_DATABASE: ${DB_DATABASE}
23+
MYSQL_USER: ${DB_USERNAME}
24+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
25+
ports:
26+
- ${MYSQL_PORT}:3306
27+
volumes:
3028
- ./mysql/init.sql:/data/application/init.sql
31-
- mysql_data:/var/lib/mysql
32-
front-end:
33-
build:
29+
- mysql_data5:/var/lib/mysql
30+
client:
31+
build:
3432
context: .
3533
dockerfile: ./Dockerfile.node
36-
container_name: front-end
34+
container_name: client
3735
volumes:
3836
- ./:/var/www/
3937
- /var/www/node_modules
4038
depends_on:
41-
- 'back-end'
39+
- 'server'
4240
volumes:
43-
mysql_data:
41+
mysql_data5:

nginx/conf.d

Whitespace-only changes.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"laravel-mix": "^5.0.1",
1616
"lodash": "^4.17.19",
1717
"resolve-url-loader": "^3.1.0",
18+
"vue": "^2.6.12",
1819
"vue-template-compiler": "^2.6.12"
1920
},
2021
"dependencies": {

0 commit comments

Comments
 (0)