-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (117 loc) · 5.93 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Deploy Angelos Server
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Set up QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Set up Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build & Push Docker Image
- name: Build and Push Angelos Server
uses: docker/build-push-action@v6
with:
platforms: linux/amd64, linux/arm64
file: ./Dockerfile
context: .
tags: ghcr.io/ls1intum/angelos-server:latest
push: true
no-cache: true
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Copy docker-compose.yml to the VM
- name: Copy Docker Compose to VM
uses: appleboy/[email protected]
with:
host: ${{ vars.VM_HOST }}
username: ${{ vars.VM_USERNAME }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
source: "./docker-compose.yml"
target: "/home/${{ vars.VM_USERNAME }}/${{ github.repository }}"
debug: true
# Create .env file on VM
- name: Create .env on VM
uses: appleboy/[email protected]
with:
host: ${{ vars.VM_HOST }}
username: ${{ vars.VM_USERNAME }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
script: |
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" > /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "MAIL_USERNAME=${{ secrets.MAIL_USERNAME }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "UPLOAD_DIR=${{ vars.UPLOAD_DIR }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ADMIN_MAIL=${{ secrets.ADMIN_MAIL }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ADMIN_PASSWORD=${{ secrets.ADMIN_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "KB_ORIGIN=${{ secrets.KB_ORIGIN }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "CHATBOT_ORIGIN=${{ secrets.CHATBOT_ORIGIN }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ANGELOS_URL=${{ secrets.ANGELOS_URL }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ANGELOS_SECRET=${{ secrets.ANGELOS_SECRET }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ANGELOS_USERNAME=${{ secrets.ANGELOS_USERNAME }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "ANGELOS_PASSWORD=${{ secrets.ANGELOS_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "EUNOMNIA_URL=${{ secrets.EUNOMNIA_URL }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
echo "EUNOMNIA_SECRET=${{ secrets.EUNOMNIA_SECRET }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env
# Create .env.postgres file for Postgres on VM
- name: Create .env.postgres on VM
uses: appleboy/[email protected]
with:
host: ${{ vars.VM_HOST }}
username: ${{ vars.VM_USERNAME }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
script: |
echo "POSTGRES_USER=${{ secrets.DB_USERNAME }}" > /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env.postgres
echo "POSTGRES_PASSWORD=${{ secrets.DB_PASSWORD }}" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env.postgres
echo "POSTGRES_DB=kbdatabase" >> /home/${{ vars.VM_USERNAME }}/${{ github.repository }}/.env.postgres
# Run Docker Compose on VM
- name: SSH to VM and Compose Up
uses: appleboy/[email protected]
with:
host: ${{ vars.VM_HOST }}
username: ${{ vars.VM_USERNAME }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
proxy_host: ${{ vars.DEPLOYMENT_GATEWAY_HOST }}
proxy_username: ${{ vars.DEPLOYMENT_GATEWAY_USER }}
proxy_key: ${{ secrets.DEPLOYMENT_GATEWAY_SSH_KEY }}
proxy_port: ${{ vars.DEPLOYMENT_GATEWAY_PORT }}
script: |
cd /home/${{ vars.VM_USERNAME }}/${{ github.repository }}
# Ensure network
if ! docker network inspect angelos-network >/dev/null 2>&1; then
docker network create angelos-network
fi
# Start up containers
docker compose up --build -d --force-recreate --remove-orphans
docker ps