Skip to content

Commit

Permalink
configure application to be compactible for traefik deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
bansikah22 committed Sep 12, 2024
1 parent f5466f0 commit 2ab2858
Show file tree
Hide file tree
Showing 8 changed files with 7,641 additions and 5,771 deletions.
8 changes: 5 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ services:
networks:
- user-net


user-frontend:
image: user-frontend:1.0
image: user-frontend:1.1
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend.rule=Host(`frontend.localhost`)"
Expand All @@ -32,10 +31,13 @@ services:
- user-net

user-backend:
image: user-backend:1.0
image: user-backend:1.1
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`backend.localhost`)"
- "traefik.http.services.backend.loadbalancer.server.port=8082"
- "traefik.http.middlewares.backend-rewrite.replacepathregex.regex=^/api/(.*)"
- "traefik.http.middlewares.backend-rewrite.replacepathregex.replacement=/api/$$1"
- "traefik.http.routers.backend.middlewares=backend-rewrite"
networks:
- user-net
41 changes: 41 additions & 0 deletions file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3.8"

networks:
user-net:
driver: bridge

services:
traefik:
image: traefik:v3.0
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "80:80" # Expose HTTP
- "8080:8080" # Expose Traefik dashboard
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro" # Allow Traefik to listen to Docker
networks:
- user-net


user-frontend:
image: user-frontend:1.0
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend.rule=Host(`frontend.localhost`)"
- "traefik.http.services.frontend.loadbalancer.server.port=80"
depends_on:
- user-backend
networks:
- user-net

user-backend:
image: user-backend:1.0
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`backend.localhost`)"
- "traefik.http.services.backend.loadbalancer.server.port=8082"
networks:
- user-net
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@RestController
@RequestMapping("/api/users")
@CrossOrigin(origins = "http://localhost:3001")
@CrossOrigin(origins = {"http://localhost:3001", "http://frontend.localhost"})
public class UserController {

@Autowired
Expand Down
2 changes: 2 additions & 0 deletions user-frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_URL=http://backend.localhost/api

3 changes: 3 additions & 0 deletions user-frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ COPY package*.json ./

RUN npm install

COPY .env ./

COPY . .

RUN npm run build
Expand All @@ -17,3 +19,4 @@ COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

Loading

0 comments on commit 2ab2858

Please sign in to comment.