-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (58 loc) · 2.01 KB
/
action-push-ecr-image.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
name: Pushes a Docker Image to ECR
on:
workflow_call:
inputs:
aws_region:
required: false
type: string
default: us-east-1
build_number:
required: true
type: string
secrets:
ecr_repo:
required: true
aws_access_key_id:
required: true
aws_secret_access_key:
required: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Restore cached docker image
uses: actions/cache@v3
env:
cache-name: cache-${{ secrets.ecr_repo }}-${{ github.run_id }}
with:
path: /tmp/${{ secrets.ecr_repo }}.tar
key: ${{ secrets.ecr_repo }}-${{ github.run_id }}
restore-keys: ${{ secrets.ecr_repo }}-${{ github.run_id }}
- name: Load Docker image
env:
ECR_REPO: ${{ secrets.ecr_repo }}
run: |
docker load --input /tmp/${ECR_REPO}.tar
export IMAGE_NAME="${{ steps.login-ecr.outputs.registry }}/${ECR_REPO}:${{ inputs.build_number }}"
export IMAGE_NAME_LATEST="${{ steps.login-ecr.outputs.registry }}/${ECR_REPO}:latest"
docker tag ${ECR_REPO}:latest ${IMAGE_NAME}
docker tag ${IMAGE_NAME} ${IMAGE_NAME_LATEST}
docker image ls -a
- name: Push
run: |
export IMAGE_NAME="${{ steps.login-ecr.outputs.registry }}/${{ secrets.ecr_repo }}"
docker push "${IMAGE_NAME}:${{ inputs.build_number }}"
docker push "${IMAGE_NAME}:latest"