-
Notifications
You must be signed in to change notification settings - Fork 34
132 lines (115 loc) · 4.16 KB
/
production.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Build and deploy to server
on:
push:
branches: ["master"]
paths-ignore:
- ".github/**"
- ".docs/**"
workflow_dispatch:
inputs:
hash:
description: "Docs Staging Hash"
type: string
default: main
required: true
fallback:
description: "Fallback by hash"
type: boolean
default: false
required: false
concurrency: ci-prod
jobs:
build:
runs-on: ubuntu-latest
name: Build website
steps:
- name: Check disk usage
run: df -h
- name: Remove unused Docker images
run: docker system prune -af
- uses: actions/checkout@v3
with:
ref: "master"
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"
- name: Update submodule
id: submodule
run: |
git submodule init
git submodule update --remote
cd docs
git checkout main
cd ..
echo "submodule_sha=$(git submodule status | awk '{print $1}' | sed -r 's/[+-]+//g')" >> $GITHUB_OUTPUT
echo "submodule_status=$(git submodule status)" >> $GITHUB_OUTPUT
echo "git_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "build_date=$(date)" >> $GITHUB_OUTPUT
- name: Install deps
run: yarn
- name: Calc gatsby cache key
id: calc-cache-key
run: |
if ${{ !!inputs.fallback }}
then
echo "key=${{ inputs.hash }}" >> $GITHUB_OUTPUT
else
echo "key=${{ steps.submodule.outputs.submodule_sha }}" >> $GITHUB_OUTPUT
fi
- name: Restore gatsby cache
uses: actions/cache@v3
id: gatsby-cache
with:
path: |
.cache
public
key: ${{ runner.os }}-gatsby-cache-docs-staging-${{ steps.calc-cache-key.outputs.key }}
restore-keys: |
${{ runner.os }}-gatsby-cache-docs-staging-
- name: Clean up temporary files
run: |
sudo rm -rf /tmp/*
sudo rm -rf /home/runner/work/_temp/*
- name: Build website
if: ${{ !inputs.fallback || (steps.gatsby-cache.outputs.cache-hit != 'true') }}
env:
CI: true
GATSBY_ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
GATSBY_ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
GATSBY_DOC_BUILD_DATE: ${{ steps.submodule.outputs.build_date }}
GATSBY_DOC_BUILD_GIT_SHA: ${{ steps.submodule.outputs.git_sha }}
GATSBY_DOC_BUILD_SUBMODULE_SHA: ${{ steps.submodule.outputs.submodule_status }}
run: |
yarn build --verbose
- name: Check output
id: check-output
run: |
sudo apt install tree
tree public
- name: Set known_hosts
id: known-hosts
run: |
echo "BJ_PROXY=$(ssh-keyscan -H ${{ secrets.BJ_PROXY_HOST }})" >> $GITHUB_OUTPUT
echo "LA1=$(ssh-keyscan -H ${{ secrets.LA_1_HOST }})" >> $GITHUB_OUTPUT
echo "LA2=$(ssh-keyscan -H ${{ secrets.LA_2_HOST }})" >> $GITHUB_OUTPUT
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: |
${{ steps.known-hosts.outputs.BJ_PROXY }}
${{ steps.known-hosts.outputs.LA1 }}
${{ steps.known-hosts.outputs.LA2 }}
- name: Deploy to LA1
run: |
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_1_HOST }}:${{ secrets.DEPLOY_PATH }}"
- name: Deploy to LA2
run: |
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_2_HOST }}:${{ secrets.DEPLOY_PATH }}"
- name: Deploy to BJ1
run: |
rsync -avz --delete -e 'ssh -p ${{ secrets.BJ_1_PROXY_PORT }} -o StrictHostKeyChecking=no' public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_PROXY_HOST }}:${{ secrets.DEPLOY_PATH }}"
- name: Deploy to BJ2
run: |
rsync -avz --delete -e 'ssh -p ${{ secrets.BJ_2_PROXY_PORT }} -o StrictHostKeyChecking=no' public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_PROXY_HOST }}:${{ secrets.DEPLOY_PATH }}"