refactor: update Docker workflows to use reusable configuration and restrict branch triggers to 'main' (#15)

* refactor: update Docker workflows to use reusable configuration and restrict branch triggers to 'main'
This commit is contained in:
Dallas98
2025-10-22 23:44:44 +08:00
committed by GitHub
parent 31ef8bc265
commit c998de2e9d
5 changed files with 107 additions and 24 deletions

View File

@@ -0,0 +1,57 @@
name: Docker Image Build & Push
on:
workflow_call:
inputs:
service_name:
required: true
type: string
build_dir:
required: true
type: string
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Docker Image Tag
id: set-tag
run: |
LOWERCASE_REPO=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
BASE_IMAGE=ghcr.io/$LOWERCASE_REPO/datamate-${{ inputs.service_name }}
if [[ $GITHUB_REF == refs/tags/v* ]]; then
TAG=${GITHUB_REF#refs/tags/v}
echo "TAGS=$BASE_IMAGE:$TAG" >> $GITHUB_OUTPUT
elif [[ $GITHUB_REF == refs/heads/main ]]; then
echo "TAGS=$BASE_IMAGE:latest" >> $GITHUB_OUTPUT
else
echo "TAGS=$BASE_IMAGE:temp" >> $GITHUB_OUTPUT
fi
- name: Build Docker Image
run: |
make build-${{ inputs.service_name }} VERSION=latest
- name: Tag Docker Image
run: |
docker tag datamate-${{ inputs.service_name }}:latest ${{ steps.set-tag.outputs.TAGS }}
- name: Push Docker Image
if: github.event_name != 'pull_request'
run: |
docker push ${{ steps.set-tag.outputs.TAGS }}