Create image-build.yml #1
This file contains hidden or 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
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/[email protected] | |
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/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
context: image-build |