Files
linux-odyssey/.github/workflows/build-docker-image.yml
T
wancat 7d25c7efaa feat: update workflows
* build images with automatic tags
* separate staging and production deployment
* reuse workflows
2023-11-18 18:05:42 +08:00

52 lines
1.2 KiB
YAML

name: Build Docker Image
on:
workflow_call:
inputs:
imageName:
type: string
required: true
description: 'Name of the image to build'
dockerfilePath:
type: string
required: true
description: 'Path to the Dockerfile'
target:
type: string
required: false
description: 'Target to build'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ inputs.imageName }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Image
uses: docker/build-push-action@v2
with:
context: .
file: ${{ inputs.dockerfilePath }}
target: ${{ inputs.target }}
push: true
tags: ${{ steps.meta.outputs.tags }}