-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
187 lines (175 loc) · 7.41 KB
/
action.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
name: Action Bootstrap
branding:
icon: arrow-right-circle
color: gray-dark
description: |
This action performs git repo checkout, configures AWS credentials, logs into ECR and generates the image name
inputs:
run-tag-generator:
description: Set to false to not run docker meta
required: false
default: 'true'
run-helm-version-generator:
description: Set to true to run docker meta for helm chart
required: false
default: 'false'
ecr-repo-name:
required: false
description: the name of the docker image to configure
default: ''
cache-registry-name:
required: false
description: the name of the docker registry to use for caching
default: ''
ecr-login:
required: false
description: 'Set to false to not login to ECR'
default: 'true'
aws-account-id:
required: true
description: 'aws-account-id to configure'
role-to-assume:
required: true
description: 'role-to-assume to configure'
role-session-name:
required: true
description: 'role-session-name to configure'
aws-region:
required: true
description: 'aws-region to configure'
checkout-depth:
required: false
description: 'The checkout depth. Set to 0 to have a full checkout'
default: '1'
load-secrets:
required: false
description: 'Load secrets from AWS secrets manager as environment variables'
default: 'false'
secret-names:
required: false
description: 'The names of the secrets to pull values from'
default: ''
parse-json-secrets:
required: false
description: 'Create an environment variable for each key-value pair'
default: 'true'
outputs:
ecr-registry:
description: 'The ECR registry'
value: '${{ steps.login-ecr.outputs.registry }}'
ecr-repo-name:
description: 'The generated ECR repository name'
value: '${{ steps.img-name.outputs.ecr-repo-name }}'
ecr-helm-chart-registry:
description: 'The generated ECR Helm registry'
value: '${{ steps.chart-registry.outputs.ecr-helm-chart-registry }}'
app-version:
description: 'The current project version'
value: '${{ steps.meta.outputs.version }}'
docker-labels:
description: 'The labels of the docker image'
value: '${{ steps.meta.outputs.labels }}'
docker-tags:
description: 'The tags of the docker image'
value: '${{ steps.meta.outputs.tags }}'
docker-cache-input:
description: 'The tags of the docker image'
value: '${{ steps.caching-config.outputs.docker-cache-input }}'
docker-cache-output:
description: 'The tags of the docker image'
value: '${{ steps.caching-config.outputs.docker-cache-output }}'
helm-chart-version:
description: 'The semver for helm chart version'
value: '${{ steps.meta-helm.outputs.version }}'
runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v4
if: (!(github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.action == 'unlabeled')))
with:
persist-credentials: false
fetch-depth: ${{ inputs.checkout-depth }}
- name: Configure AWS credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ inputs.role-to-assume }}
role-session-name: ${{ inputs.role-session-name }}
aws-region: ${{ inputs.aws-region }}
- name: Load AWS Secrets
id: load-secrets
if: inputs.load-secrets == 'true'
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: ${{ inputs.secret-names }}
parse-json-secrets: ${{ inputs.parse-json-secrets }}
- name: Login to Amazon ECR
id: login-ecr
if: inputs.ecr-login == 'true'
uses: aws-actions/amazon-ecr-login@v2
- name: Image Name
id: img-name
shell: bash
if: inputs.run-tag-generator == 'true'
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "ecr-repo-name=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/alpha-image/${{ inputs.ecr-repo-name }}" >>"${GITHUB_OUTPUT}"
else
echo "ecr-repo-name=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/image/${{ inputs.ecr-repo-name }}" >>"${GITHUB_OUTPUT}"
fi
- name: Chart Registry
id: chart-registry
shell: bash
if: inputs.run-helm-version-generator == 'true'
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "ecr-helm-repo-name=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/alpha-chart/${{ inputs.ecr-repo-name }}" >>"${GITHUB_OUTPUT}"
echo "ecr-helm-chart-registry=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/alpha-chart" >>"${GITHUB_OUTPUT}"
else
echo "ecr-helm-repo-name=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/image/${{ inputs.ecr-repo-name }}" >>"${GITHUB_OUTPUT}"
echo "ecr-helm-chart-registry=${{inputs.aws-account-id}}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com/chart" >>"${GITHUB_OUTPUT}"
fi
- name: Caching Config
id: caching-config
shell: bash
if: inputs.run-tag-generator == 'true' && inputs.cache-registry-name != ''
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "$(gh pr -R ${{github.repository}} view "${{ github.event.pull_request.number }}" --json commits -q '.commits | length' || true)" == "1" ]]; then
echo "docker-cache-input=${{ inputs.cache-registry-name }}/${{ inputs.ecr-repo-name }}:cache" >>"${GITHUB_OUTPUT}"
else
echo "docker-cache-input=${{ inputs.cache-registry-name }}/${{ inputs.ecr-repo-name }}:pr${{ github.event.pull_request.number }}-cache" >>"${GITHUB_OUTPUT}"
fi
echo "docker-cache-output=${{ inputs.cache-registry-name }}/${{ inputs.ecr-repo-name }}:pr${{ github.event.pull_request.number }}-cache" >>"${GITHUB_OUTPUT}"
else
echo "docker-cache-input=${{ inputs.cache-registry-name }}/${{ inputs.ecr-repo-name }}:cache" >>"${GITHUB_OUTPUT}"
echo "docker-cache-output=${{ inputs.cache-registry-name }}/${{ inputs.ecr-repo-name }}:cache" >>"${GITHUB_OUTPUT}"
fi
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
if: ((!(github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.action == 'unlabeled'))) && inputs.run-tag-generator == 'true')
env:
DOCKER_METADATA_PR_HEAD_SHA: 'true'
with:
images: |
${{ steps.img-name.outputs.ecr-repo-name }}
tags: |
type=ref,event=branch
type=ref,event=pr,suffix=-{{sha}}
type=semver,pattern={{version}},prefix=v
type=semver,pattern={{major}}.{{minor}},prefix=v
type=semver,pattern={{major}},prefix=v
- name: Docker meta helm
id: meta-helm
uses: docker/metadata-action@v5
if: ((!(github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.action == 'unlabeled'))) && inputs.run-helm-version-generator == 'true')
with:
images: |
${{ steps.chart-registry.outputs.ecr-helm-repo-name }}
tags: |
type=ref,event=branch
type=ref,event=pr,prefix=v0.0.0-,suffix=-{{sha}}
type=semver,pattern={{version}},prefix=v
type=semver,pattern={{major}}.{{minor}},prefix=v
type=semver,pattern={{major}},prefix=v