-
Notifications
You must be signed in to change notification settings - Fork 4
81 lines (70 loc) · 3.08 KB
/
build_and_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
name: Deploy LEMS
on:
release:
types: [released]
env:
REGISTRY: 'registry.digitalocean.com/first-israel-registry'
IMAGE_TAG: ${{ github.ref_name }}
DIGITALOCEAN_KEY: ${{ secrets.DIGITALOCEAN_KEY }}
DIGITALOCEAN_SECRET: ${{ secrets.DIGITALOCEAN_SECRET }}
DIGITALOCEAN_ENDPOINT: ${{ vars.DIGITALOCEAN_ENDPOINT }}
DIGITALOCEAN_SPACE: ${{ vars.DIGITALOCEAN_SPACE }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
MONGO_CA_CERTIFICATE: ${{ secrets.MONGO_CA_CERTIFICATE }}
BASE_URL: ${{ vars.BASE_URL }}
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL }}
WS_URL: ${{ vars.WS_URL }}
NEXT_PUBLIC_WS_URL: ${{ vars.NEXT_PUBLIC_WS_URL }}
RECAPTCHA: ${{ vars.RECAPTCHA }}
RECAPTCHA_SECRET_KEY: ${{ secrets.RECAPTCHA_SECRET_KEY }}
RECAPTCHA_SITE_KEY: ${{ secrets.RECAPTCHA_SITE_KEY }}
NEXT_PUBLIC_RECAPTCHA_SITE_KEY: ${{ secrets.RECAPTCHA_SITE_KEY }}
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Install Node Modules
run: npm ci
- name: LEMS Build
run: npm run build
- name: Build container image
run: docker compose build
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Log in to DigitalOcean Container Registry with short-lived credentials
run: doctl registry login --expiry-seconds 600
- name: Remove all old images
run: |
if doctl registry repository list-tags lems-frontend | grep -o "sha.*"; then
doctl registry repository delete-manifest lems-frontend $(doctl registry repository list-tags lems-frontend | grep -o "sha.*") --force
fi
if doctl registry repository list-tags lems-backend | grep -o "sha.*"; then
doctl registry repository delete-manifest lems-backend $(doctl registry repository list-tags lems-backend | grep -o "sha.*") --force
fi
- name: Push image to DigitalOcean Container Registry
run: docker compose push
deploy:
runs-on: ubuntu-latest
needs: build_and_push
steps:
- name: Deploy to Digital Ocean droplet via SSH action
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
passphrase: ${{ secrets.PASSPHRASE }}
envs: REGISTRY,IMAGE_TAG,DIGITALOCEAN_KEY,DIGITALOCEAN_SECRET,DIGITALOCEAN_ENDPOINT,DIGITALOCEAN_SPACE,JWT_SECRET,MONGODB_URI,MONGO_CA_CERTIFICATE,BASE_URL,NEXT_PUBLIC_BASE_URL,WS_URL,NEXT_PUBLIC_WS_URL,RECAPTCHA,RECAPTCHA_SECRET_KEY,RECAPTCHA_SITE_KEY,{{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
script: |
docker login -u ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} -p ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} registry.digitalocean.com
cd lems
docker compose down
docker compose rm
git reset --hard origin/main
git pull origin main
docker compose up -d