-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (61 loc) · 1.93 KB
/
build-and-push-docker-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
65
66
67
name: General Build and Push Docker Images to ECR (buildx)
on:
workflow_call:
inputs:
aws_region:
type: string
description: "AWS region for ECR"
required: true
image_name:
type: string
description: "Docker image name"
required: true
image_tag:
type: string
description: "Docker image tag"
required: true
context_path:
type: string
description: "Build context path"
required: true
dockerfile_path:
type: string
description: "Path to the Dockerfile"
required: true
platforms:
type: string
description: "Platforms to build for"
required: false
default: "linux/amd64,linux/arm64"
provenance:
type: boolean
description: "Enable provenance"
required: false
default: true
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
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: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ${{ inputs.context_path }}
file: ${{ inputs.dockerfile_path }}
push: true
platforms: ${{ inputs.platforms }}
provenance: ${{ inputs.provenance }}
tags: ${{ secrets.DOCKER_REGISTRY_HOST }}/${{ inputs.image_name }}:${{ inputs.image_tag }}
- name: Docker image pushed successfully
run: echo "Docker image pushed successfully to ECR."