Skip to content

Commit

Permalink
Create image-build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin1024 authored Jul 18, 2024
1 parent b993551 commit 2b000ab
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: "Build Image"

on: push

jobs:
buildx:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
statuses: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV

- name: Set commit status pending
uses: myrotvorets/set-commit-status-action@v1.1.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: image-build

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::558529356944:role/global-iamr-github-actions-image-build
role-session-name: GitHubImageBuild

- name: Login to ECR
uses: docker/login-action@v2
with:
registry: 558529356944.dkr.ecr.us-east-1.amazonaws.com
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- uses: int128/create-ecr-repository-action@v1
id: ecr
with:
repository: ${{ github.event.repository.name }}

- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v4
with:
images: ${{ steps.ecr.outputs.repository-uri }}
tags: |
type=raw,value=${{ env.SHORT_SHA }}
type=raw,value=${{ github.event.repository.name }}-${{ env.SHORT_SHA }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Update status
uses: myrotvorets/set-commit-status-action@v1.1.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
context: image-build

0 comments on commit 2b000ab

Please sign in to comment.