Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Test #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .env
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# frontend:
# frontend
PORT=8080
AUTH_API_ADDRESS=http://auth-api:8081
TODOS_API_ADDRESS=http://todos-api:8082
AUTH_API_ADDRESS=https://nemyred.xyz/api/auth
TODOS_API_ADDRESS=https://nemyred.xyz/api/todos

# auth-api:
# auth-api
AUTH_API_PORT=8081
JWT_SECRET=myfancysecret
USERS_API_ADDRESS=http://users-api:8083

# todos-api:
# todos-api
JWT_SECRET=myfancysecret
REDIS_HOST=redis-queue
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_CHANNEL=log_channel

# users-api:
# users-api
SERVER_PORT=8083
JWT_SECRET=myfancysecret

# log-message-processor:
REDIS_HOST=redis-queue
# log-message-processor
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_CHANNEL=log_channel

#login details
# login details (not valid environment variables - remove or handle separately)
# USERNAME PASSWORD
admin Admin123
hng HngTech
user Password
# admin Admin123
# hng HngTech
# user Password
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
letsencrypt/
14 changes: 14 additions & 0 deletions auth-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.21

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go build -o auth-api .

EXPOSE 8080

CMD ["./auth-api"]
134 changes: 134 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
version: '3.8'

services:
traefik:
image: traefik:v3.0
container_name: traefik
restart: always
command:
- "--configFile=/traefik.yml"
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./traefik.yml:/traefik.yml"
- "./letsencrypt:/letsencrypt"
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`nemyred.xyz`) && PathPrefix(`/dashboard`)"
- "traefik.http.routers.traefik.entrypoints=websecure"
- "traefik.http.routers.traefik.tls=true"
- "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
networks:
- web

frontend:
build: ./frontend
container_name: vue_frontend
expose:
- "80"
env_file:
- .env # Ensure .env with updated AUTH_API_ADDRESS is used
environment:
- NODE_ENV=production # Force production mode to use correct env
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend.rule=Host(`nemyred.xyz`)"
- "traefik.http.routers.frontend.entrypoints=websecure"
- "traefik.http.routers.frontend.tls=true"
- "traefik.http.routers.frontend.tls.certresolver=letsencrypt"
- "traefik.http.services.frontend.loadbalancer.server.port=80"
networks:
- web
depends_on:
- auth-api
- todos-api

auth-api:
build: ./auth-api
container_name: auth_api
expose:
- "8081"
env_file:
- .env
labels:
- "traefik.enable=true"
- "traefik.http.routers.auth.rule=Host(`nemyred.xyz`) && (PathPrefix(`/api/auth`) || PathPrefix(`/login`))" # Fallback for /login
- "traefik.http.routers.auth.entrypoints=websecure"
- "traefik.http.routers.auth.tls=true"
- "traefik.http.routers.auth.tls.certresolver=letsencrypt"
- "traefik.http.routers.auth.middlewares=auth-strip"
- "traefik.http.middlewares.auth-strip.stripprefix.prefixes=/api/auth" # Only strip /api/auth, not /login
- "traefik.http.services.auth.loadbalancer.server.port=8081"
networks:
- web
depends_on:
- users-api

todos-api:
build: ./todos-api
container_name: todos_api
expose:
- "8082"
env_file:
- .env
labels:
- "traefik.enable=true"
- "traefik.http.routers.todos.rule=Host(`nemyred.xyz`) && PathPrefix(`/api/todos`)"
- "traefik.http.routers.todos.entrypoints=websecure"
- "traefik.http.routers.todos.tls=true"
- "traefik.http.routers.todos.tls.certresolver=letsencrypt"
- "traefik.http.routers.todos.middlewares=todos-strip"
- "traefik.http.middlewares.todos-strip.stripprefix.prefixes=/api/todos"
- "traefik.http.services.todos.loadbalancer.server.port=8082"
networks:
- web
depends_on:
- redis

users-api:
build: ./users-api
container_name: users_api
expose:
- "8083"
env_file:
- .env
environment:
- SPRING_REDIS_HOST=redis
- SPRING_REDIS_PORT=6379
labels:
- "traefik.enable=true"
- "traefik.http.routers.users.rule=Host(`nemyred.xyz`) && PathPrefix(`/api/users`)"
- "traefik.http.routers.users.entrypoints=websecure"
- "traefik.http.routers.users.tls=true"
- "traefik.http.routers.users.tls.certresolver=letsencrypt"
- "traefik.http.routers.users.middlewares=users-strip"
- "traefik.http.middlewares.users-strip.stripprefix.prefixes=/api/users"
- "traefik.http.services.users.loadbalancer.server.port=8083"
networks:
- web
depends_on:
- redis

log-message-processor:
build: ./log-message-processor
container_name: log_processor
env_file:
- .env
networks:
- web
depends_on:
- redis

redis:
image: redis:alpine
container_name: devops-stage-4-redis-1
networks:
- web

networks:
web:
external: true
15 changes: 15 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:12 as build-stage

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

RUN npm run build

FROM nginx:alpine
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
17 changes: 17 additions & 0 deletions log-message-processor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.9

# Set the working directory
WORKDIR /app

# Copy the requirements file
COPY requirements.txt .

# Upgrade pip and install dependencies
RUN pip install --upgrade pip && \
pip install redis>=5.0.0 requests>=2.31.0 thriftpy2>=0.4.16 py_zipkin --upgrade

# Copy the application code
COPY . .

# Run the application
CMD ["python", "main.py"]
3 changes: 3 additions & 0 deletions log-message-processor/requirements_backup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
redis==2.10.6
py_zipkin==0.11.0
requests
12 changes: 12 additions & 0 deletions todos-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
31 changes: 31 additions & 0 deletions traefik.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
api:
dashboard: true
insecure: true # For testing only (not recommended for production)

entryPoints:
web:
address: ":80"
http:
redirections:
entryPoint:
to: websecure
scheme: https
websecure:
address: ":443"

providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
network: web # Ensure Traefik uses the correct Docker network

certificatesResolvers:
letsencrypt:
acme:
email: [email protected]
storage: /letsencrypt/acme.json
httpChallenge:
entryPoint: web

log:
level: DEBUG # Enable debug logs for troubleshooting
13 changes: 13 additions & 0 deletions users-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Build stage
FROM maven:3.8.4-openjdk-8 AS build-stage
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn package -DskipTests

# Run stage
FROM openjdk:8-jre-slim
WORKDIR /app
COPY --from=build-stage /app/target/users-api-0.0.1-SNAPSHOT.jar ./users-api.jar
EXPOSE 8083
CMD ["java", "-jar", "users-api.jar"]