Skip to content

Commit 797d635

Browse files
committed
fix(ci): update for isolate network
1 parent 1f43be7 commit 797d635

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

code/docker-compose.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ services:
1616
interval: 10s
1717
timeout: 5s
1818
retries: 5
19+
networks:
20+
- backend-network
1921

2022
backend:
2123
build:
@@ -25,28 +27,42 @@ services:
2527
depends_on:
2628
db:
2729
condition: service_healthy
28-
# environment:
29-
# SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/getactive
30-
# SPRING_DATASOURCE_USERNAME: root
31-
# SPRING_DATASOURCE_PASSWORD: password
32-
ports:
33-
- "3232:3232"
3430
healthcheck:
3531
test: ["CMD", "curl", "-f", "http://localhost:3232/v1/health"]
3632
interval: 10s
3733
timeout: 5s
3834
retries: 5
35+
networks:
36+
- backend-network
37+
- frontend-network
3938

4039
frontend:
4140
build:
4241
context: ./frontend
4342
dockerfile: Dockerfile
44-
container_name: getactive-frontend
43+
image: getactive-frontend:latest
44+
restart: "no"
4545
depends_on:
46-
backend:
47-
condition: service_healthy
46+
- backend
47+
48+
nginx:
49+
build:
50+
context: ./nginx
51+
dockerfile: Dockerfile
52+
container_name: getactive-nginx
53+
depends_on:
54+
- frontend
55+
- backend
4856
ports:
4957
- "80:80"
58+
networks:
59+
- frontend-network
60+
61+
networks:
62+
frontend-network:
63+
driver: bridge
64+
backend-network:
65+
driver: bridge
5066

5167
volumes:
5268
mysql_data:

code/frontend/Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
FROM node:18-alpine as build
1+
FROM node:18-alpine as builder
22

33
WORKDIR /app
44

5+
# Copy package files
56
COPY package*.json ./
6-
77
RUN npm ci
88

9+
# Copy source code
910
COPY . .
1011

12+
# Build the application
1113
RUN npm run build
1214

13-
FROM nginx:alpine
14-
15-
COPY --from=build /app/dist /usr/share/nginx/html
15+
# Output stage - this stage is just for copying the build output
16+
FROM alpine:latest
1617

17-
COPY nginx.conf /etc/nginx/conf.d/default.conf
18+
# Create a directory for the build output
19+
WORKDIR /build-output
1820

19-
EXPOSE 80
21+
# Copy only the built files from the builder stage
22+
COPY --from=builder /app/dist ./dist
2023

21-
CMD ["nginx", "-g", "daemon off;"]
24+
# This image doesn't need to run anything
25+
# It's just a way to pass the build output to other images

code/frontend/src/services/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios';
33
import { jwtUtils } from '../utils/jwt';
44

55
const api = axios.create({
6-
baseURL: 'http://localhost:3232',
6+
baseURL: '/v1',
77
timeout: 5000,
88
});
99

code/nginx/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use the frontend build output
2+
FROM getactive-frontend:latest as frontend
3+
4+
# Nginx stage
5+
FROM nginx:alpine
6+
7+
# Install curl for healthcheck
8+
RUN apk add --no-cache curl
9+
10+
# Copy nginx configuration
11+
COPY nginx.conf /etc/nginx/conf.d/default.conf
12+
13+
# Copy built frontend files from the frontend image
14+
COPY --from=frontend /build-output/dist /usr/share/nginx/html
15+
16+
# Health check
17+
HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \
18+
CMD curl -f http://localhost/ || exit 1
19+
20+
EXPOSE 80
21+
22+
CMD ["nginx", "-g", "daemon off;"]

code/frontend/nginx.conf renamed to code/nginx/nginx.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ server {
1212
}
1313

1414
location /v1/ {
15-
proxy_pass http://localhost:3232/v1/;
15+
allow 172.16.0.0/12; # Docker internal network
16+
allow 192.168.0.0/16; # Docker internal network
17+
deny all; # Deny all other access
18+
19+
proxy_pass http://backend:3232/v1/;
1620
proxy_http_version 1.1;
1721
proxy_set_header Upgrade $http_upgrade;
1822
proxy_set_header Connection 'upgrade';

0 commit comments

Comments
 (0)