Skip to content

Commit

Permalink
Create build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
habibimustafa authored Nov 26, 2024
1 parent 7dde5b5 commit 59d0eb7
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build & Push Image
'on':
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
environment: prod
permissions:
id-token: write
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: '${{ github.head_ref }}'
fetch-depth: 0

- name: Generate build version
run: |
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "currdate=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
id: version

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
dcr.dicoding.space/${{ github.repository_owner }}/aws-cli-jq
ghcr.io/${{ github.repository_owner }}/aws-cli-jq
tags: |
type=raw,value=${{ steps.version.outputs.branch }}
type=raw,value=${{ steps.version.outputs.currdate }}
type=raw,value=${{ steps.version.outputs.commit }}
flavor: latest=true

- name: Generate build cache tag
run: |
echo "ghcr=ghcr.io/${{ github.repository_owner }}/aws-cli-jq:buildcache" >> $GITHUB_OUTPUT
id: buildcache

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Dicoding Container Registry
uses: docker/login-action@v3
with:
registry: dcr.dicoding.space
username: ${{ secrets.DCR_USER }}
password: ${{ secrets.DCR_PASS }}

- name: Build and Push Docker image
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.buildcache.outputs.ghcr }}
cache-to: type=registry,ref=${{ steps.buildcache.outputs.ghcr }},mode=max

0 comments on commit 59d0eb7

Please sign in to comment.