Skip to content

Commit 59d0eb7

Browse files
Create build.yml
1 parent 7dde5b5 commit 59d0eb7

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/build.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build & Push Image
2+
'on':
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
environment: prod
10+
permissions:
11+
id-token: write
12+
contents: read
13+
packages: write
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
with:
18+
ref: '${{ github.head_ref }}'
19+
fetch-depth: 0
20+
21+
- name: Generate build version
22+
run: |
23+
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
24+
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
25+
echo "currdate=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
26+
id: version
27+
28+
- name: Extract metadata (tags, labels) for Docker
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: |
33+
dcr.dicoding.space/${{ github.repository_owner }}/aws-cli-jq
34+
ghcr.io/${{ github.repository_owner }}/aws-cli-jq
35+
tags: |
36+
type=raw,value=${{ steps.version.outputs.branch }}
37+
type=raw,value=${{ steps.version.outputs.currdate }}
38+
type=raw,value=${{ steps.version.outputs.commit }}
39+
flavor: latest=true
40+
41+
- name: Generate build cache tag
42+
run: |
43+
echo "ghcr=ghcr.io/${{ github.repository_owner }}/aws-cli-jq:buildcache" >> $GITHUB_OUTPUT
44+
id: buildcache
45+
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
with:
52+
driver-opts: |
53+
image=moby/buildkit:latest
54+
55+
- name: Login to GitHub Container Registry
56+
uses: docker/login-action@v3
57+
with:
58+
registry: ghcr.io
59+
username: ${{ github.repository_owner }}
60+
password: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Login to Dicoding Container Registry
63+
uses: docker/login-action@v3
64+
with:
65+
registry: dcr.dicoding.space
66+
username: ${{ secrets.DCR_USER }}
67+
password: ${{ secrets.DCR_PASS }}
68+
69+
- name: Build and Push Docker image
70+
id: docker_build
71+
uses: docker/build-push-action@v6
72+
with:
73+
context: .
74+
file: ./Dockerfile
75+
push: true
76+
tags: ${{ steps.meta.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}
78+
cache-from: type=registry,ref=${{ steps.buildcache.outputs.ghcr }}
79+
cache-to: type=registry,ref=${{ steps.buildcache.outputs.ghcr }},mode=max

0 commit comments

Comments
 (0)