-
Notifications
You must be signed in to change notification settings - Fork 3
95 lines (77 loc) · 2.91 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
name: "Deploy"
on:
workflow_run:
workflows: ["Build and push packages"]
branches:
- "master"
- "*.*.*"
types:
- completed
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
SEMVER_REGEX: ^\d.\d.\d+(?:-(\w)+(:?.\d+)?)?$
jobs:
stop:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Stop
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker stop $(docker ps -f name=pe-testnet-api -q) || true
docker stop $(docker ps -f name=pe-testnet-indexer -q) || true
docker rm pe-testnet-api pe-testnet-indexer || true
drop_db:
runs-on: ubuntu-latest
needs: stop
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: REGEX
uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.event.workflow_run.head_branch }}
regex: ${{env.SEMVER_REGEX}}
- name: Drop database
if: ${{steps.regex-match.outputs.match != ''}}
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
git -C ./platform-explorer pull
docker pull owl352/refinery_cli_docker
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api
docker run --rm --env-file testnet.env ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api npm run db:drop
docker run --rm --env-file testnet.env -v ./platform-explorer/packages/indexer/migrations:/migrations owl352/refinery_cli_docker ./refinery migrate -e DATABASE_URL -p /migrations
start:
runs-on: ubuntu-latest
needs: drop_db
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Deploy to the server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
git -C ./platform-explorer pull
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:indexer
docker run -d -p 3005:3005 --restart always --env-file testnet.env --name pe-testnet-api ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api
sleep 3
docker run -d --env-file testnet.env --restart always --name pe-testnet-indexer ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:indexer ./indexer