This commit is contained in:
parent
84863e089b
commit
63aa67a1fe
5 changed files with 157 additions and 128 deletions
49
.forgejo/workflows/build.yml
Normal file
49
.forgejo/workflows/build.yml
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
|
||||||
|
REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
|
||||||
|
CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }}
|
||||||
|
IMAGE_VERSION: build
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
config-inline: |
|
||||||
|
[registry."${{ env.REGISTRY }}"]
|
||||||
|
ca=["/etc/ssl/certs/ca-certificates.crt"]
|
||||||
|
- name: Tag Version
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.event_name }}" == "push" ]]; then
|
||||||
|
echo "IMAGE_VERSION=${{ github.ref_name }}" | sed 's/v//g' >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "IMAGE_VERSION=${{ env.IMAGE_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
- name: Login in to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ env.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ env.REGISTRY_PASSWORD }}
|
||||||
|
- name: Build and push docker image
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64
|
||||||
|
context: .
|
||||||
|
file: ./docker/Dockerfile
|
||||||
|
tags: ${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_IMAGE_NAME }}:${{ env.IMAGE_VERSION }}
|
||||||
|
push: true
|
||||||
79
.forgejo/workflows/ci-cd.yml
Normal file
79
.forgejo/workflows/ci-cd.yml
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
# /.forgejo/workflows/ci-cd.yml
|
||||||
|
name: Build & Deploy on Dev
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
|
||||||
|
REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }}
|
||||||
|
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
|
||||||
|
CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }}
|
||||||
|
IMAGE_VERSION: latest
|
||||||
|
DISCORD_WEBHOOK: ${{ vars.DISCORD_WEBHOOK }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
with:
|
||||||
|
config-inline: |
|
||||||
|
[registry."${{ env.REGISTRY }}"]
|
||||||
|
ca=["/etc/ssl/certs/ca-certificates.crt"]
|
||||||
|
- name: Tag Version
|
||||||
|
run: |
|
||||||
|
echo "IMAGE_VERSION=latest"
|
||||||
|
- name: Login in to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ env.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ env.REGISTRY_PASSWORD }}
|
||||||
|
- name: Build and push docker image
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
platforms: linux/amd64
|
||||||
|
context: .
|
||||||
|
file: ./docker/Dockerfile
|
||||||
|
tags: ${{ env.CONTAINER_IMAGE_NAME }}:latest,${{ env.CONTAINER_IMAGE_NAME }}:${{ env.IMAGE_VERSION }}
|
||||||
|
push: true
|
||||||
|
- name: Remote Deploy
|
||||||
|
uses: appleboy/ssh-action@v1.2.1
|
||||||
|
with:
|
||||||
|
host: ${{ vars.SSH_DEPLOY_HOST }}
|
||||||
|
port: ${{ vars.SSH_DEPLOY_PORT }}
|
||||||
|
username: ${{ secrets.SSH_DEPLOY_USER }}
|
||||||
|
password: ${{ secrets.SSH_DEPLOY_PASSWORD }}
|
||||||
|
script: |
|
||||||
|
cd ~/repo
|
||||||
|
./replace-env.sh API_ORG "${{ env.IMAGE_VERSION }}"
|
||||||
|
./deploy.sh hrms-api-org
|
||||||
|
|
||||||
|
- name: Discord Notification
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
STATUS="${{ job.status == 'success' && '✅ Success' || '❌ Failed' }}"
|
||||||
|
COLOR="${{ job.status == 'success' && '3066993' || '15158332' }}"
|
||||||
|
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
curl -H "Content-Type: application/json" \
|
||||||
|
-X POST \
|
||||||
|
-d "{
|
||||||
|
\"embeds\": [{
|
||||||
|
\"title\": \"$STATUS\",
|
||||||
|
\"description\": \"**Build & Deploy**\\n- Image: \`${{ env.CONTAINER_IMAGE_NAME }}\`\\n- Version: \`${{ env.IMAGE_VERSION }}\`\\n- By: \`${{ github.actor }}\`\",
|
||||||
|
\"color\": $COLOR,
|
||||||
|
\"footer\": {
|
||||||
|
\"text\": \"Release Notification\",
|
||||||
|
\"icon_url\": \"https://example.com/success-icon.png\"
|
||||||
|
},
|
||||||
|
\"timestamp\": \"$TIMESTAMP\"
|
||||||
|
}]
|
||||||
|
}" \
|
||||||
|
${{ env.DISCORD_WEBHOOK }}
|
||||||
29
.forgejo/workflows/deploy.yml
Normal file
29
.forgejo/workflows/deploy.yml
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "Version to deploy"
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
default: "latest"
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_VERSION: build
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Remote Deploy
|
||||||
|
uses: appleboy/ssh-action@v1.2.1
|
||||||
|
with:
|
||||||
|
host: ${{ vars.SSH_DEPLOY_HOST }}
|
||||||
|
port: ${{ vars.SSH_DEPLOY_PORT }}
|
||||||
|
username: ${{ secrets.SSH_DEPLOY_USER }}
|
||||||
|
password: ${{ secrets.SSH_DEPLOY_PASSWORD }}
|
||||||
|
script: |
|
||||||
|
cd ~/repo
|
||||||
|
./replace-env.sh API_ORG "${{ inputs.version }}"
|
||||||
|
./deploy.sh hrms-api-org
|
||||||
22
.github/workflows/discord-notify.yml
vendored
22
.github/workflows/discord-notify.yml
vendored
|
|
@ -1,22 +0,0 @@
|
||||||
name: Discord PR Notify
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
discord:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Send Discord
|
|
||||||
run: |
|
|
||||||
curl -X POST "${{ secrets.DISCORD_WEBHOOK_PULLREQUEST }}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "🔔 **Service:** ${{ github.repository }}",
|
|
||||||
"description": "👤 **Author:** ${{ github.event.pull_request.user.login }}\n🌿 **Branch:** ${{ github.event.pull_request.head.ref }} → ${{ github.event.pull_request.base.ref }}\n📦 **Pull Request:** [#${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})",
|
|
||||||
"color": 5814783,
|
|
||||||
"timestamp": "${{ github.event.pull_request.created_at }}"
|
|
||||||
}]
|
|
||||||
}'
|
|
||||||
106
.github/workflows/release.yaml
vendored
106
.github/workflows/release.yaml
vendored
|
|
@ -1,106 +0,0 @@
|
||||||
name: release
|
|
||||||
run-name: release ${{ github.actor }}
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "version-[0-9]+.[0-9]+.[0-9]+"
|
|
||||||
workflow_dispatch:
|
|
||||||
env:
|
|
||||||
REGISTRY: docker.frappet.com
|
|
||||||
IMAGE_NAME: ehr/bma-ehr-org-service
|
|
||||||
DEPLOY_HOST: frappet.com
|
|
||||||
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-org
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
# skip Set up QEMU because it fail on act and container
|
|
||||||
# Gen Version try to get version from tag or inut
|
|
||||||
- name: Set output tags
|
|
||||||
id: vars
|
|
||||||
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
|
|
||||||
- name: Gen Version
|
|
||||||
id: gen_ver
|
|
||||||
run: |
|
|
||||||
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
|
|
||||||
IMAGE_VER=${{ steps.vars.outputs.tag }}
|
|
||||||
else
|
|
||||||
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
|
|
||||||
fi
|
|
||||||
if [[ $IMAGE_VER == '' ]]; then
|
|
||||||
IMAGE_VER='test-vBeta'
|
|
||||||
fi
|
|
||||||
echo '::set-output name=image_ver::'$IMAGE_VER
|
|
||||||
- name: Check Version
|
|
||||||
run: |
|
|
||||||
echo $GITHUB_REF
|
|
||||||
echo ${{ steps.gen_ver.outputs.image_ver }}
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
- name: Login in to registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: ${{env.REGISTRY}}
|
|
||||||
username: ${{secrets.DOCKER_USER}}
|
|
||||||
password: ${{secrets.DOCKER_PASS}}
|
|
||||||
- name: Build and push docker image
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: linux/amd64
|
|
||||||
file: docker/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
|
|
||||||
- name: Remote Deployment
|
|
||||||
uses: appleboy/ssh-action@v0.1.8
|
|
||||||
with:
|
|
||||||
host: ${{env.DEPLOY_HOST}}
|
|
||||||
username: frappet
|
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
|
||||||
port: 10102
|
|
||||||
script: |
|
|
||||||
cd "${{env.COMPOSE_PATH}}"
|
|
||||||
docker compose pull
|
|
||||||
docker compose up -d
|
|
||||||
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
|
||||||
- name: Notify Discord Success
|
|
||||||
if: success()
|
|
||||||
run: |
|
|
||||||
curl -H "Content-Type: application/json" \
|
|
||||||
-X POST \
|
|
||||||
-d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "✅ Deployment Success!",
|
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
|
||||||
"color": 3066993,
|
|
||||||
"footer": {
|
|
||||||
"text": "Release 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": "❌ Deployment Failed!",
|
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
|
||||||
"color": 15158332,
|
|
||||||
"footer": {
|
|
||||||
"text": "Release 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