-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yaml
53 lines (53 loc) · 2.01 KB
/
action.yaml
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
name: Build, tag, and push image to Amazon ECR
description: Build and tag a Docker image and push it to Amazon ECR
inputs:
role-to-assume:
description: The ARN of the role to assume
required: true
runs:
using: composite
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: eu-west-1
role-to-assume: ${{ inputs.role-to-assume }}
role-skip-session-tagging: true
role-duration-seconds: 3600
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Create Amazon ECR repository if not exists
env:
ECR_REPOSITORY: ${{ github.event.repository.name }}
shell: bash
run: |
aws ecr describe-repositories --repository-names ${ECR_REPOSITORY,,} || aws ecr create-repository --repository-name ${ECR_REPOSITORY,,}
- name: Prepare image tag
id: prepare-image-tag
shell: bash
run: |
IMAGE_TAG=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
IMAGE_TAG=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
IMAGE_TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
IMAGE_TAG=pr-${{ github.event.number }}
elif [ "${{ github.event_name }}" = "push" ]; then
IMAGE_TAG="sha-${GITHUB_SHA::7}"
fi
echo "image-tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ github.event.repository.name }}
IMAGE_TAG: ${{ steps.prepare-image-tag.outputs.image-tag }}
shell: bash
run: |
docker build . -t $ECR_REGISTRY/${ECR_REPOSITORY,,}:$IMAGE_TAG --build-arg DE_ECR=$ECR_REGISTRY
docker push $ECR_REGISTRY/${ECR_REPOSITORY,,}:$IMAGE_TAG