Skip to content

Commit cd7c307

Browse files
authored
Refactored some dockerfile (#16)
* Refactored some dockerfile
1 parent 1263461 commit cd7c307

File tree

18 files changed

+59
-147
lines changed

18 files changed

+59
-147
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ jobs:
2020
- name: docker hub login
2121
run: |
2222
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin $REGISTRY_DOMAIN
23-
- name: Build nginx image
24-
run: |
25-
cd nginx
26-
docker build . -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-dev
27-
docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-dev
2823
- name: Build api dev image
2924
run: |
3025
cd api
@@ -38,12 +33,12 @@ jobs:
3833
- name: Build frontend vue dev image
3934
run: |
4035
cd frontend-vue
41-
docker build . --target build-stage --build-arg NODE_ENV=$NODE_ENV --build-arg BASE_URL=/frontend-vue/ -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:frontend-vue-dev
36+
docker build . --target build-stage --build-arg NODE_ENV=development --build-arg BASE_URL=/frontend-vue/ -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:frontend-vue-dev
4237
docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:frontend-vue-dev
4338
- name: Build backend dev image
4439
run: |
4540
cd backend
46-
docker build . --target build-stage --build-arg NODE_ENV=$NODE_ENV --build-arg BASE_URL=/backend/ -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:backend-dev
41+
docker build . --target build-stage --build-arg NODE_ENV=development --build-arg BASE_URL=/backend/ -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:backend-dev
4742
docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:backend-dev
4843
- name: Build mysql dev image
4944
run: |
@@ -81,12 +76,6 @@ jobs:
8176
- name: Unit test frontend nuxt
8277
run: |
8378
docker exec frontend-nuxt npm run test
84-
- name: Build nginx image
85-
if: github.ref == 'refs/heads/master'
86-
run: |
87-
cd nginx
88-
docker build . -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-latest
89-
docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-latest
9079
- name: Build api latest image
9180
if: github.ref == 'refs/heads/master'
9281
run: |

.gitlab-ci.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ stages:
44
- build production
55

66
cache:
7-
key: '$CI_PIPELINE_ID'
7+
key: "$CI_PIPELINE_ID"
88
paths:
99
- /root/.cache
1010
- /root/.npm
@@ -14,15 +14,6 @@ cache:
1414
before_script:
1515
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin $REGISTRY_DOMAIN
1616

17-
build-nginx:
18-
stage: build dev environment
19-
image: docker:stable
20-
<<: *before-script
21-
script:
22-
- cd nginx
23-
- docker build . -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-dev
24-
- docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-dev
25-
2617
build-api:
2718
stage: build dev environment
2819
image: docker:stable
@@ -158,12 +149,3 @@ production-mysql:
158149
- cd mysql
159150
- docker build . -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:mysql-latest
160151
- docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:mysql-latest
161-
162-
production-nginx:
163-
stage: build production
164-
image: docker:stable
165-
<<: *before-script
166-
script:
167-
- cd nginx
168-
- docker build . -t $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-latest
169-
- docker push $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-latest

backend/Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ ARG BASE_URL
3030
ENV NODE_ENV=${NODE_ENV}
3131
ENV BASE_URL=${BASE_URL}
3232

33-
WORKDIR /srv
34-
3533
# Add configuration files
3634
COPY image-files/ /
3735

36+
WORKDIR /srv
37+
3838
COPY . .
3939

4040
RUN npm run build --mode=production
@@ -47,10 +47,7 @@ FROM nginx:stable-alpine AS production-stage
4747
# Add configuration files
4848
COPY image-files/ /
4949

50-
RUN chmod +x /usr/local/bin/docker-entrypoint*.sh
51-
ENV PATH /usr/local/bin:$PATH
52-
53-
COPY --from=build-stage /srv/dist /srv/backend/
50+
COPY --from=build-stage /srv/dist /srv
5451

5552
EXPOSE 80
5653

backend/image-files/etc/nginx/nginx.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ http {
3131

3232
root /srv/;
3333

34-
location ^~ /backend {
34+
location ^~ / {
3535
expires -1;
3636
add_header Pragma "no-cache";
3737
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
38-
39-
try_files $uri $uri/ /backend/index.html = 404;
38+
39+
try_files $uri $uri/ /index.html = 404;
4040
}
4141

4242
#error_page 404 /404.html;
4343

4444
# redirect server error pages to the static page /50x.html
4545
#
46-
46+
4747
error_page 500 502 503 504 /50x.html;
4848
location = /50x.html {
4949
root /srv;

backend/image-files/usr/local/bin/docker-entrypoint.dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44

5-
mkdir -p /srv/public/static
5+
mkdir -p /srv/static
66

77
cat <<EOT > /srv/public/static/config.json
88
{

backend/image-files/usr/local/bin/docker-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
set -e
44

5-
mkdir -p /srv/backend/static
5+
mkdir -p /srv/static
66

7-
cat <<EOT > /srv/backend/static/config.json
7+
cat <<EOT > /srv/static/config.json
88
{
99
"apiUrl": "$API_URL",
1010
"format": {

docker-compose.actions.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
version: '3.7'
1+
version: "3.7"
22

33
services:
44
nginx:
55
container_name: nginx
6-
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-dev
6+
image: nginx:stable
7+
depends_on:
8+
- api
9+
- frontend-nuxt
10+
- frontend-vue
11+
- mysql
712
networks:
813
- internal
14+
volumes:
15+
- ./nginx/image-files/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
16+
ports:
17+
- 80:80
918

1019
api:
1120
container_name: api

docker-compose.prod.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
version: '3.7'
1+
version: "3.7"
22

33
services:
44
nginx:
55
container_name: nginx
6-
image: $REGISTRY_DOMAIN/chrisleekr/nodejs-vuejs-mysql-boilerplate:nginx-latest
7-
ports:
8-
- '80:80'
9-
- '443:443'
6+
image: nginx:stable
7+
depends_on:
8+
- api
9+
- frontend-nuxt
10+
- frontend-vue
11+
- mysql
1012
networks:
1113
- internal
14+
volumes:
15+
- ./nginx/image-files/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
16+
ports:
17+
- 80:80
1218

1319
api:
1420
container_name: api

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
version: '3.7'
1+
version: "3.7"
22

33
services:
44
nginx:
55
container_name: nginx
6+
image: nginx:stable
67
depends_on:
78
- api
89
- frontend-nuxt
10+
- frontend-vue
911
- mysql
10-
build:
11-
context: ./nginx
1212
networks:
1313
- internal
1414
volumes:
1515
- ./nginx/image-files/etc/nginx/nginx.conf:/etc/nginx/nginx.conf
16-
- ./nginx:/etc/nginx/html
1716
ports:
1817
- 80:80
1918

@@ -99,6 +98,7 @@ services:
9998
networks:
10099
- internal
101100
environment:
101+
- BASE_URL=/backend/
102102
- API_URL=http://localhost/api
103103

104104
mysql:

frontend-nuxt/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,4 @@ EXPOSE 3000
4848

4949
ENTRYPOINT [ "docker-entrypoint.sh" ]
5050

51-
RUN npm run build
52-
5351
CMD ["npm", "start"]

frontend-vue/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ ARG BASE_URL
3030
ENV NODE_ENV=${NODE_ENV}
3131
ENV BASE_URL=${BASE_URL}
3232

33-
WORKDIR /srv
34-
3533
# Add configuration files
3634
COPY image-files/ /
3735

36+
WORKDIR /srv
37+
3838
COPY . .
3939

4040
RUN npm run build --mode=production
@@ -47,10 +47,8 @@ FROM nginx:stable-alpine AS production-stage
4747
# Add configuration files
4848
COPY image-files/ /
4949

50-
RUN chmod +x /usr/local/bin/docker-entrypoint*.sh
51-
ENV PATH /usr/local/bin:$PATH
52-
53-
COPY --from=build-stage /srv/dist /srv/frontend-vue/
50+
# Add configuration files
51+
COPY --from=build-stage /srv/dist /srv
5452

5553
EXPOSE 80
5654

frontend-vue/image-files/etc/nginx/nginx.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ http {
3131

3232
root /srv/;
3333

34-
location ^~ /frontend-vue {
34+
location ^~ / {
3535
expires -1;
3636
add_header Pragma "no-cache";
3737
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
3838

39-
try_files $uri $uri/ /frontend-vue/index.html = 404;
39+
try_files $uri $uri/ /index.html = 404;
4040
}
4141

4242
#error_page 404 /404.html;

frontend-vue/image-files/usr/local/bin/docker-entrypoint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
set -e
44

5-
mkdir -p /srv/frontend-vue/static
5+
mkdir -p /srv/static
66

7-
cat <<EOT > /srv/frontend-vue/static/config.json
7+
cat <<EOT > /srv/static/config.json
88
{
99
"apiUrl": "$API_URL",
1010
"format": {
11-
"dateTime": "YYYY-MM-DD HH:MM:SS"
11+
"timeZone": "Australia/Melbourne",
12+
"dateTime": "YYYY-MM-DD HH:mm:ss",
13+
"pickerDateTime": "yyyy-MM-dd HH:mm"
1214
}
1315
}
1416
EOT

nginx/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

nginx/image-files/etc/nginx/nginx.conf

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ http {
2020

2121
server {
2222
listen 80;
23-
listen 443 ssl;
24-
listen [::]:443 ssl;
25-
26-
ssl_certificate /ssl/nginx-selfsigned.crt;
27-
ssl_certificate_key /ssl/nginx-selfsigned.key;
28-
2923

3024
location / {
3125
return 301 /frontend-nuxt/;
@@ -35,10 +29,10 @@ http {
3529
return 301 /frontend-nuxt/;
3630
}
3731

38-
location ~* ^/frontend-nuxt/(.*) {
32+
location ~* ^/frontend-nuxt/(.*)$ {
3933
set $frontendNuxtHost "frontend-nuxt";
4034
set $frontendNuxtPort "3000";
41-
rewrite /frontend-nuxt/(.*) /frontend-nuxt/$1 break;
35+
rewrite ^/frontend-nuxt/(.*)$ /frontend-nuxt/$1 break;
4236

4337
proxy_pass http://$frontendNuxtHost:$frontendNuxtPort/frontend-nuxt/$1$is_args$args;
4438

@@ -54,12 +48,12 @@ http {
5448
return 301 /frontend-vue/;
5549
}
5650

57-
location ~* ^/frontend-vue/(.*) {
51+
location ~* ^/frontend-vue/(.*)$ {
5852
set $frontendVueHost "frontend-vue";
5953
set $frontendVuePort "80";
60-
rewrite /frontend-vue/(.*) /frontend-vue/$1 break;
54+
rewrite ^/frontend-vue/(.*)$ /frontend-vue/$1 break;
6155

62-
proxy_pass http://$frontendVueHost:$frontendVuePort/frontend-vue/$1$is_args$args;
56+
proxy_pass http://$frontendVueHost:$frontendVuePort/$1$is_args$args;
6357

6458
proxy_redirect off;
6559
proxy_set_header Host $host;
@@ -73,12 +67,12 @@ http {
7367
return 301 /backend/;
7468
}
7569

76-
location ~* ^/backend/(.*) {
70+
location ~* ^/backend/(.*)$ {
7771
set $backendHost "backend";
7872
set $backendPort "80";
79-
rewrite /backend/(.*) /backend/$1 break;
73+
rewrite ^/backend/(.*)$ /backend/$1 break;
8074

81-
proxy_pass http://$backendHost:$backendPort/backend/$1$is_args$args;
75+
proxy_pass http://$backendHost:$backendPort/$1$is_args$args;
8276

8377
proxy_redirect off;
8478
proxy_set_header Host $host;

nginx/image-files/ssl/nginx-selfsigned.crt

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)