Skip to content

Commit 1ed9f4c

Browse files
committed
Add workflow to build image for branch and latest for master
1 parent e36ab0b commit 1ed9f4c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/docker-image.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: 'Branch to run the workflow on'
11+
required: false
12+
tags:
13+
- "v*.*.*" # Runs on version tags
14+
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # Saves time by not fetching other branches
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to GitHub Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.repository_owner }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Build and push Docker image
40+
id: docker_build
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
push: true
45+
tags: |
46+
ghcr.io/${{ github.repository }}:${{ github.ref_name }}
47+
${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest', github.repository) || '' }}
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)