Skip to content
Closed
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
116 changes: 103 additions & 13 deletions compose.aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,91 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- ./letsencrypt:/letsencrypt

keycloak:
restart: always
image: quay.io/keycloak/keycloak:24.0.1
command:
- start-dev
- --import-realm
- --transaction-xa-enabled=false
depends_on:
db:
condition: service_healthy
environment:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://db:5432/keycloak
KC_DB_USERNAME: postgres
KC_DB_PASSWORD: password
KC_HOSTNAME: ${KEYCLOAK_HOST}
KC_PROXY: edge
KC_PROXY_HEADERS: xforwarded
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: password
KC_HTTP_ENABLED: true
KC_HOSTNAME_STRICT: false
KC_HEALTH_ENABLED: true
volumes:
- ./docker/keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro
networks:
- server
labels:
- "traefik.enable=true"
- "traefik.http.routers.keycloak.rule=Host(`${KEYCLOAK_HOST}`)"
- "traefik.http.services.keycloak.loadbalancer.server.port=8080"
- "traefik.http.routers.keycloak.entrypoints=websecure"
- "traefik.http.routers.keycloak.tls.certresolver=letsencrypt"

server:
image: ghcr.io/aet-devops25/team-server-down/server:latest
restart: always
image: ghcr.io/aet-devops25/team-server-down/server:aws-deployment
environment:
DB_HOST: ${DB_HOST:-db}
DB_PORT: ${DB_PORT:-5432}
DB_NAME: ${DB_NAME:-postgres}
DB_USER: ${DB_USER:-postgres}
DB_PASSWORD: ${DB_PASSWORD:-postgres}
ALLOWED_ORIGIN: ${ALLOWED_ORIGIN:-http://localhost:3000}
IDP_INTERNAL_URI: ${IDP_INTERNAL_URI:-http://keycloak:8080/realms/development}
IDP_EXTERNAL_URI: ${IDP_EXTERNAL_URI:-http://localhost:8080/realms/development}
SERVER_URL: ${SERVER_URL:-http://localhost:9091}
depends_on:
db:
condition: service_healthy
restart: unless-stopped
networks:
- server
labels:
- "traefik.enable=true"
- "traefik.http.routers.server.rule=Host(`${SERVER_HOST}`)"
- "traefik.http.services.server.loadbalancer.server.port=8080"
- "traefik.http.services.server.loadbalancer.server.port=9091"
- "traefik.http.routers.server.entrypoints=websecure"
- "traefik.http.routers.server.tls.certresolver=letsencrypt"

client:
image: ghcr.io/aet-devops25/team-server-down/client:latest
realtime:
restart: always
image: ghcr.io/aet-devops25/team-server-down/realtime:aws-deployment
environment:
- NEXT_PUBLIC_API_URL=${PUBLIC_API_URL}
- NEXT_PUBLIC_GENAI_URL=${PUBLIC_GENAI_URL}
depends_on:
REDIS_HOST: ${REDIS_HOST:-redis}
REDIS_PORT: ${REDIS_PORT:-6379}
volumes:
- ./realtime:/app
networks:
- server
restart: unless-stopped

client:
restart: always
image: ghcr.io/aet-devops25/team-server-down/client:aws-deployment
entrypoint: npm run start
environment:
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:9091}
NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_API_URL:-http://localhost:3000}
NEXT_PUBLIC_GENAI_URL: ${NEXT_PUBLIC_GENAI_URL:-http://localhost:8000}
NEXT_PUBLIC_REALTIME_URL: ${NEXT_PUBLIC_REALTIME_URL:-ws://localhost:9090}
NEXTAUTH_URL: ${NEXTAUTH_URL:-http://localhost:3000/api/auth/}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET:-feZJWB3mcQ93VBmqHKQI5er5NEIxcDPb3wtT/KaLB9s=}
KEYCLOAK_CLIENT_ID: ${KEYCLOAK_CLIENT_ID:-webclient}
KEYCLOAK_ISSUER: ${KEYCLOAK_ISSUER:-http://keycloak:8080/realms/development}
KEYCLOAK_END_SESSION_ENDPOINT: ${KEYCLOAK_END_SESSION_ENDPOINT:-http://keycloak:8080/realms/development/protocol/openid-connect/logout}
KEYCLOAK_CLIENT_SECRET: ${KEYCLOAK_CLIENT_SECRET:-SXiMvr1GG10bk2J63ODZC9SOaoAZ4dbe}
labels:
- "traefik.enable=true"
- "traefik.http.routers.client.rule=Host(`${CLIENT_HOST}`)"
Expand All @@ -70,16 +126,50 @@ services:
interval: 10s
timeout: 3s
retries: 3
ports:
- "5432:5432"
volumes:
- /mnt/ebs/db-data:/var/lib/postgresql/data
networks:
- server

volumes:
db-data:
redis:
image: redis:8.0.3-alpine
healthcheck:
test: [ "CMD-SHELL", "redis-cli ping | grep PONG" ]
interval: 1s
timeout: 3s
retries: 5
command:
- redis-server
volumes:
- redis-data:/data
networks:
- server

genai:
restart: always
image: ghcr.io/aet-devops25/team-server-down/genai:aws-deployment
environment:
OPEN_WEB_UI_API_KEY: sk-7eb81f98e32f48aaa59b315f73485aaa
SERVER_URL: ${SERVER_URL:-http://localhost:9091}
CLIENT_URL: ${CLIENT_URL:-http://localhost:3000}
GENAI_URL: ${GENAI_URL:-http://localhost:8000}
API_URL: ${API_URL:-https://gpu.aet.cit.tum.de/api/chat/completions}
volumes:
- ./genai:/app
networks:
- server
labels:
- "traefik.enable=true"
- "traefik.http.routers.genai.rule=Host(`${GENAI_HOST}`)"
- "traefik.http.services.genai.loadbalancer.server.port=8000"
- "traefik.http.routers.genai.entrypoints=websecure"
- "traefik.http.routers.genai.tls.certresolver=letsencrypt"

networks:
server:

volumes:
db-data:
node-modules-client:
redis-data:
redis-insight-data:
5 changes: 5 additions & 0 deletions infrastructure/ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
git:
repo: https://github.com/AET-DevOps25/team-server-down
dest: /home/ubuntu/team-server-down/
version: develop
clone: yes
update: yes

Expand All @@ -98,6 +99,10 @@
echo "CLIENT_HOST=client.{{ public_ip.json.ip }}.nip.io" >> .env.prod
echo "SERVER_HOST=api.{{ public_ip.json.ip }}.nip.io" >> .env.prod
echo "PUBLIC_API_URL=https://api.{{ public_ip.json.ip }}.nip.io/api" >> .env.prod
echo "REDISINSIGHT_HOST=redisinsight.{{ public_ip.json.ip }}.nip.io" >> .env.prod
echo "GENAI_HOST=genai.{{ public_ip.json.ip }}.nip.io" >> .env.prod
echo "KEYCLOAK_HOST=keycloak.{{ public_ip.json.ip }}.nip.io" >> .env.prod


- name: Start Container
community.docker.docker_compose_v2:
Expand Down
32 changes: 16 additions & 16 deletions infrastructure/terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 49 additions & 13 deletions infrastructure/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ variable avail_zone {}
variable env_prefix {}
variable instance_type {}
variable ssh_key {}
# variable my_ip {}
variable ssh_private_key{}


resource "aws_vpc" "teamserverdown-vpc" {
cidr_block = var.vpc_cidr_block
tags = {
Expand Down Expand Up @@ -87,45 +87,81 @@ resource "aws_route_table_association" "a-rtb-subnet" {
route_table_id = aws_route_table.teamserverdown-route-table.id
}

resource "aws_key_pair" "ssh-key" {
key_name = "teamserverdown-key"
public_key = file(var.ssh_key)
# resource "aws_key_pair" "ssh-key" {
# key_name = "teamserverdown-key"
# public_key = file(var.ssh_key)
# }

resource "aws_ebs_volume" "teamserverdown_volume" {
availability_zone = var.avail_zone
size = 10
tags = {
Name = "${var.env_prefix}-ebs-volume"
}
}

output "server-ip" {
value = aws_instance.teamserverdown-server.public_ip
resource "aws_volume_attachment" "teamserverdown_attachment" {
device_name = "/dev/xvdf"
volume_id = aws_ebs_volume.teamserverdown_volume.id
instance_id = aws_instance.teamserverdown-server.id
force_detach = true
}


resource "aws_instance" "teamserverdown-server" {
ami = "ami-084568db4383264d4"
instance_type = var.instance_type
key_name = "teamserverdown-key"
associate_public_ip_address = true
subnet_id = aws_subnet.teamserverdown-subnet-1.id
vpc_security_group_ids = [aws_security_group.teamserverdown-sg.id]
availability_zone = var.avail_zone

user_data = <<-EOF
#!/bin/bash
until ls /dev/xvdf; do sleep 1; done

file -s /dev/xvdf | grep ext4 || mkfs.ext4 /dev/xvdf

mkdir -p /mnt/data
mount /dev/xvdf /mnt/data

echo '/dev/xvdf /mnt/data ext4 defaults,nofail 0 2' >> /etc/fstab
EOF


tags = {
Name = "${var.env_prefix}-server"
}
}

resource "aws_eip" "teamserverdown_eip" {
}

resource "aws_eip_association" "eip_assoc" {
instance_id = aws_instance.teamserverdown-server.id
allocation_id = aws_eip.teamserverdown_eip.id
}

output "static_public_ip" {
value = aws_eip.teamserverdown_eip.public_ip
}

resource "null_resource" "wait_for_ssh" {
depends_on = [aws_instance.teamserverdown-server]
depends_on = [aws_eip_association.eip_assoc]

provisioner "local-exec" {
command = "bash -c 'until nc -zv ${aws_instance.teamserverdown-server.public_ip} 22; do sleep 5; done'"
command = "bash -c 'until nc -zv ${aws_eip.teamserverdown_eip.public_ip} 22; do sleep 5; done'"
}
}

resource "null_resource" "configure_server" {
depends_on = [null_resource.wait_for_ssh]

triggers = {
trigger = aws_instance.teamserverdown-server.public_ip
trigger = aws_eip.teamserverdown_eip.public_ip
}
provisioner "local-exec" {
working_dir = "/Users/leonliang/tum-informatik/SS25/DevOps/team-server-down/infrastructure/ansible"
command = "ansible-playbook --inventory ${aws_instance.teamserverdown-server.public_ip}, --private-key ${var.ssh_private_key} --user ubuntu playbook.yml --ssh-extra-args='-o StrictHostKeyChecking=no'"
working_dir = "/Users/leon.liang/Downloads/team-server-down/infrastructure/ansible"
command = "ansible-playbook --inventory ${aws_eip.teamserverdown_eip.public_ip}, --private-key ${var.ssh_private_key} --user ubuntu playbook.yml --ssh-extra-args='-o StrictHostKeyChecking=no'"
}
}
}
5 changes: 2 additions & 3 deletions infrastructure/terraform/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ subnet_1_cidr_block = "10.0.0.0/24"
avail_zone = "us-east-1a"
env_prefix = "dev"
instance_type = "t2.micro"
ssh_key = "/Users/leonliang/.ssh/teamserverdown.pub"
# my_ip = "your IP"
ssh_private_key = "/Users/leonliang/.ssh/teamserverdown"
ssh_key = "/Users/leon.liang/.ssh/teamserverdown.pub"
ssh_private_key = "/Users/leon.liang/.ssh/teamserverdown"
Loading