-
Notifications
You must be signed in to change notification settings - Fork 3
131 lines (112 loc) · 4.01 KB
/
cicd.yaml
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
name: CI/CD
on:
push:
pull_request:
permissions:
packages: write
jobs:
ci-build-test:
runs-on: ubuntu-latest
container: joshkeegan/dotnet-build:8.0.100
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: make publish-all
- name: Run Unit Tests
working-directory: test/UnitTests
run: make run
- name: Upload Artefacts
uses: actions/upload-artifact@v4
with:
name: ci-build-test-artefacts
path: |
artefacts
sharedScripts
src/StringSearch.Api.Host/Dockerfile
src/StringSearch.Api.Host/out
Makefile
if: ${{ always() }}
ci-docker:
runs-on: ubuntu-latest
needs: ci-build-test
outputs:
uniqueifier: ${{ steps.output_uniqueifier.outputs.uniqueifier }}
steps:
- name: Docker Login
if: github.ref == 'refs/heads/master'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download Artefacts
uses: actions/download-artifact@v4
with:
name: ci-build-test-artefacts
path: .
- name: Build Image
run: |
make \
build-api-image \
buildId="${{ github.run_number }}-${{ github.run_attempt }}" \
commitHash="${GITHUB_SHA:0:8}"
- name: Publish Image
if: github.ref == 'refs/heads/master'
run: make publish-api-image
- name: Output Uniqueifier
id: output_uniqueifier
run: echo "::set-output name=uniqueifier::`cat artefacts/uniqueifier`"
- name: Upload Artefacts
uses: actions/upload-artifact@v4
with:
name: ci-docker-artefacts
path: |
artefacts/deploy
artefacts/uniqueifier
sharedScripts
deploy-prod:
environment: prod
concurrency: deploy-prod
runs-on: ubuntu-latest
needs: ci-docker
if: github.ref == 'refs/heads/master'
container: joshkeegan/deploy-ssh:latest
steps:
- name: Download Artefacts
uses: actions/download-artifact@v4
with:
name: ci-docker-artefacts
path: .
# Must hardcode /root here because gh actions overrides $HOME for some bizarre reason :s
# https://github.com/actions/runner/issues/863
- name: Add SSH Private Key
run: echo "${{ secrets.SSH_PRIVATE_KEY }}" > /root/.ssh/id_rsa
# Debug step left here since deployments have randomly failed.
# Leaving this here for now since by the time I investigate the issue it fixes itself, so the next time
# it happens I want this output to be in the logs . . .
- name: Debug DNS
run: |
apk add bind-tools
dig ${{ secrets.HOSTNAME }}
getent ahosts ${{ secrets.HOSTNAME }}
- name: Copy Artefacts to Target
run: |
set -x
ssh ${{ secrets.USERNAME }}@${{ secrets.HOSTNAME }} -p ${{ secrets.SSH_PORT }} "mkdir -p ~/cd/prod/gh-actions/${{ needs.ci-docker.outputs.uniqueifier }}"
for l in `ls`; \
do \
scp -r -P ${{ secrets.SSH_PORT }} $PWD/$l ${{ secrets.USERNAME }}@${{ secrets.HOSTNAME }}:~/cd/prod/gh-actions/${{ needs.ci-docker.outputs.uniqueifier }} ; \
done
- name: Deploy
run: |
ssh ${{ secrets.USERNAME }}@${{ secrets.HOSTNAME }} -p ${{ secrets.SSH_PORT }} \
"cd ~/cd/prod/gh-actions/${{ needs.ci-docker.outputs.uniqueifier }}/artefacts/deploy && \
make \
rootPath=\"/home/josh/pisearch/pi_digits\" \
environment=\"prod\" \
appsettingsDir=\"/home/josh/pisearch/config\" \
hostname=\"${{ secrets.HOSTNAME }}\" \
deploy"
- name: Post-Deployment Tests
run: /bin/bash artefacts/deploy/runDeploymentTests.sh ${{ secrets.HOSTNAME }} 80