Skip to content

Commit cd0a517

Browse files
Merge pull request #13 from datavisyn/add_revision_as_tag
Add revision as tag
2 parents ff746e4 + 984cc6f commit cd0a517

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

.github/workflows/deploy-product.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ on:
1414
DV_AWS_ECR_REGISTRY:
1515
required: false
1616
DV_BOT_USER:
17-
required: true
17+
required: false
18+
DV_AWS_ECR_ROLE:
19+
required: false
20+
DV_AWS_REGION:
21+
required: false
22+
1823
inputs:
1924
stage:
2025
description: "stage that should be deployed (develop|qa|production)"
@@ -24,6 +29,16 @@ on:
2429
description: "customer for that the app should be deployed"
2530
required: true
2631
type: string
32+
add_revision_as_tag:
33+
description: "add revision label as tag"
34+
required: false
35+
type: boolean
36+
default: false
37+
outputs:
38+
revision_label:
39+
description: "revision that is stored as a label"
40+
value: ${{ jobs.deploy.outputs.revision_label }}
41+
2742

2843
permissions:
2944
id-token: write
@@ -40,6 +55,8 @@ env:
4055
jobs:
4156
deploy:
4257
runs-on: ubuntu-20.04
58+
outputs:
59+
revision_label: ${{ steps.get-revision-label.outputs.revision_label }}
4360
steps:
4461
# checkout repo to get package.json
4562
- uses: actions/checkout@v3
@@ -62,6 +79,7 @@ jobs:
6279
branch_name: ${{ github.ref_name }}
6380
time_zone: ${{ env.TIME_ZONE }}
6481
- name: trigger deployment
82+
id: trigger-deployment
6583
uses: datavisyn/github-action-trigger-workflow@v1
6684
with:
6785
owner: "datavisyn"
@@ -70,4 +88,25 @@ jobs:
7088
workflow_file_name: "deploy-app.yml"
7189
ref: ${{ env.WORKFLOW_BRANCH }}
7290
github_user: ${{ secrets.DV_BOT_USER }}
73-
client_payload: '{ "app": "${{ steps.get-parameters.outputs.app }}", "customer": "${{ inputs.customer }}", "stage": "${{ inputs.stage }}", "sub_app": "${{ steps.get-parameters.outputs.sub_app }}", "branch": "${{ steps.get-parameters.outputs.image_tag2 }}" }'
91+
client_payload: '{ "app": "${{ steps.get-parameters.outputs.app }}", "customer": "${{ inputs.customer }}", "stage": "${{ inputs.stage }}", "sub_app": "${{ steps.get-parameters.outputs.sub_app }}", "branch": "${{ steps.get-parameters.outputs.image_tag2 }}", "add_revision_as_tag": "${{ inputs.add_revision_as_tag }}" }'
92+
- name: Configure AWS Credentials
93+
if: ${{ inputs.add_revision_as_tag == true }}
94+
uses: aws-actions/[email protected]
95+
with:
96+
role-to-assume: ${{ secrets.DV_AWS_ECR_ROLE }}
97+
aws_role: ${{ secrets.DV_AWS_ECR_ROLE }}
98+
aws-region: ${{ secrets.DV_AWS_REGION }}
99+
- name: Login to Amazon ECR
100+
if: ${{ inputs.add_revision_as_tag == true }}
101+
id: login-ecr
102+
uses: aws-actions/[email protected]
103+
- name: get revision label
104+
id: get-revision-label
105+
if: ${{ inputs.add_revision_as_tag == true }}
106+
run: |
107+
echo "fetch labels of image"
108+
ECR_REPO=$(echo ${{ steps.get-parameters.outputs.ecr_repos }} | cut -d ',' -f 1)
109+
echo "ECR_REPO: $ECR_REPO"
110+
MANIFEST=$(aws ecr batch-get-image --repository-name "$ECR_REPO" --image-id imageTag="${{ steps.get-parameters.outputs.image_tag2 }}" --accepted-media-types "application/vnd.docker.distribution.manifest.v1+json" --output json |jq -r '.images[].imageManifest' |jq -r '.history[0].v1Compatibility' |jq -r '.config.Labels | to_entries | .[] | select(.key=="org.opencontainers.image.revision") | .value')
111+
echo "$MANIFEST"
112+
echo "revision_label=$MANIFEST" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)