-
Notifications
You must be signed in to change notification settings - Fork 10
183 lines (161 loc) · 5.26 KB
/
ci-build.yml
File metadata and controls
183 lines (161 loc) · 5.26 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
types: [ opened, reopened, synchronize ]
workflow_call:
inputs:
platforms:
description: 'Platforms to build for'
required: false
type: string
latest:
description: 'Tag image as latest'
required: false
type: boolean
default: false
push:
description: 'Push image to registry (makes it push if it usually wouldnt)'
required: false
type: boolean
default: false
tag-prefix:
description: 'Tag prefix to use'
required: false
type: string
default: 'rn'
workflow_dispatch:
name: ci-build
env:
REGISTRY: ghcr.io
DOTNET_VERSION: 10.0.x
jobs:
tests:
name: Tests (${{ matrix.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: common-unit
project: Common.Tests/Common.Tests.csproj
- name: api-integration
project: API.IntegrationTests/API.IntegrationTests.csproj
steps:
- name: Checkout
uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '${{ env.DOTNET_VERSION }}'
- name: Run ${{ matrix.name }} tests
run: |
set -euo pipefail
dotnet test -c Release --project ${{ matrix.project }}
build:
name: Build (${{ matrix.image }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: docker/API.Dockerfile
image: api
- dockerfile: docker/LiveControlGateway.Dockerfile
image: live-control-gateway
- dockerfile: docker/Cron.Dockerfile
image: cron
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build ${{ matrix.image }}
uses: ./.github/actions/build-app
with:
dockerfile: ${{ matrix.dockerfile }}
push: ${{ inputs.push || (github.ref_protected && github.event_name != 'pull_request') }}
image: ${{ matrix.image }}
platforms: ${{ inputs.platforms || 'linux/amd64' }}
tag-prefix: ${{ inputs.tag-prefix || 'rn' }}
promote-image:
name: Promote Image (${{ matrix.image }})
needs: [build, tests]
runs-on: ubuntu-latest
if: ${{ inputs.push || (github.ref_protected && github.event_name != 'pull_request') }}
strategy:
fail-fast: false
matrix:
include:
- image: api
- image: live-control-gateway
- image: cron
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Promote Manifest ${{ matrix.image }}
uses: ./.github/actions/promote-image
with:
image: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
run-tag: ${{ inputs.tag-prefix || 'rn' }}-${{ github.run_number }}-a${{ github.run_attempt }}
latest: ${{ inputs.latest || false }}
deploy-prod-workflow:
runs-on: ubuntu-latest
needs: promote-image
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'master' }}
environment: production
steps:
- name: Send repository dispatch
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.GITOPS_PAT }}
repository: openshock/kubernetes-cluster-gitops
event-type: update-backend-prod
client-payload: |
{
"tag": "${{ inputs.tag-prefix || 'rn' }}-${{ github.run_number }}-a${{ github.run_attempt }}"
}
deploy-staging:
runs-on: ubuntu-latest
needs: promote-image
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'develop' }}
environment: staging
steps:
- name: Send repository dispatch
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.GITOPS_PAT }}
repository: openshock/kubernetes-cluster-gitops
event-type: update-backend-staging
client-payload: |
{
"tag": "${{ inputs.tag-prefix || 'rn' }}-${{ github.run_number }}-a${{ github.run_attempt }}"
}
deploy-dev:
runs-on: ubuntu-latest
needs: promote-image
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'develop' }}
environment: development
steps:
- uses: actions/checkout@v6
with:
sparse-checkout: |
.github
- uses: ./.github/actions/watchtower-update
with:
url: ${{ vars.WATCHTOWER_URL }}
token: ${{ secrets.WATCHTOWER_TOKEN }}