Revize 5b73f460
Přidáno uživatelem Michal Schwob před asi 3 roky(ů)
- ID 5b73f4607a395f4715529815ed4646f36c658276
- Rodič 7e048a58
backend/docker-compose.yml | ||
---|---|---|
17 | 17 |
|
18 | 18 |
|
19 | 19 |
app: # Spring boot application |
20 |
build: . |
|
20 |
build: ./backend
|
|
21 | 21 |
container_name: app-backend # name of the container |
22 |
image: schwobik/backend-app:1.0
|
|
22 |
image: schwobik/backend-app:1.1
|
|
23 | 23 |
ports: |
24 | 24 |
- "8080:8080" # expose port 8080 out of the docker container do the local machine |
25 | 25 |
depends_on: |
... | ... | |
29 | 29 |
|
30 | 30 |
frontend: |
31 | 31 |
# Since our Dockerfile for web-server is located in react-app foler, our build context is ./react-app |
32 |
build: ../frontend
|
|
32 |
build: ./frontend |
|
33 | 33 |
container_name: frontend |
34 |
image: schwobik/frontend-app:1.0
|
|
34 |
image: schwobik/frontend-app:1.1
|
|
35 | 35 |
ports: |
36 |
- "80:80" |
|
36 |
- "3000:3000" |
|
37 |
|
|
38 |
nginx: |
|
39 |
image: schwobik/nginx:1.1 |
|
40 |
depends_on: |
|
41 |
- app |
|
42 |
- frontend |
|
43 |
restart: always |
|
44 |
build: ./nginx |
|
45 |
ports: |
|
46 |
- "3050:80" |
|
37 | 47 |
|
38 | 48 |
volumes: |
39 | 49 |
db-data: |
deployments/app-deployment.yaml | ||
---|---|---|
1 |
apiVersion: apps/v1 |
|
2 |
kind: Deployment |
|
3 |
metadata: |
|
4 |
name: app |
|
5 |
spec: |
|
6 |
replicas: 1 |
|
7 |
selector: |
|
8 |
matchLabels: |
|
9 |
component: app |
|
10 |
strategy: {} |
|
11 |
template: |
|
12 |
metadata: |
|
13 |
labels: |
|
14 |
component: app |
|
15 |
spec: |
|
16 |
containers: |
|
17 |
- env: |
|
18 |
- name: SPRING_DATASOURCE_URL |
|
19 |
value: jdbc:postgresql://db-service:5432/test |
|
20 |
image: schwobik/backend-app:1.1 |
|
21 |
name: app |
|
22 |
ports: |
|
23 |
- containerPort: 8080 |
|
24 |
resources: {} |
|
25 |
restartPolicy: Always |
|
26 |
status: {} |
deployments/app-service.yaml | ||
---|---|---|
1 |
apiVersion: v1 |
|
2 |
kind: Service |
|
3 |
metadata: |
|
4 |
name: app-service |
|
5 |
spec: |
|
6 |
type: ClusterIP |
|
7 |
ports: |
|
8 |
- name: "8080" |
|
9 |
port: 8080 |
|
10 |
targetPort: 8080 |
|
11 |
selector: |
|
12 |
component: app |
deployments/db-deployment.yaml | ||
---|---|---|
1 |
apiVersion: apps/v1 |
|
2 |
kind: Deployment |
|
3 |
metadata: |
|
4 |
name: db |
|
5 |
spec: |
|
6 |
replicas: 1 |
|
7 |
selector: |
|
8 |
matchLabels: |
|
9 |
component: db |
|
10 |
strategy: |
|
11 |
type: Recreate |
|
12 |
template: |
|
13 |
metadata: |
|
14 |
labels: |
|
15 |
component: db |
|
16 |
spec: |
|
17 |
containers: |
|
18 |
- env: |
|
19 |
- name: POSTGRES_DB |
|
20 |
value: test |
|
21 |
- name: POSTGRES_PASSWORD |
|
22 |
value: Password.123 |
|
23 |
- name: POSTGRES_USER |
|
24 |
value: test |
|
25 |
image: postgres:14.2 |
|
26 |
name: postgres-db |
|
27 |
ports: |
|
28 |
- containerPort: 5432 |
|
29 |
resources: {} |
|
30 |
restartPolicy: Always |
|
31 |
status: {} |
deployments/db-service.yaml | ||
---|---|---|
1 |
apiVersion: v1 |
|
2 |
kind: Service |
|
3 |
metadata: |
|
4 |
name: db-service |
|
5 |
spec: |
|
6 |
type: ClusterIP |
|
7 |
ports: |
|
8 |
- name: "5432" |
|
9 |
port: 5432 |
|
10 |
targetPort: 5432 |
|
11 |
selector: |
|
12 |
component: db |
deployments/frontend-deployment.yaml | ||
---|---|---|
1 |
apiVersion: apps/v1 |
|
2 |
kind: Deployment |
|
3 |
metadata: |
|
4 |
name: frontend-deployment |
|
5 |
spec: |
|
6 |
replikas: 1 |
|
7 |
selector: |
|
8 |
matchLabels: |
|
9 |
component: app |
|
10 |
template: |
|
11 |
metadata: |
|
12 |
labels: |
|
13 |
component: app |
|
14 |
spec: |
|
15 |
containers: |
|
16 |
- name: frontend |
|
17 |
image: schwobik/frontend-app:1.1.1 |
|
18 |
ports: |
|
19 |
- containerPort: 3000 |
deployments/frontend-service.yaml | ||
---|---|---|
1 |
apiVersion: v1 |
|
2 |
kind: Service |
|
3 |
metadata: |
|
4 |
name: frontend-service |
|
5 |
spec: |
|
6 |
type: LoadBalancer |
|
7 |
ports: |
|
8 |
- name: "3000" |
|
9 |
port: 3000 |
|
10 |
targetPort: 3000 |
|
11 |
selector: |
|
12 |
component: frontend |
deployments/nginx-service.yaml | ||
---|---|---|
1 |
apiVersion: networking.k8s.io/v1 |
|
2 |
kind: Ingress |
|
3 |
metadata: |
|
4 |
name: ingress-service |
|
5 |
anotation: |
|
6 |
kubernetes.io/ingress.class: "nginx" |
|
7 |
nginx.ingress.kubernetes.io/use-regex: "true" |
|
8 |
nginx.ingress.kubernetes.io/rewrite-target: /$1 |
|
9 |
spec: |
|
10 |
rules: |
|
11 |
- http: |
|
12 |
paths: |
|
13 |
- path: /?(.*) |
|
14 |
pathType: Prefix |
|
15 |
backend: |
|
16 |
service: |
|
17 |
name: frontend-service |
|
18 |
port: |
|
19 |
number: 3000 |
|
20 |
- path: /api/?(.*) |
|
21 |
pathType: Prefix |
|
22 |
backend: |
|
23 |
service: |
|
24 |
name: app-service |
|
25 |
port: |
|
26 |
number: 8080 |
frontend/Dockerfile | ||
---|---|---|
31 | 31 |
COPY nginx/nginx.conf /etc/nginx/conf.d |
32 | 32 |
|
33 | 33 |
# Expose port 80 for HTTP Traffic |
34 |
EXPOSE 80
|
|
34 |
EXPOSE 3000
|
|
35 | 35 |
|
36 | 36 |
# start the nginx web server |
37 | 37 |
CMD ["nginx", "-g", "daemon off;"] |
frontend/nginx/nginx.conf | ||
---|---|---|
1 |
server { |
|
2 |
listen 80; |
|
3 |
|
|
4 |
root /usr/share/nginx/html; |
|
1 |
server{ |
|
2 |
listen 3000; |
|
5 | 3 |
|
6 | 4 |
location / { |
7 |
index index.html index.htm; |
|
5 |
root /usr/share/nginx/html; |
|
6 |
index index.html index.htm; |
|
8 | 7 |
try_files $uri $uri/ /index.html; |
9 | 8 |
} |
10 |
|
|
11 |
location /api/ { |
|
12 |
proxy_pass http://app-backend:8080/api/; |
|
13 |
proxy_http_version 1.1; |
|
14 |
proxy_set_header Upgrade $http_upgrade; |
|
15 |
proxy_set_header Connection 'upgrade'; |
|
16 |
proxy_set_header Host $host; |
|
17 |
proxy_cache_bypass $http_upgrade; |
|
18 |
} |
|
19 | 9 |
} |
nginx/Dockerfile | ||
---|---|---|
1 |
FROM nginx |
|
2 |
COPY ./default.conf /etc/nginx/conf.d/default.conf |
nginx/Dockerfile.dev | ||
---|---|---|
1 |
FROM nginx |
|
2 |
COPY ./default.conf /etc/nginx/conf.d/default.conf |
nginx/default.conf | ||
---|---|---|
1 |
upstream client {
|
|
2 |
server client:3000;
|
|
1 |
upstream frontend {
|
|
2 |
server frontend:3000;
|
|
3 | 3 |
} |
4 | 4 |
|
5 | 5 |
upstream api { |
... | ... | |
10 | 10 |
listen 80; |
11 | 11 |
|
12 | 12 |
location / { |
13 |
proxy_pass http://client;
|
|
13 |
proxy_pass http://frontend;
|
|
14 | 14 |
} |
15 | 15 |
|
16 | 16 |
location /sockjs-node { |
Také k dispozici: Unified diff
Deployment changes
re #9333