-
Notifications
You must be signed in to change notification settings - Fork 14
95 lines (84 loc) · 3.32 KB
/
deploy-cluster.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 cluster
on:
push:
branches: [main]
workflow_dispatch:
schedule:
- cron: '0 7 * * *'
jobs:
deploy-website-staging:
name: Deploy website to staging
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ./deploy.key
sudo chmod 600 ./deploy.key
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_MACHINE_USER_PRIVATE_KEY}}
SSH_HOST: ${{ secrets.SSH_HOST_STAGING_V2 }}
- name: Deploy website to staging
run: ssh -i ./deploy.key www-data@$SSH_HOST 'python3 /opt/scripts/app-deploy-release/deploy.py /opt/git/releases/annuaire-entreprises-site https://github.com/annuaire-entreprises-data-gouv-fr/site.git website --version main --versions_to_keep=5 1> >(tee --append /var/log/deploy_annuaire-entreprises-site)'
env:
SSH_HOST: ${{ secrets.SSH_HOST_STAGING_V2 }}
- name: Notify staging failure only
if: failure()
uses: ./.github/actions/notify
with:
message: '🚨 ${{ github.event.repository.name }} : deploy to staging failed'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}
deploy-website-production:
name: Deploy website to production
runs-on: ubuntu-latest
needs: [deploy-website-staging]
timeout-minutes: 15
strategy:
matrix:
include:
- environment: production-01
host: SSH_PRODUCTION_01
- environment: production-02
host: SSH_PRODUCTION_02
- environment: production-03
host: SSH_PRODUCTION_03
steps:
- uses: actions/checkout@v3
- name: Set up SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ./deploy.key
sudo chmod 600 ./deploy.key
ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_MACHINE_USER_PRIVATE_KEY}}
SSH_HOST: ${{ secrets[matrix.host] }}
- name: Deploy website to production
run: ssh -i ./deploy.key www-data@$SSH_HOST 'python3 /opt/scripts/app-deploy-release/deploy.py /opt/git/releases/annuaire-entreprises-site https://github.com/annuaire-entreprises-data-gouv-fr/site.git website --version main --versions_to_keep=5 | tee --append /var/log/deploy_annuaire-entreprises-site'
env:
SSH_HOST: ${{ secrets[matrix.host] }}
- name: Notify production failure only
if: failure()
uses: ./.github/actions/notify
with:
message: '🚨 ${{ github.event.repository.name }} [${{ matrix.environment }}] : deploy to production cluster failed'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}
notify-deploy-success:
name: Notify successful deployment
runs-on: ubuntu-latest
needs: [deploy-website-production]
steps:
- uses: actions/checkout@v3
- name: Notify deploy success
uses: ./.github/actions/notify
with:
message: '✅ ${{ github.event.repository.name }} : successfully deploy production cluster'
hook: ${{ secrets.TCHAP_HOOK }}
id: ${{ secrets.TCHAP_ROOM_ID }}