-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (74 loc) · 2.51 KB
/
reusable-docker-ecr.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
on:
workflow_call:
inputs:
version_tag:
required: true
type: string
ecr_registry:
required: true
type: string
aws_region:
required: false
default: us-west-2
type: string
release_branch:
required: false
default: main
type: string
develop_branch:
required: false
default: develop
type: string
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
jobs:
dockerize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: set environment variables
run: |
echo "CI_JOB_TIMESTAMP=$(date --utc --rfc-3339=seconds)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ inputs.aws_region }}
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Lowercase repo for container registry
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
- name: Build, tag, and push image to Amazon ECR
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ inputs.ecr_registry }}/${{ env.REPO }}:${{ inputs.version_tag }}
labels: |
org.opencontainers.image.created=${{ env.CI_JOB_TIMESTAMP }}
org.opencontainers.image.version=${{ inputs.version_tag }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Add test tag
if: github.ref == format('refs/heads/{0}', inputs.develop_branch)
uses: akhilerm/[email protected]
with:
src: ${{ inputs.ecr_registry }}/${{ env.REPO }}:${{ inputs.version_tag }}
dst: ${{ inputs.ecr_registry }}/${{ env.REPO }}:test
- name: Add latest tag
if: github.ref == format('refs/heads/{0}', inputs.release_branch)
uses: akhilerm/[email protected]
with:
src: ${{ inputs.ecr_registry }}/${{ env.REPO }}:${{ inputs.version_tag }}
dst: ${{ inputs.ecr_registry }}/${{ env.REPO }}:latest
- name: Logout of Amazon ECR
if: always()
run: docker logout ${{ inputs.ecr_registry }}