Skip to content

Commit ed22362

Browse files
committed
Merge branch 'main' into 23-setup-openapi-generated-client
# Conflicts: # client/Dockerfile
2 parents 80a6467 + be619cd commit ed22362

File tree

11 files changed

+529
-2
lines changed

11 files changed

+529
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build Docker Images
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
name: Run Java Tests
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- uses: actions/setup-java@v4
15+
with:
16+
java-version: '21'
17+
distribution: 'temurin'
18+
19+
- name: Setup Gradle
20+
uses: gradle/actions/setup-gradle@v4
21+
22+
- name: Build with Gradle
23+
run: cd server && gradle build
24+
25+
build:
26+
name: Build Docker Images
27+
needs: test
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
service: [client, server]
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Log in to the Container registry
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
with:
48+
platforms: all
49+
50+
- name: Install Docker Buildx
51+
id: buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Extract metadata (tags, labels) for Docker
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ghcr.io/${{ github.repository }}/${{ matrix.service }}
59+
tags: |
60+
type=raw,value=latest,enable={{is_default_branch}}
61+
type=ref,event=branch
62+
type=ref,event=pr
63+
64+
- name: Build and push Docker Image
65+
uses: docker/build-push-action@v5
66+
with:
67+
platforms: linux/amd64,linux/arm64
68+
context: ./${{ matrix.service }}
69+
file: ./${{ matrix.service }}/Dockerfile
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy Docker Images
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
environment:
10+
name: AWS
11+
url: 'https://client.${{ vars.EC2_PUBLIC_IP }}.nip.io'
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
16+
- name: Copy Docker Compose File From Repo to VM Host
17+
uses: appleboy/scp-action@v0.1.7
18+
with:
19+
host: ${{ vars.EC2_PUBLIC_IP }}
20+
username: ${{ vars.AWS_EC2_USER }}
21+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
22+
source: "./compose.aws.yml"
23+
target: /home/${{ vars.AWS_EC2_USER }}
24+
25+
- name: SSH to VM and Create .env.prod
26+
uses: appleboy/ssh-action@v1.0.3
27+
with:
28+
host: ${{ vars.EC2_PUBLIC_IP }}
29+
username: ${{ vars.AWS_EC2_USER }}
30+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
31+
script: |
32+
rm .env.prod
33+
touch .env.prod
34+
echo "CLIENT_HOST=client.${{ vars.EC2_PUBLIC_IP }}.nip.io" >> .env.prod
35+
echo "SERVER_HOST=api.${{ vars.EC2_PUBLIC_IP }}.nip.io" >> .env.prod
36+
echo "PUBLIC_API_URL=https://api.${{ vars.EC2_PUBLIC_IP }}.nip.io/api" >> .env.prod
37+
38+
- name: SSH to VM and Execute Docker-Compose Up
39+
uses: appleboy/ssh-action@v1.0.3
40+
with:
41+
host: ${{ vars.EC2_PUBLIC_IP }}
42+
username: ${{ vars.AWS_EC2_USER }}
43+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
44+
script: |
45+
echo "Logging into Docker registry..."
46+
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
47+
echo "Starting Docker Compose..."
48+
docker compose -f compose.aws.yml --env-file=.env.prod up --pull=always -d

client/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ WORKDIR /app
2828
ENV NODE_ENV=production
2929

3030
# Copy only essential files
31-
COPY --from=builder /app/public ./public
3231
COPY --from=builder /app/.next ./.next
3332
COPY --from=builder /app/node_modules ./node_modules
3433
COPY --from=builder /app/package.json ./package.json

client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next
3131

3232
## Deploy on Vercel
3333

34+
3435
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
3536

3637
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

