-
Notifications
You must be signed in to change notification settings - Fork 239
242 lines (211 loc) · 9.14 KB
/
CD.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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
name: C/D
on:
workflow_dispatch:
inputs:
version:
description: 'the version number to release'
required: true
sha:
description: 'the github sha to release'
required: true
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
IMAGE_NAME: aws-otel-collector
IMAGE_NAMESPACE: amazon
PACKAGING_ROOT: build/packages
ECR_REPO_INTEGRATION_TEST: aws-otel-test/adot-collector-integration-test
ECR_REPO: aws-observability/aws-otel-collector
PACKAGE_CACHE_KEY: "cached_tested_packages_${{ github.run_id }}"
SSM_RELEASE_S3_BUCKET: "aws-otel-collector-ssm"
SSM_RELEASE_PACKAGE_NAME: "AWSDistroOTel-Collector"
RELEASE_S3_BUCKET: "aws-otel-collector"
permissions:
id-token: write
contents: write
jobs:
release-checking:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-input-vars.outputs.version }}
testing_version: ${{ steps.checking_sha_version.outputs.testing_version }}
latest-or-newer: ${{ steps.version.outputs.latest-or-newer }}
sha: ${{ steps.set-input-vars.outputs.sha }}
steps:
- uses: actions/checkout@v4
- name: Set Input Variables
id: set-input-vars
run: |
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
echo "sha=${{ github.event.inputs.sha }}" >> $GITHUB_OUTPUT
else
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "sha=${{ github.sha }}" >> $GITHUB_OUTPUT
fi
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.COLLECTOR_ASSUMABLE_ROLE_ARN }}
aws-region: us-west-2
- name: Login Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_RELEASE_USERNAME }}
password: ${{ secrets.DOCKERHUB_RELEASE_TOKEN }}
- name: Download candidate
run: aws s3 cp "s3://aws-otel-collector-release-candidate/${{ steps.set-input-vars.outputs.sha }}.tar.gz" candidate.tar.gz
- name: Uncompress the candidate package
run: tar zxvf candidate.tar.gz
- name: Check commit SHA and version
id: checking_sha_version
run: |
version_in_release=`cat $PACKAGING_ROOT/VERSION`
version_in_release_candidate=`cat $PACKAGING_ROOT/TESTING_VERSION`
sha_in_candidate=`cat $PACKAGING_ROOT/GITHUB_SHA`
if [ $version_in_release != ${{ steps.set-input-vars.outputs.version }} ]; then
echo "::error::Wrong version is detected: $version_in_release != ${{ steps.set-input-vars.outputs.version }}"
exit 1
fi
if [ $sha_in_candidate != ${{ steps.set-input-vars.outputs.sha }} ]; then
echo "::error::Wrong SHA is detected: $sha_in_candidate != ${{ steps.set-input-vars.outputs.sha }}"
exit 1
fi
echo "testing_version=$version_in_release_candidate" >> $GITHUB_OUTPUT
- name: Compare version with Dockerhub latest
id: version
run: |
TAG="${{ steps.set-input-vars.outputs.version }}"
TARGET_VERSION=$TAG bash tools/workflow/docker-version-compare.sh
- name: Cache packages
uses: actions/cache@v3
with:
key: ${{ env.PACKAGE_CACHE_KEY }}
path: ${{ env.PACKAGING_ROOT }}
release-to-s3:
runs-on: ubuntu-latest
needs: [release-checking]
steps:
- uses: actions/checkout@v4
- name: Cache if success
id: release-to-s3
uses: actions/cache@v3
with:
key: release-to-s3-${{ github.run_id }}
path: VERSION
- name: Restore cached packages
uses: actions/cache@v3
if: steps.release-to-s3.outputs.cache-hit != 'true'
with:
key: ${{ env.PACKAGE_CACHE_KEY }}
path: ${{ env.PACKAGING_ROOT }}
- name: Configure AWS Credentials
if: steps.release-to-s3.outputs.cache-hit != 'true'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.COLLECTOR_PROD_RELEASE_ROLE_ARN }}
aws-region: us-west-2
- name: Release to S3
if: steps.release-to-s3.outputs.cache-hit != 'true'
run: s3_bucket_name=${{ env.RELEASE_S3_BUCKET }} upload_to_latest=0 bash tools/release/image-binary-release/s3-release.sh
- name: Release binaries to s3 with latest version
if: ${{ needs.release-checking.outputs.latest-or-newer == 'true' && steps.release-to-s3.outputs.cache-hit != 'true' }}
run: s3_bucket_name=${{ env.RELEASE_S3_BUCKET }} upload_to_latest=1 bash tools/release/image-binary-release/s3-release.sh
release-version-image:
runs-on: ubuntu-latest
needs: [release-checking]
steps:
- uses: actions/checkout@v4
- name: Cache if success
id: release-version-image
uses: actions/cache@v3
with:
key: release-version-image-${{ github.run_id }}
path: VERSION
- name: Configure AWS Credentials
if: steps.release-version-image.outputs.cache-hit != 'true'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.COLLECTOR_PROD_RELEASE_ROLE_ARN }}
aws-region: us-east-1
- name: Login to Public Release ECR
if: steps.release-version-image.outputs.cache-hit != 'true'
id: login-ecr
uses: docker/login-action@v3
with:
registry: public.ecr.aws
env:
AWS_REGION: us-east-1
- name: Login Dockerhub
if: steps.release-version-image.outputs.cache-hit != 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_RELEASE_USERNAME }}
password: ${{ secrets.DOCKERHUB_RELEASE_TOKEN }}
- name: Pull image from integration test ECR and Upload to public release ECR and Dockerhub
if: steps.release-version-image.outputs.cache-hit != 'true'
uses: akhilerm/[email protected]
with:
src: public.ecr.aws/${{ env.ECR_REPO_INTEGRATION_TEST }}:${{ needs.release-checking.outputs.testing_version }}
dst: |
public.ecr.aws/${{ env.ECR_REPO }}:${{ needs.release-checking.outputs.version }}
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ needs.release-checking.outputs.version }}
- name: Pull image from release ECR, tag as latest and push to public release ECR and DockerHub
if: ${{ needs.release-checking.outputs.latest-or-newer == 'true' && steps.release-version-image.outputs.cache-hit != 'true'}}
uses: akhilerm/[email protected]
with:
src: public.ecr.aws/${{ env.ECR_REPO }}:${{ needs.release-checking.outputs.version }}
dst: |
public.ecr.aws/${{ env.ECR_REPO }}:latest
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest
release-ssm:
runs-on: ubuntu-latest
needs: [release-version-image,release-to-s3, release-checking]
steps:
- name: Cache if success
id: release-ssm
uses: actions/cache@v3
with:
key: release-ssm-${{ github.run_id }}
path: VERSION
- name: Trigger SSM package build and public
if: steps.release-ssm.outputs.cache-hit != 'true'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: release SSM package
token: ${{ secrets.REPO_WRITE_ACCESS_TOKEN }}
inputs: '{ "version": "${{ needs.release-checking.outputs.version }}", "sha": "${{ needs.release-checking.outputs.sha }}", "public": "true", "pkgname": "${{ env.SSM_RELEASE_PACKAGE_NAME }}", "latest": "${{ needs.release-checking.outputs.latest-or-newer }}" }'
release-to-github:
runs-on: ubuntu-latest
needs: [ release-ssm, release-to-s3, release-version-image, release-checking]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.release-checking.outputs.sha }}
- name: Generate release-note
run: sh tools/release/generate-release-note.sh
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
run: |
gh release create --target ${{ needs.release-checking.outputs.sha }} \
--title ${{ needs.release-checking.outputs.version }} \
--notes-file release-note \
--verify-tag \
--draft \
--prerelease \
${{ needs.release-checking.outputs.version }}