add: build docker hub
This commit is contained in:
parent
2b1d6852c9
commit
d10c86e0cb
3 changed files with 90 additions and 276 deletions
90
.github/workflows/dockerhub-release-leave.yaml
vendored
Normal file
90
.github/workflows/dockerhub-release-leave.yaml
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
name: DockerHub Release - Leave Service
|
||||
run-name: DockerHub Release - Leave Service by ${{ github.actor }}
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "leave-[0-9]+.[0-9]+.[0-9]+"
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
IMAGE_VER:
|
||||
description: 'Image version (e.g., latest, v1.0.0)'
|
||||
required: false
|
||||
default: 'latest'
|
||||
|
||||
env:
|
||||
DOCKERHUB_REGISTRY: docker.io
|
||||
IMAGE_NAME: hrms-api-leave
|
||||
|
||||
jobs:
|
||||
release-to-dockerhub:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set output tags
|
||||
id: vars
|
||||
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Generate version
|
||||
id: gen_ver
|
||||
run: |
|
||||
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
|
||||
IMAGE_VER=${{ steps.vars.outputs.tag }}
|
||||
elif [[ $GITHUB_REF == 'refs/heads/'* ]]; then
|
||||
BRANCH_NAME=${GITHUB_REF#refs/heads/}
|
||||
IMAGE_VER="${BRANCH_NAME}-latest"
|
||||
else
|
||||
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
|
||||
fi
|
||||
if [[ $IMAGE_VER == '' ]]; then
|
||||
IMAGE_VER='test-vBeta'
|
||||
fi
|
||||
echo "image_ver=${IMAGE_VER}" >> $GITHUB_OUTPUT
|
||||
echo "Generated version: ${IMAGE_VER}"
|
||||
|
||||
- name: Display version
|
||||
run: |
|
||||
echo "Git Ref: $GITHUB_REF"
|
||||
echo "Image Version: ${{ steps.gen_ver.outputs.image_ver }}"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{env.DOCKERHUB_REGISTRY}}
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=ref,event=branch
|
||||
type=raw,value=${{ steps.gen_ver.outputs.image_ver }}
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: BMA.EHR.Leave/Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.gen_ver.outputs.image_ver }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Image digest
|
||||
run: echo "Image pushed with digest ${{ steps.build.outputs.digest }}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue