Download binary #2
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
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 |