compose.aws.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
services:
2+
reverse-proxy:
3+
image: traefik:v3.4
4+
command:
5+
- "--providers.docker=true"
6+
- "--providers.docker.exposedByDefault=false"
7+
- "--entrypoints.web.address=:80"
8+
- "--entrypoints.websecure.address=:443"
9+
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
10+
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
11+
- "--certificatesresolvers.letsencrypt.acme.httpchallenge=true"
12+
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
13+
- "--certificatesresolvers.letsencrypt.acme.email=admin@tum.de"
14+
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
15+
restart: unless-stopped
16+
ports:
17+
- "80:80"
18+
- "443:443"
19+
volumes:
20+
- /var/run/docker.sock:/var/run/docker.sock
21+
- ./letsencrypt:/letsencrypt
22+
23+
server:
24+
image: ghcr.io/aet-devops25/team-server-down/server:latest
25+
environment:
26+
DB_HOST: ${DB_HOST:-db}
27+
DB_PORT: ${DB_PORT:-5432}
28+
DB_NAME: ${DB_NAME:-postgres}
29+
DB_USER: ${DB_USER:-postgres}
30+
DB_PASSWORD: ${DB_PASSWORD:-postgres}
31+
depends_on:
32+
db:
33+
condition: service_healthy
34+
restart: unless-stopped
35+
networks:
36+
- server
37+
labels:
38+
- "traefik.enable=true"
39+
- "traefik.http.routers.server.rule=Host(`${SERVER_HOST}`)"
40+
- "traefik.http.services.server.loadbalancer.server.port=8080"
41+
- "traefik.http.routers.server.entrypoints=websecure"
42+
- "traefik.http.routers.server.tls.certresolver=letsencrypt"
43+
44+
client:
45+
image: ghcr.io/aet-devops25/team-server-down/client:latest
46+
environment:
47+
- PUBLIC_API_URL=${PUBLIC_API_URL}
48+
depends_on:
49+
- server
50+
restart: unless-stopped
51+
labels:
52+
- "traefik.enable=true"
53+
- "traefik.http.routers.client.rule=Host(`${CLIENT_HOST}`)"
54+
- "traefik.http.services.client.loadbalancer.server.port=3000"
55+
- "traefik.http.routers.client.entrypoints=websecure"
56+
- "traefik.http.routers.client.tls.certresolver=letsencrypt"
57+
- "traefik.http.middlewares.client-compress.compress=true"
58+
- "traefik.http.routers.client.middlewares=client-compress"
59+
- "traefik.http.routers.client.priority=1"
60+
61+
db:
62+
image: postgres:16.2-bullseye
63+
restart: unless-stopped
64+
environment:
65+
POSTGRES_USER: postgres
66+
POSTGRES_PASSWORD: postgres
67+
healthcheck:
68+
test: [ "CMD-SHELL", "sh -c 'pg_isready -U postgres -d postgres'" ]
69+
interval: 10s
70+
timeout: 3s
71+
retries: 3
72+
ports:
73+
- "5432:5432"
74+
volumes:
75+
- db-data:/var/lib/postgresql/data
76+
networks:
77+
- server
78+
79+
volumes:
80+
db-data:
81+
82+
networks:
83+
server:
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
- hosts: all
2+
become: true
3+
vars:
4+
container_count: 4
5+
default_container_name: docker
6+
default_container_image: ubuntu
7+
default_container_command: sleep 1
8+
9+
- name: Install Docker, Docker Compose
10+
hosts: all
11+
become: true
12+
tasks:
13+
- name: Install aptitude
14+
apt:
15+
name: aptitude
16+
state: latest
17+
update_cache: true
18+
19+
- name: Install required system packages
20+
apt:
21+
pkg:
22+
- apt-transport-https
23+
- ca-certificates
24+
- curl
25+
- software-properties-common
26+
- python3-pip
27+
- virtualenv
28+
- python3-setuptools
29+
state: latest
30+
update_cache: true
31+
32+
- name: Add Docker GPG apt Key
33+
apt_key:
34+
url: https://download.docker.com/linux/ubuntu/gpg
35+
state: present
36+
37+
- name: Add Docker Repository
38+
apt_repository:
39+
repo: deb https://download.docker.com/linux/ubuntu focal stable
40+
state: present
41+
42+
- name: Update apt and install docker-ce
43+
apt:
44+
name: docker-ce
45+
state: latest
46+
update_cache: true
47+
48+
- name: Install Docker module for Python
49+
apt:
50+
name: python3-docker
51+
state: present
52+
become: true
53+
54+
- name: Start docker daemon
55+
systemd:
56+
name: docker
57+
state: started
58+
59+
- name: Create a new Linux User
60+
hosts: all
61+
become: yes
62+
tasks:
63+
- name: Create new Linux User
64+
user:
65+
name: teamserverdown
66+
groups: adm,docker
67+
append: yes
68+
69+
- name: Reconnect to server session
70+
meta: reset_connection
71+
72+
- name: Start Project
73+
hosts: all
74+
become: yes
75+
tasks:
76+
- name: Clone GitHub repository
77+
git:
78+
repo: https://github.com/AET-DevOps25/team-server-down
79+
dest: /home/ubuntu/team-server-down/
80+
clone: yes
81+
update: yes
82+
83+
- name: Get the public IP address of the network.
84+
uri:
85+
url: https://api.ipify.org?format=json
86+
method: Get
87+
changed_when: false
88+
register: public_ip
89+
until: public_ip.status == 200
90+
retries: 6
91+
delay: 10
92+
93+
- name: Create .env.prod
94+
ansible.builtin.shell: |
95+
cd team-server-down
96+
rm .env.prod
97+
touch .env.prod
98+
echo "CLIENT_HOST=client.{{ public_ip.json.ip }}.nip.io" >> .env.prod
99+
echo "SERVER_HOST=api.{{ public_ip.json.ip }}.nip.io" >> .env.prod
100+
echo "PUBLIC_API_URL=https://api.{{ public_ip.json.ip }}.nip.io/api" >> .env.prod
101+
102+
- name: Start Container
103+
community.docker.docker_compose_v2:
104+
project_src: /home/ubuntu/team-server-down
105+
files: compose.aws.yml
106+
env_files: .env.prod
107+
register: output
108+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# Crash log files
9+
crash.log
10+
crash.*.log
11+
12+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
13+
# password, private keys, and other secrets. These should not be part of version
14+
# control as they are data points which are potentially sensitive and subject
15+
# to change depending on the environment.
16+
*.tfvars
17+
*.tfvars.json
18+
19+
# Ignore override files as they are usually used to override resources locally and so
20+
# are not checked in
21+
override.tf
22+
override.tf.json
23+
*_override.tf
24+
*_override.tf.json
25+
26+
# Include override files you do wish to add to version control using negated pattern
27+
# !example_override.tf
28+
29+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
30+
# example: *tfplan*
31+
32+
# Ignore CLI configuration files
33+
.terraformrc
34+
terraform.rc

0 commit comments

Comments
 (0)