-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (88 loc) · 2.92 KB
/
build-push-image-ecr.yml
File metadata and controls
98 lines (88 loc) · 2.92 KB
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
name: Build and push image to registry
on:
workflow_call:
inputs:
image_name:
description: A list of the repo names to push to
required: true
type: string
region:
description: The AWS region to use for the ECR registry
required: true
type: string
tags:
# https://github.com/marketplace/actions/docker-metadata-action#tags-input
description: Tag rules for docker/metadata-action
required: false
type: string
default: |
type=edge
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
context:
description: The context to use for the Docker build command
required: false
type: string
default: ./
dockerfile:
description: The Dockerfile to use for the Docker build command
required: false
type: string
default: Dockerfile
platforms:
description: The platforms to use for the Docker build command
required: false
type: string
default: linux/amd64
push:
description: Whether to push the image to the registry
required: false
type: boolean
default: true
secrets:
role_to_assume:
required: true
jobs:
build:
name: Build and push image to registry
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.role_to_assume }}
aws-region: ${{ inputs.region }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ inputs.image_name }}
tags: ${{ inputs.tags }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: ${{ inputs.context }}
file: ${{ inputs.dockerfile }}
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}