Skip to content

Commit 2bd1e17

Browse files
committed
fix(docker): add docker build
1 parent cc51aee commit 2bd1e17

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Push Docker Image
2+
on:
3+
push:
4+
tags:
5+
- '*.*.*'
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'The version tag to build (e.g., 1.2.3)'
10+
required: true
11+
12+
jobs:
13+
build-and-push:
14+
runs-on: ubuntu-latest
15+
name: build
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
22+
with:
23+
# On workflow_dispatch, checkout the tag passed in. On a tag push, checkout the tag from the event.
24+
ref: ${{ github.event.inputs.version || github.ref }}
25+
fetch-depth: 0
26+
27+
- name: Log in to GitHub Container Registry
28+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Set version
35+
id: version
36+
run: echo "VERSION=${{ github.event.inputs.version || github.ref_name }}" >> $GITHUB_ENV
37+
38+
- name: Convert repository name to lowercase
39+
id: repo
40+
run: echo "REPO_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
41+
42+
- name: Build Docker image
43+
run: |
44+
docker build -t ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }} .
45+
docker tag ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }} ghcr.io/${{ env.REPO_NAME }}:latest
46+
47+
- name: Push Docker image
48+
run: |
49+
docker push ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }}
50+
docker push ghcr.io/${{ env.REPO_NAME }}:latest

0 commit comments

Comments
 (0)