add workflows: build-push-ghcr-images

This commit is contained in:
Haitao Pan 2026-04-02 17:44:51 +08:00
parent 51945b50da
commit c34fb28a33

View File

@ -0,0 +1,66 @@
name: Build And Push GHCR Image
on:
workflow_call:
inputs:
push_latest:
description: Also publish the `latest` tag.
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
push_latest:
description: Also publish the `latest` tag.
required: false
default: false
type: boolean
permissions:
contents: read
packages: write
concurrency:
group: build-push-ghcr-image-accounts-${{ github.ref_name }}
cancel-in-progress: false
env:
REGISTRY: ghcr.io
IMAGE_REPO_OWNER: ${{ vars.IMAGE_REPO_OWNER || github.repository_owner }}
IMAGE_NAME: accounts
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check Out Repository
uses: actions/checkout@v4
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log In To GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ vars.GHCR_USERNAME || github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN || github.token }}
- name: Compute Image Tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_REPO_OWNER }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short
type=raw,value=latest,enable=${{ inputs.push_latest }}
- name: Build And Push Image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}