-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (69 loc) · 2.51 KB
/
Copy pathdeploy.yml
File metadata and controls
77 lines (69 loc) · 2.51 KB
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
name: Build and Deploy
on:
push:
branches:
- master
env:
REGISTRY: ghcr.io
IMAGE_NAME_API: hypnoastic/teamgraph-api
IMAGE_NAME_WEB: hypnoastic/teamgraph-web
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push API image
uses: docker/build-push-action@v5
with:
context: .
file: apps/api/Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_API }}:latest
- name: Build and push Web image
uses: docker/build-push-action@v5
with:
context: .
file: apps/web/Dockerfile
build-args: |
API_TARGET=http://api:8000
NEXT_PUBLIC_API_BASE_URL=/api
NEXT_PUBLIC_GOOGLE_CLIENT_ID=363093052470-govsjs7tl9dd1a4rvehhmi8hf4vrpv1c.apps.googleusercontent.com
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_WEB }}:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
command_timeout: 15m
script: |
set -euo pipefail
if [ ! -d ~/teamgraph/.git ]; then
rm -rf ~/teamgraph
git clone --depth 1 https://github.com/hypnoastic/TeamGraph-AI.git ~/teamgraph
fi
cd ~/teamgraph
git fetch origin master
git reset --hard origin/master
echo '${{ secrets.PROD_ENV }}' > .env
echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > google-credentials.json
echo "${{ secrets.GITHUB_TOKEN }}" | sudo docker login ghcr.io -u ${{ github.actor }} --password-stdin
sudo docker compose -f docker-compose.prod.yml --env-file .env pull api web
sudo docker compose -f docker-compose.prod.yml --env-file .env up -d --no-build --pull missing api web nginx
sudo docker compose -f docker-compose.prod.yml --env-file .env restart nginx
sudo docker image prune -f --filter "until=72h" || true