-
-
Notifications
You must be signed in to change notification settings - Fork 2
66 lines (52 loc) · 1.89 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
name: Build and maybe deploy to dothq.org
on:
push:
branches: ["production", "staging"]
workflow_dispatch:
env:
SERVER_ID: "32657111668989263"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install dependencies
run: |
yarn
- name: Build
run: |
yarn build
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/production'
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Retrieve server hostname
run: |
TS_JSON=$(curl "https://api.tailscale.com/api/v2/device/${{ env.SERVER_ID }}" -u "${{ secrets.TS_KEY }}:")
HOSTNAME=$(echo $TS_JSON | jq -r '.name')
echo "SERVER_HOSTNAME=$HOSTNAME" >> $GITHUB_ENV
- name: Connect to Tailscale network
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
- name: Install SSH key
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.CI_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ env.SERVER_HOSTNAME }} > ~/.ssh/known_hosts
- name: Connect over SSH and deploy
run: |
ssh -t ci@${{ env.SERVER_HOSTNAME }} "cd /app && git pull && ./scripts/rebuild_docker.sh"
- name: Nuke SSH keys
run: rm -rf ~/.ssh