Skip to content

Commit

Permalink
feat: add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sgametrio committed Jan 4, 2024
1 parent b0a9f2a commit 2b3b5e1
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/docker-build-push-ecr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# The reason why I created this workflow is that without using artifacts, it's much faster.
name: Docker

on:
workflow_call:
inputs:
aws_account_id:
description: "AWS Account ID"
type: string
required: true
aws_region:
description: "AWS Region"
type: string
required: true
aws_role_name:
description: "AWS Role Name"
type: string
required: true
image_name:
description: "Name of the Docker image to build"
type: string
required: false
default: ${{ github.event.repository.name }}
image_tag:
description: "Tag of the Docker image to build"
type: string
required: false
default: ${{ github.sha }}
docker_context:
description: "Path to the build context"
type: string
required: false
default: .

permissions:
id-token: write
contents: read

jobs:
build:
name: Build Image
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ inputs.aws_account_id }}:role/${{ inputs.aws_role_name }}
aws-region: ${{ inputs.aws_region }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build and export
uses: docker/build-push-action@v5
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: ${{ inputs.image_name }}
SOURCE_TAG: ${{ github.sha }}
IMAGE_TAG: ${{ inputs.image_tag }}
BRANCH: ${{ github.head_ref }}
with:
context: ${{ inputs.docker_context }}
# platforms: linux/amd64,linux/arm64 # TODO add support for multi-arch builds
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
$REGISTRY/$REPOSITORY:$SOURCE_TAG
$REGISTRY/$REPOSITORY:$IMAGE_TAG
$REGISTRY/$REPOSITORY:latest

0 comments on commit 2b3b5e1

Please sign in to comment.