-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |