-
Notifications
You must be signed in to change notification settings - Fork 65
471 lines (425 loc) · 20.5 KB
/
deploy_agent.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
name: Deploy the .NET Agent
on:
workflow_dispatch:
inputs:
get-version-automatically:
description: 'Automatically determine the Agent Version and Run ID'
type: boolean
required: true
default: true
agent_version:
description: 'OVERRIDE: Agent Version to deploy. Format: X.X.X - ignored unless "Automatically determine..." is unchecked'
required: false
run_id:
description: 'OVERRIDE: Run ID of the all_solutions.yml workflow that was triggered by creating a Release in GitHub. ID can be found in URL for run. Ignored unless "Automatically determine..." is unchecked'
required: false
deploy:
type: boolean
description: Deploy Build Artifacts. (If not selected, do everything except deploy.)
required: true
default: true
downloadsite:
type: boolean
description: Deploy MSI / ZIP / Tarball to the Download Site
required: true
default: true
nuget:
type: boolean
description: Deploy Nuget Packages
required: true
default: true
linux:
type: boolean
description: Deploy APT / YUM Packages
required: true
default: true
linux-deploy-to-production:
type: boolean
description: Deploy APT / YUM Packages to Production Repository. (If not selected, will deploy to a test respository.)
required: true
default: true
indexdownloadsite:
type: boolean
description: Re-Index the Download Site S3 container
required: true
default: true
permissions:
contents: read
packages: read
env:
DOTNET_NOLOGO: true
jobs:
get-release-info:
name: Get Release Version and Run ID
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.step2.outputs.release_version }}
workflow_run_id: ${{ steps.step2.outputs.workflow_run_id }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
with:
disable-sudo: true
egress-policy: audit
- name: Checkout
if: ${{ inputs.get-version-automatically }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Get Release Version and Run ID
if: ${{ inputs.get-version-automatically }}
id: step1
run: |
# Get the commit sha for the most recent release
COMMIT_SHA=$(git rev-list -n 1 "$(gh release list --limit 1 | awk '{ print $1 }')")
if [[ -z "$COMMIT_SHA" ]]; then
echo "::error::Unable to find SHA of most recent release"
exit 1
fi
echo "Found commit sha: $COMMIT_SHA"
# get info on the most recent release, writing output to a json file
gh release view --json name,isDraft,isPrerelease,publishedAt > release.json
# Get the version id of the most recent release (reported as "v99.99.99" so we strip off the "v")
RELEASE_VERSION=$(cat release.json | jq --raw-output ".name | .[1:]")
if [[ -z "$RELEASE_VERSION" ]]; then
echo "::error::Could not find the latest release."
exit 1
fi
echo "Found release version: $RELEASE_VERSION"
if [ "$(cat release.json | jq --raw-output '.isDraft')" = "true" ]; then
echo "::error::$RELEASE_VERSION is marked as 'Draft'. Use manual overrides to continue."
exit 1
fi
if [ "$(cat release.json | jq --raw-output '.isPrerelease')" = "true" ]; then
echo "::error::$RELEASE_VERSION is marked as 'Pre-Release'. Use manual overrides to continue."
exit 1
fi
# check release date - should be within the last 7 days (to ensure we don't grab an old release)
PUBLISHED_AT=$(cat release.json | jq --raw-output '.publishedAt')
if [[ -z "$PUBLISHED_AT" ]]; then
echo "::error::Release publish date is empty. Use manual overrides to continue."
exit 1
fi
LAST_WEEK=$(date --date "-7days" -u +"%s")
PUBLISH_DATE=$(date --date "$PUBLISHED_AT" -u +"%s")
if [ $LAST_WEEK -ge $PUBLISH_DATE ]; then
echo "::error::$RELEASE_VERSION was published more than a week ago. Use manual overrides to continue."
exit 1
fi
echo "release_version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
# get the run id of the most recent successful run of the all_solutions workflow triggered by a release event, against the given commit sha
WORKFLOW_RUN_ID=$(gh run list --commit $COMMIT_SHA --workflow all_solutions.yml --event release --status success --limit 1 --json databaseId,status --jq ".[0] | .databaseId")
if [[ -z "$WORKFLOW_RUN_ID" ]]; then
echo "::error::Could not find a successful all_solutions workflow run for the Release event against commit SHA $COMMIT_SHA. Use manual overrides to continue."
exit 1
fi
echo "Found workflow run id: $WORKFLOW_RUN_ID"
echo "workflow_run_id=$WORKFLOW_RUN_ID" >> "$GITHUB_OUTPUT"
- name: Set Output Release Version and Build Run ID
id: step2
run: |
if [ "${{ inputs.get-version-automatically}}" = "true" ]; then
echo "release_version=${{steps.step1.outputs.release_version}}" >> "$GITHUB_OUTPUT"
echo "workflow_run_id=${{steps.step1.outputs.workflow_run_id}}" >> "$GITHUB_OUTPUT"
else
if [[ -z "${{inputs.agent_version}}" ]]; then
echo "::error::Agent Version not specified."
exit 1
fi
if [[ -z "${{inputs.run_id}}" ]]; then
echo "::error::Run ID not specified."
exit 1
fi
echo "release_version=${{inputs.agent_version}}" >> "$GITHUB_OUTPUT"
echo "workflow_run_id=${{inputs.run_id}}" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
get-external-artifacts:
name: Get and Publish Deploy Artifacts Locally
needs: get-release-info
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
with:
disable-sudo: true
egress-policy: audit
- name: Download Deploy Artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ needs.get-release-info.outputs.workflow_run_id }}
name: deploy-artifacts
path: ${{ github.workspace }}
repository: ${{ github.repository }}
- name: Upload Deploy Artifacts Locally
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: deploy-artifacts
path: ${{ github.workspace }}
if-no-files-found: error
deploy-downloadsite:
needs: [get-release-info, get-external-artifacts]
if: ${{ inputs.downloadsite }}
name: Deploy MSI to Download Site
runs-on: windows-2022
steps:
- name: Download Deploy Artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: deploy-artifacts
path: ${{ github.workspace }}\staging_dir
- name: Move Artifacts to working_dir
run: |
Copy-Item -Path .\staging_dir\DownloadSite -Destination .\working_dir -Recurse
shell: powershell
- name: Create Version-less Installers
run: |
Copy-Item .\working_dir\NewRelicDotNetAgent_*_x64.msi .\working_dir\NewRelicDotNetAgent_x64.msi -Force -Recurse
Copy-Item .\working_dir\NewRelicDotNetAgent_*_x86.msi .\working_dir\NewRelicDotNetAgent_x86.msi -Force -Recurse
Copy-Item .\working_dir\NewRelicDotNetAgent_*_x64.zip .\working_dir\NewRelicDotNetAgent_x64.zip -Force -Recurse
Copy-Item .\working_dir\NewRelicDotNetAgent_*_x86.zip .\working_dir\NewRelicDotNetAgent_x86.zip -Force -Recurse
Copy-Item .\working_dir\newrelic-dotnet-agent_*_amd64.tar.gz .\working_dir\newrelic-dotnet-agent_amd64.tar.gz -Force -Recurse
Copy-Item .\working_dir\newrelic-dotnet-agent_*_arm64.tar.gz .\working_dir\newrelic-dotnet-agent_arm64.tar.gz -Force -Recurse
shell: powershell
- name: Deploy latest_release to Download Site
run: |
$Env:AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}"
$Env:AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}"
$Env:AWS_DEFAULT_REGION="us-west-2"
New-Item -ItemType directory -Path .\latest_release -Force
Copy-Item .\working_dir\* .\latest_release\ -Force -Recurse
cd .\latest_release
if ("${{ inputs.deploy }}" -eq "true") {
aws s3 sync . ${{ secrets.BUCKET_NAME }}/dot_net_agent/latest_release/ --include "*" --exclude ".DS_Store" --delete
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "aws s3 sync . ${{ secrets.BUCKET_NAME }}/dot_net_agent/latest_release/ --include `"*`" --exclude `".DS_Store`" --delete"
}
shell: pwsh
- name: Deploy previous_release to Download Site
run: |
$Env:AWS_ACCESS_KEY_ID="${{ secrets.AWS_ACCESS_KEY_ID }}"
$Env:AWS_SECRET_ACCESS_KEY="${{ secrets.AWS_SECRET_ACCESS_KEY }}"
$Env:AWS_DEFAULT_REGION="us-west-2"
New-Item -ItemType directory -Path .\previous_releases\${{ needs.get-release-info.outputs.release_version }} -Force
Copy-Item .\working_dir\* ".\previous_releases\${{ needs.get-release-info.outputs.release_version }}\" -Force -Recurse
cd .\previous_releases\${{ needs.get-release-info.outputs.release_version }}
if ("${{ inputs.deploy }}" -eq "true") {
aws s3 sync . ${{ secrets.BUCKET_NAME }}/dot_net_agent/previous_releases/${{ needs.get-release-info.outputs.release_version }}/ --include "*" --exclude ".DS_Store" --delete
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "aws s3 sync . ${{ secrets.BUCKET_NAME }}/dot_net_agent/previous_releases/${{ needs.get-release-info.outputs.release_version }}/ --include `"*`" --exclude `".DS_Store`" --delete"
}
shell: pwsh
index-download-site:
needs: deploy-downloadsite
name: Rebuild indexes on the download site
if: ${{ inputs.indexdownloadsite }}
uses: ./.github/workflows/build_download_site_index_files.yml
strategy:
matrix:
prefix: ["dot_net_agent/latest_release", "dot_net_agent/previous_releases"]
with:
prefix: ${{ matrix.prefix }}
aws-region: "us-east-1"
dry-run: false
secrets: inherit
deploy-nuget:
needs: get-external-artifacts
if: ${{ inputs.nuget }}
name: Deploy Agent to NuGet
runs-on: windows-2022
env:
nuget_source: https://www.nuget.org
steps:
- name: Download Deploy Artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: deploy-artifacts
path: ${{ github.workspace }}\working_dir
- name: Setup NuGet API Key
run: |
nuget.exe setApiKey ${{ secrets.NUGET_APIKEY }} -Source ${{ env.nuget_source }}
shell: pwsh
- name: Deploy Agent to Nuget
run: |
$packageName = Get-ChildItem ${{ github.workspace }}\working_dir\NugetAgent\NewRelic.Agent.*.nupkg -Name
$packagePath = Convert-Path ${{ github.workspace }}\working_dir\NugetAgent\$packageName
$version = $packageName.TrimStart('NewRelic.Agent').TrimStart('.').TrimEnd('.nupkg')
if ("${{ inputs.deploy }}" -eq "true") {
nuget.exe push $packagePath -Source ${{ env.nuget_source }}
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "nuget.exe push $packagePath -Source ${{ env.nuget_source }}"
}
shell: powershell
- name: Deploy Agent API to Nuget
run: |
$packageName = Get-ChildItem ${{ github.workspace }}\working_dir\NugetAgentApi\NewRelic.Agent.Api.*.nupkg -Name
$packagePath = Convert-Path ${{ github.workspace }}\working_dir\NugetAgentApi\$packageName
$version = $packageName.TrimStart('NewRelic.Agent.Api').TrimStart('.').TrimEnd('.nupkg')
if ("${{ inputs.deploy }}" -eq "true") {
nuget.exe push $packagePath -Source ${{ env.nuget_source }}
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "nuget.exe push $packagePath -Source ${{ env.nuget_source }}"
}
shell: powershell
- name: Deploy Azure Cloud Services to Nuget
run: |
$packageName = Get-ChildItem ${{ github.workspace }}\working_dir\NugetAzureCloudServices\NewRelicWindowsAzure.*.nupkg -Name
$packagePath = Convert-Path ${{ github.workspace }}\working_dir\NugetAzureCloudServices\$packageName
$version = $packageName.TrimStart('NewRelicWindowsAzure').TrimStart('.').TrimEnd('.nupkg')
if ("${{ inputs.deploy }}" -eq "true") {
nuget.exe push $packagePath -Source ${{ env.nuget_source }}
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "nuget.exe push $packagePath -Source ${{ env.nuget_source }}"
}
shell: powershell
- name: Deploy Azure WebSites-x64 to Nuget
run: |
$packageName = Get-ChildItem ${{ github.workspace }}\working_dir\NugetAzureWebSites-x64\NewRelic.Azure.WebSites.*.nupkg -Name
$packagePath = Convert-Path ${{ github.workspace }}\working_dir\NugetAzureWebSites-x64\$packageName
$version = $packageName.TrimStart('NewRelic.Azure.WebSites.x').TrimStart('.').TrimEnd('.nupkg')
if ("${{ inputs.deploy }}" -eq "true") {
nuget.exe push $packagePath -Source ${{ env.nuget_source }}
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "nuget.exe push $packagePath -Source ${{ env.nuget_source }}"
}
shell: powershell
- name: Deploy Azure WebSites-x86 to Nuget
run: |
$packageName = Get-ChildItem ${{ github.workspace }}\working_dir\NugetAzureWebSites-x86\NewRelic.Azure.WebSites.*.nupkg -Name
$packagePath = Convert-Path ${{ github.workspace }}\working_dir\NugetAzureWebSites-x86\$packageName
$version = $packageName.TrimStart('NewRelic.Azure.WebSites.x').TrimStart('.').TrimEnd('.nupkg')
if ("${{ inputs.deploy }}" -eq "true") {
nuget.exe push $packagePath -Source ${{ env.nuget_source }}
}
else {
Write-Host "Input:deploy was not true. The following deploy command was not run:"
Write-Host "nuget.exe push $packagePath -Source ${{ env.nuget_source }}"
}
shell: powershell
deploy-linux:
needs: [get-release-info, get-external-artifacts]
if: ${{ inputs.linux }}
name: Deploy Linux to APT and YUM
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
with:
egress-policy: audit
- name: Install dos2unix
run: |
sudo apt-get update -y
sudo apt-get install -y dos2unix
shell: bash
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Download Deploy Artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: deploy-artifacts
path: ${{ github.workspace }}/
- name: Get GPG Key
id: write_gpgkey
run: |
filePath="/tmp/gpg.tar.bz2"
echo "${{ secrets.GPG_KEY }}" | base64 -d > $filePath
echo "filePath=$filePath" >> $GITHUB_OUTPUT
shell: bash
- name: Move Artifacts and GPG Key to Staging Location
run: |
cp LinuxRpm/*.rpm ${{ github.workspace }}/deploy/linux/packages
cp LinuxDeb/*.deb ${{ github.workspace }}/deploy/linux/packages
cp -f ${{ steps.write_gpgkey.outputs.filePath }} ${{ github.workspace }}/deploy/linux/deploy_scripts/gpg.tar.bz2
shell: bash
- name: Prepare docker.env
run: |
# Confirm that the version is in the proper format.
IFS='.' read -ra agent_version_array <<< "${{ needs.get-release-info.outputs.release_version }}"
agent_version_count=${#agent_version_array[@]}
if [ $agent_version_count -ne 3 ] ; then
echo "::error Supplied agent version from Workflow (${{ needs.get-release-info.outputs.release_version }}) is malformed. It needs to be like '10.0.0'."
exit 1
else
AGENT_VERSION=${{ needs.get-release-info.outputs.release_version }}
fi
# Build the docker.env
cd ${{ github.workspace }}/deploy/linux/
touch docker.env
echo "AGENT_VERSION=$AGENT_VERSION" >> docker.env
echo "ACTION=release" >> docker.env
if [ "${{ inputs.linux-deploy-to-production }}" == "true" ] ; then
# We're actually deploying to production (apt.newrelic.com and yum.newrelic.com)
echo "S3_BUCKET=${{ secrets.PROD_MAIN_S3 }}" >> docker.env
echo "AWS_ACCESS_KEY_ID=${{ secrets.LINUX_AWS_ACCESS_KEY_ID }}" >> docker.env
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.LINUX_AWS_SECRET_ACCESS_KEY }}" >> docker.env
else
# Deploy to the test bucket that mirrors apt/yum.newrelic.com
echo "S3_BUCKET=${{ secrets.TEST_S3_BUCKET }}" >> docker.env
echo "AWS_ACCESS_KEY_ID=${{ secrets.TEST_BUCKET_AWS_ACCESS_KEY_ID }}" >> docker.env
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.TEST_BUCKET_AWS_SECRET_ACCESS_KEY }}" >> docker.env
fi
echo "GPG_KEYS=/data/deploy_scripts/gpg.tar.bz2" >> docker.env
shell: bash
- name: Build and Run Container
run: |
cd ${{ github.workspace }}/deploy/linux/
find . -name "*.bash" |xargs chmod a+x
find . -type f |xargs dos2unix
docker compose build
if [ "${{ inputs.deploy }}" == "true" ] ; then
docker compose run deploy_packages
else
echo "Input:deploy was not true. The following deploy command was not run:"
echo "docker compose run deploy_packages"
fi
shell: bash
- name: Clear Fastly cache
continue-on-error: true
if: ${{ inputs.deploy && success() }}
run: |
curl -i -X POST -H 'Fastly-Key:${{ secrets.FASTLY_TOKEN }}' ${{ secrets.FASTLY_URL }}
shell: bash
- name: Clear Cloudflare cache
continue-on-error: true
if: ${{ inputs.deploy && success() }}
run: |
curl ${{ secrets.CLOUDFLARE_CACHE_URL }} -H 'Content-Type: application/json' -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_CACHE_TOKEN }}" -d '{"purge_everything": true}'
shell: bash
publish-release-notes:
needs: [get-release-info, deploy-linux, deploy-nuget, index-download-site]
if: ${{ inputs.deploy && inputs.downloadsite && inputs.nuget && inputs.linux && inputs.linux-deploy-to-production }}
name: Create and Publish Release Notes
uses: newrelic/newrelic-dotnet-agent/.github/workflows/publish_release_notes.yml@main
with:
agent_version: ${{ needs.get-release-info.outputs.release_version }}
run_id: ${{ needs.get-release-info.outputs.workflow_run_id }}
secrets: inherit
post-deploy:
permissions:
issues: write
contents: read
packages: read
needs: [get-release-info, deploy-linux, deploy-nuget, index-download-site]
if: ${{ inputs.deploy && inputs.downloadsite && inputs.nuget && inputs.linux && inputs.linux-deploy-to-production }}
name: Run Post Deploy Workflow
uses: newrelic/newrelic-dotnet-agent/.github/workflows/post_deploy_agent.yml@main
with:
agent_version: ${{ needs.get-release-info.outputs.release_version }}
wait_for_apt_and_yum: true
secrets: inherit