-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (50 loc) · 1.83 KB
/
main.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
name: Continuous Build
on:
push:
branches:
- main
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
only_build:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag api3tracker:latest
build_deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_REMOTE_PATH: /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod
steps:
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: /dev/null
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag api3tracker:latest
- name: Push main Docker image
run: docker save api3tracker:latest | bzip2 | ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null $SSH_HOST 'bunzip2 -d | docker load'
- name: Apply Terraform plan
run: |
echo "::add-mask::$TF_VAR_API3TRACKER_ENDPOINT"
echo "::add-mask::$TF_VAR_API3TRACKER_ARCHIVE_ENDPOINT"
export REMOTE_CMD="cd $SSH_REMOTE_PATH && git pull && terraform init && terraform apply -auto-approve && docker system prune -af"
ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/dev/null $SSH_HOST bash -c '"'$REMOTE_CMD'"'