-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (83 loc) · 2.92 KB
/
sorcery-vm.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
name: Sorcery VM deployment
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test ./src/Tests/Sorcery.UnitTests/Sorcery.UnitTests.csproj --no-build --verbosity normal
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Publish
run: dotnet publish -c Release -o ./release
- name: Compress artifact
run: tar -czvf sorcery.tar.gz -C ./release .
- name: Upload artifact
uses: actions/[email protected]
with:
name: sorcery
path: ./sorcery.tar.gz
if-no-files-found: error
deploy:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [build, publish]
steps:
- name: Download artifact
uses: actions/[email protected]
with:
name: sorcery
path: ./
- name: Query public IP
id: ip
uses: haythem/[email protected]
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.SORCERY_AZURE_CREDENTIALS }}
- name: Azure CLI - allow connections from worker
id: jitAllow
uses: azure/CLI@v1
with:
azcliversion: 2.34.1
inlineScript: |
az network nsg rule create -g ${{ secrets.SORCERY_AZURE_RG_NAME }} --nsg-name ${{ secrets.SORCERY_AZURE_NSG_NAME }} -n GitHubActionDeployJIT --priority 100 \
--source-address-prefixes ${{ steps.ip.outputs.ipv4 }} --destination-port-ranges 22 --direction Inbound --access Allow --protocol TCP
- name: Install SSH key
uses: shimataro/[email protected]
with:
key: ${{ secrets.SORCERY_VM_KEY }}
known_hosts: ${{ secrets.SORCERY_VM_KNOWN_HOSTS }}
- name: scp to Sorcery-VM
run: scp ./sorcery.tar.gz "${{ secrets.SORCERY_VM_USER }}@${{ secrets.SORCERY_VM_IP }}:/home/${{ secrets.SORCERY_VM_USER }}/server/release"
- name: Restart nginx via SSH
run: ssh "${{ secrets.SORCERY_VM_USER }}@${{ secrets.SORCERY_VM_IP }}" \
"sudo rm -rf /usr/share/nginx/sorcery/* && sudo tar -xzf /home/${{ secrets.SORCERY_VM_USER }}/server/release/sorcery.tar.gz -C /usr/share/nginx/sorcery . && sudo nginx -s reload"
- name: Azure CLI - remove JIT rule
if: always()
uses: azure/CLI@v1
with:
azcliversion: 2.34.1
inlineScript: |
az network nsg rule delete -g ${{ secrets.SORCERY_AZURE_RG_NAME }} --nsg-name ${{ secrets.SORCERY_AZURE_NSG_NAME }} -n GitHubActionDeployJIT