Skip to content

Commit d732688

Browse files
committed
feat : add GitHub Actions workflow for automated Container image builds
Implements CI/CD pipeline to build and push Docker images to GitHub Container Registry on push to master, tag creation, and pull requests. Uses docker/Dockerfile.build with caching and automatic tag generation based on branch, PR, semver, and commit SHA Signed-off-by: Pratik Raj <rajpratik71@gmail.com>
1 parent 8559989 commit d732688

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- master
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}
20+
21+
jobs:
22+
build-and-push:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GitHub Container Registry
36+
if: github.event_name != 'pull_request'
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata (tags, labels)
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=ref,event=branch
50+
type=ref,event=pr
51+
type=semver,pattern={{version}}
52+
type=semver,pattern={{major}}.{{minor}}
53+
type=sha
54+
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@v5
57+
with:
58+
context: .
59+
file: docker/Dockerfile.build
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)