-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (187 loc) · 8.71 KB
/
deploy-services-prod-auto.yml
File metadata and controls
205 lines (187 loc) · 8.71 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
name: Deploy Services to Production (Auto Latest)
on:
workflow_dispatch:
inputs:
deploy_api:
description: 'Deploy API with latest tag'
required: false
type: boolean
default: false
deploy_producer:
description: 'Deploy Producer with latest tag'
required: false
type: boolean
default: false
deploy_provider:
description: 'Deploy Provider with latest tag'
required: false
type: boolean
default: false
deploy_ui:
description: 'Deploy UI (React app) with latest tag'
required: false
type: boolean
default: false
deploy_jobs_dashboard:
description: 'Deploy Jobs Dashboard with latest tag'
required: false
type: boolean
default: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.ACR_CREDENTIALS }}
- name: Get latest API tag from ACR
if: ${{ inputs.deploy_api }}
id: api_tag
run: |
LATEST_TAG=$(az acr repository show-tags \
--name sportdeets \
--repository sportsdataapi \
--orderby time_desc \
--output tsv \
| grep -E '^[0-9]+$' \
| head -n 1)
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest API tag: $LATEST_TAG"
- name: Get latest Producer tag from ACR
if: ${{ inputs.deploy_producer }}
id: producer_tag
run: |
LATEST_TAG=$(az acr repository show-tags \
--name sportdeets \
--repository sportsdataproducer \
--orderby time_desc \
--output tsv \
| grep -E '^[0-9]+$' \
| head -n 1)
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest Producer tag: $LATEST_TAG"
- name: Get latest Provider tag from ACR
if: ${{ inputs.deploy_provider }}
id: provider_tag
run: |
LATEST_TAG=$(az acr repository show-tags \
--name sportdeets \
--repository sportsdataprovider \
--orderby time_desc \
--output tsv \
| grep -E '^[0-9]+$' \
| head -n 1)
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest Provider tag: $LATEST_TAG"
- name: Get latest UI tag from ACR
if: ${{ inputs.deploy_ui }}
id: ui_tag
run: |
LATEST_TAG=$(az acr repository show-tags \
--name sportdeets \
--repository sportsdataui \
--orderby time_desc \
--output tsv \
| grep -E '^[0-9]+$' \
| head -n 1)
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest UI tag: $LATEST_TAG"
- name: Get latest Jobs Dashboard tag from ACR
if: ${{ inputs.deploy_jobs_dashboard }}
id: jobs_dashboard_tag
run: |
set -euo pipefail
LATEST_TAG=$(az acr repository show-tags \
--name sportdeets \
--repository sportsdatajobsdashboard \
--orderby time_desc \
--output tsv \
| grep -E '^[0-9]+$' \
| head -n 1)
if [ -z "$LATEST_TAG" ]; then
echo "::error::No numeric tags found for sportsdatajobsdashboard"
exit 1
fi
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest Jobs Dashboard tag: $LATEST_TAG"
- name: Checkout sports-data-config repo
uses: actions/checkout@v4
with:
repository: jrandallsexton/sports-data-config
token: ${{ secrets.GH_PAT }}
path: sports-data-config
- name: Update API image tag
if: ${{ inputs.deploy_api && steps.api_tag.outputs.tag != '' }}
working-directory: sports-data-config
run: |
# Update or add image to api-patch.yaml
if grep -q "image:" app/overlays/04_prod/api-patch.yaml; then
sed -i "s|image: .*|image: sportdeets.azurecr.io/sportsdataapi:${{ steps.api_tag.outputs.tag }}|g" app/overlays/04_prod/api-patch.yaml
else
sed -i '/- name: api-all/a\ image: sportdeets.azurecr.io/sportsdataapi:${{ steps.api_tag.outputs.tag }}' app/overlays/04_prod/api-patch.yaml
fi
echo "Updated API to tag: ${{ steps.api_tag.outputs.tag }}"
- name: Update Producer image tag
if: ${{ inputs.deploy_producer && steps.producer_tag.outputs.tag != '' }}
working-directory: sports-data-config
run: |
# Update or add image to producer-patch.yaml
if grep -q "image:" app/overlays/04_prod/producer-patch.yaml; then
sed -i "s|image: .*|image: sportdeets.azurecr.io/sportsdataproducer:${{ steps.producer_tag.outputs.tag }}|g" app/overlays/04_prod/producer-patch.yaml
else
sed -i '/- name: producer/a\ image: sportdeets.azurecr.io/sportsdataproducer:${{ steps.producer_tag.outputs.tag }}' app/overlays/04_prod/producer-patch.yaml
fi
echo "Updated Producer to tag: ${{ steps.producer_tag.outputs.tag }}"
- name: Update Provider image tag
if: ${{ inputs.deploy_provider && steps.provider_tag.outputs.tag != '' }}
working-directory: sports-data-config
run: |
# Update or add image to provider-patch.yaml
if grep -q "image:" app/overlays/04_prod/provider-patch.yaml; then
sed -i "s|image: .*|image: sportdeets.azurecr.io/sportsdataprovider:${{ steps.provider_tag.outputs.tag }}|g" app/overlays/04_prod/provider-patch.yaml
else
sed -i '/- name: provider-football-ncaa/a\ image: sportdeets.azurecr.io/sportsdataprovider:${{ steps.provider_tag.outputs.tag }}' app/overlays/04_prod/provider-patch.yaml
fi
echo "Updated Provider to tag: ${{ steps.provider_tag.outputs.tag }}"
- name: Update UI image tag
if: ${{ inputs.deploy_ui && steps.ui_tag.outputs.tag != '' }}
working-directory: sports-data-config
run: |
# Update or add image to web-ui-patch.yaml
if grep -q "image:" app/overlays/04_prod/web-ui-patch.yaml; then
sed -i "s|image: .*|image: sportdeets.azurecr.io/sportsdataui:${{ steps.ui_tag.outputs.tag }}|g" app/overlays/04_prod/web-ui-patch.yaml
else
sed -i '/- name: web-ui/a\ image: sportdeets.azurecr.io/sportsdataui:${{ steps.ui_tag.outputs.tag }}' app/overlays/04_prod/web-ui-patch.yaml
fi
echo "Updated UI to tag: ${{ steps.ui_tag.outputs.tag }}"
- name: Update Jobs Dashboard image tag
if: ${{ inputs.deploy_jobs_dashboard && steps.jobs_dashboard_tag.outputs.tag != '' }}
working-directory: sports-data-config
run: |
# Update or add image to jobs-dashboard-patch.yaml
if grep -q "image:" app/overlays/04_prod/jobs-dashboard-patch.yaml; then
sed -i "s|image: .*|image: sportdeets.azurecr.io/sportsdatajobsdashboard:${{ steps.jobs_dashboard_tag.outputs.tag }}|g" app/overlays/04_prod/jobs-dashboard-patch.yaml
else
sed -i '/- name: jobs-dashboard/a\ image: sportdeets.azurecr.io/sportsdatajobsdashboard:${{ steps.jobs_dashboard_tag.outputs.tag }}' app/overlays/04_prod/jobs-dashboard-patch.yaml
fi
echo "Updated Jobs Dashboard to tag: ${{ steps.jobs_dashboard_tag.outputs.tag }}"
- name: Commit and push changes
working-directory: sports-data-config
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
git add app/overlays/04_prod/*.yaml
if git diff --staged --quiet; then
echo "No changes to commit"
else
COMMIT_MSG="Deploy to production (auto):"
[ "${{ inputs.deploy_api }}" == "true" ] && COMMIT_MSG="$COMMIT_MSG API=${{ steps.api_tag.outputs.tag }}"
[ "${{ inputs.deploy_producer }}" == "true" ] && COMMIT_MSG="$COMMIT_MSG Producer=${{ steps.producer_tag.outputs.tag }}"
[ "${{ inputs.deploy_provider }}" == "true" ] && COMMIT_MSG="$COMMIT_MSG Provider=${{ steps.provider_tag.outputs.tag }}"
[ "${{ inputs.deploy_ui }}" == "true" ] && COMMIT_MSG="$COMMIT_MSG UI=${{ steps.ui_tag.outputs.tag }}"
[ "${{ inputs.deploy_jobs_dashboard }}" == "true" ] && [ -n "${{ steps.jobs_dashboard_tag.outputs.tag }}" ] && COMMIT_MSG="$COMMIT_MSG JobsDashboard=${{ steps.jobs_dashboard_tag.outputs.tag }}"
git commit -m "$COMMIT_MSG"
git push
echo "✅ Changes committed to sports-data-config. Flux will deploy automatically."
fi