build docker hub
This commit is contained in:
parent
7c28d3f3ae
commit
ac1d85f672
1 changed files with 91 additions and 0 deletions
91
.github/workflows/build.yaml
vendored
Normal file
91
.github/workflows/build.yaml
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
name: build to DockerHub
|
||||
run-name: build ${{ github.actor }}
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "checkin-[0-9]+.[0-9]+.[0-9]+"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
DOCKERHUB_REGISTRY: docker.io
|
||||
IMAGE_NAME: hrms-edm
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Generate Version
|
||||
id: gen_ver
|
||||
run: |
|
||||
if [[ $GITHUB_REF == 'refs/heads/'* ]]; then
|
||||
BRANCH_NAME="${GITHUB_REF##*/}"
|
||||
IMAGE_VER="$BRANCH_NAME-$(date +%Y%m%d)-${GITHUB_SHA::7}"
|
||||
else
|
||||
IMAGE_VER="pr-${GITHUB_SHA::7}"
|
||||
fi
|
||||
echo "{\"version\":\"$IMAGE_VER\", \"date\":\"$(date +"%Y-%m-%d_%T")\",\"ref\":\"$GITHUB_REF\", \"sha\":\"$GITHUB_SHA\" }" > ./Services/server/src/version.json
|
||||
echo "image_ver=$IMAGE_VER" >> $GITHUB_OUTPUT
|
||||
echo "Build version: $IMAGE_VER"
|
||||
cat ./Services/server/src/version.json
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push to DockerHub
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: ./Services
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.gen_ver.outputs.image_ver }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
|
||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
|
||||
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
||||
|
||||
- name: Notify Discord Success
|
||||
if: success()
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "✅ Build Success!",
|
||||
"description": "**Details:**\n- Image: `${{ secrets.DOCKERHUB_USERNAME }}/${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Branch: `${{ github.ref_name }}`\n- Built by: `${{github.actor}}`",
|
||||
"color": 3066993,
|
||||
"footer": {
|
||||
"text": "Build Notification",
|
||||
"icon_url": "https://example.com/success-icon.png"
|
||||
},
|
||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||
}]
|
||||
}' \
|
||||
${{ secrets.DISCORD_WEBHOOK }}
|
||||
|
||||
- name: Notify Discord Failure
|
||||
if: failure()
|
||||
run: |
|
||||
curl -H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d '{
|
||||
"embeds": [{
|
||||
"title": "❌ Build Failed!",
|
||||
"description": "**Details:**\n- Image: `${{ secrets.DOCKERHUB_USERNAME }}/${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Branch: `${{ github.ref_name }}`\n- Attempted by: `${{github.actor}}`",
|
||||
"color": 15158332,
|
||||
"footer": {
|
||||
"text": "Build Notification",
|
||||
"icon_url": "https://example.com/failure-icon.png"
|
||||
},
|
||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||
}]
|
||||
}' \
|
||||
${{ secrets.DISCORD_WEBHOOK }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue