Skip to content

Commit 156f78c

Browse files
committed
Docker dev and prod working.
1 parent bfd3352 commit 156f78c

File tree

11 files changed

+118
-49
lines changed

11 files changed

+118
-49
lines changed

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# fastapi-vue3-docker-workflow
22
Stubbing out and documenting FastAPI, VueJS 3 and Docker workflow.
33

4+
NOTE: This is a sandbox project. Glean ideas only.
5+
6+
47
![Build Containers for Prod & Push to Dockerhub](https://github.com/LarryEitel/fastapi-vue3-docker-workflow/workflows/Build%20Containers%20for%20Prod%20&%20Push%20to%20Dockerhub/badge.svg)
58

69
## Must Reads
@@ -13,9 +16,21 @@ Stubbing out and documenting FastAPI, VueJS 3 and Docker workflow.
1316
- yarn serve and [http://localhost:8080/](http://localhost:8080/)
1417
- [X] Push to Git
1518
- [X] Create Dockerfile to run Vue from Docker
16-
- From frontend DIR, [create Docker image](https://cli.vuejs.org/guide/deployment.html#docker-nginx)
17-
- docker build . -t frontend
18-
- docker run -d -p 8080:80 frontend
19+
- [Dockerizing a Vue App](https://mherman.org/blog/dockerizing-a-vue-app/)
20+
21+
- For Dev
22+
- docker build -f ./frontend/DockerfileDev -t frontend:dev ./frontend
23+
- Hot loading doesn't work with this as expected. Only with docker-compose
24+
- docker run -it -v ${PWD}:/app -v /app/node_modules -p 8080:8080 -e CHOKIDAR_USEPOLLING=true --rm frontend:dev
25+
- docker-compose -f docker-compose-dev.yml up -d
26+
27+
- For Prod
28+
- docker build -f ./frontend/Dockerfile -t frontend:prod ./frontend
29+
- winpty docker run -it -p 80:80 --rm frontend:prod
30+
- docker-compose
31+
- docker-compose up -d --build
32+
33+
1934
- [x] Create GitAction to build docker image and push to dockerhub
2035
- Confirm image arrived at private [hub.docker.com](https://hub.docker.com/)
2136
- [x] Create [DigitalOcean](digitalocean.com) Droplet for <domain.com>
@@ -46,8 +61,6 @@ Stubbing out and documenting FastAPI, VueJS 3 and Docker workflow.
4661
- sudo ./svc.sh install
4762
- sudo ./svc.sh start
4863
- sudo ./svc.sh status
49-
- QUESTION: How to follow log?
50-
- sudo journalctl -u actions.runner........
5164
- [x] Docker Prep
5265
- mkdir /root/devops
5366
- cd /root/devops
@@ -65,10 +78,10 @@ Stubbing out and documenting FastAPI, VueJS 3 and Docker workflow.
6578
- Confirm server is running
6679
- systemctl status nginx
6780
- Key nginx commands
68-
- systemctl stop nginx
81+
- sudo systemctl stop nginx
6982
- systemctl start nginx
7083
- systemctl restart nginx
71-
- systemctl reload nginx
84+
- sudo systemctl reload nginx
7285
- systemctl disable nginx
7386
- systemctl enable nginx
7487
- systemctl status nginx.service

docker-compose-dev.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3'
2+
services:
3+
client:
4+
build:
5+
context: ./frontend
6+
dockerfile: Dockerfile
7+
ports:
8+
- "8080:8080"
9+
container_name: frontend
10+
volumes:
11+
- ./frontend:/app
12+
- /app/node_modules
13+
environment:
14+
- CHOKIDAR_USEPOLLING=true

docker-compose.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
version: '3'
1+
version: '3.7'
22
services:
3-
client:
3+
frontend-prod:
4+
container_name: frontend-prod
45
build:
56
context: ./frontend
6-
dockerfile: Dockerfile
7+
dockerfile: DockerfileProd
78
ports:
8-
- "8080:8080"
9-
container_name: frontend
10-
volumes:
11-
- ./frontend:/app
12-
- /app/node_modules
13-
environment:
14-
- CHOKIDAR_USEPOLLING=true
9+
- '80:80'

frontend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
**/node_modules
22
**/dist
3+
**/.git
4+
**/.gitignore

frontend/Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
# FROM mhart/alpine-node:15.5.1
2-
FROM node:lts-alpine
3-
1+
# build environment
2+
FROM node:15.5.1-alpine as build
43
WORKDIR /app
4+
ENV PATH /app/node_modules/.bin:$PATH
55

6-
COPY package*.json ./
7-
RUN npm install
6+
# COPY package.json /app/package.json
7+
COPY package.json ./
88

9+
RUN npm install --silent
10+
RUN npm install @vue/[email protected] -g
911

1012
COPY .eslintrc.js ./
1113
COPY babel.config.js ./
12-
1314
COPY . .
1415

15-
RUN ls
16-
RUN ls ./src
17-
18-
EXPOSE "${PORT:-8080}:80"
16+
RUN npm run build
1917

20-
CMD ["yarn", "serve"]
18+
# production environment
19+
FROM nginx:1.19.6-alpine
20+
COPY --from=build /app/dist /usr/share/nginx/html
21+
EXPOSE 80
22+
CMD ["nginx", "-g", "daemon off;"]

frontend/Dockerfile-dev

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

frontend/DockerfileDev

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:lts-alpine
2+
3+
WORKDIR /app
4+
5+
# add `/app/node_modules/.bin` to $PATH
6+
ENV PATH /app/node_modules/.bin:$PATH
7+
8+
COPY package*.json ./
9+
RUN npm install
10+
11+
12+
COPY .eslintrc.js ./
13+
COPY babel.config.js ./
14+
15+
COPY . .
16+
17+
CMD ["yarn", "serve"]
18+
19+
# docker run -d -p 8080:8080 frontend

frontend/Dockerfile_

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

frontend/src/components/HelloWorld.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
>vue-cli documentation</a
99
>.
1010
</p>
11-
<h3>Installed CLI Plugins</h3>
11+
<h3>Installed CLI Plugins asdfasdfasd asdfasdf</h3>
1212
<ul>
1313
<li>
1414
<a

nginx_config.conf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
server {
2+
3+
server_name craulio.com www.craulio.com;
4+
5+
location / {
6+
proxy_pass http://localhost:8080;
7+
proxy_http_version 1.1;
8+
proxy_buffering off;
9+
proxy_set_header Upgrade $http_upgrade;
10+
proxy_set_header Connection 'upgrade';
11+
proxy_set_header Host $host;
12+
# proxy_set_header X-Real-IP $remote_addr;
13+
proxy_cache_bypass $http_upgrade;
14+
}
15+
16+
listen 443 ssl; # managed by Certbot
17+
ssl_certificate /etc/letsencrypt/live/craulio.com/fullchain.pem; # managed by Certbot
18+
ssl_certificate_key /etc/letsencrypt/live/craulio.com/privkey.pem; # managed by Certbot
19+
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
20+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
21+
22+
23+
}
24+
server {
25+
if ($host = www.craulio.com) {
26+
return 301 https://$host$request_uri;
27+
} # managed by Certbot
28+
29+
30+
if ($host = craulio.com) {
31+
return 301 https://$host$request_uri;
32+
} # managed by Certbot
33+
34+
35+
listen 80;
36+
37+
server_name craulio.com www.craulio.com;
38+
return 404; # managed by Certbot
39+
40+
41+
42+
43+
}

0 commit comments

Comments
 (0)