set auto build

This commit is contained in:
Kittapath 2024-01-11 12:15:17 +07:00
parent c0d8d80fa9
commit e4f6bc1b01
2 changed files with 79 additions and 119 deletions

View file

@ -1,39 +0,0 @@
# use for local build with act
name: build-local
run-name: build-local ${{ github.actor }}
on:
workflow_dispatch:
env:
REGISTRY: docker.frappet.com
IMAGE_NAME: demo/bma-ehr-app
jobs:
# act workflow_dispatch -W .github/workflows/build-local.yaml --input IMAGE_VER=test-v1
build-local:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# skip Set up QEMU because it fail on act and container
- name: Gen Version
id: gen_ver
run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER='${GITHUB_REF/refs\/tags\//}'
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: Test Version
run: |
echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Build and load local docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
load: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest

View file

@ -1,86 +1,85 @@
name: release-test name: release-test
run-name: release-test ${{ github.actor }} run-name: release-test ${{ github.actor }}
on: on:
# push: # push:
# tags: # tags:
# - 'v[0-9]+.[0-9]+.[0-9]+' # - 'v[0-9]+.[0-9]+.[0-9]+'
# tags-ignore: # tags-ignore:
# - '2.*' # - '2.*'
# Allow run workflow manually from Action tab # Allow run workflow manually from Action tab
workflow_dispatch: workflow_dispatch:
env: env:
REGISTRY: docker.frappet.com REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-faq IMAGE_NAME: ehr/bma-ehr-faq
DEPLOY_HOST: frappet.com DEPLOY_HOST: frappet.com
COMPOSE_PATH: /home/frappet/docker/bma-ehr-faq COMPOSE_PATH: /home/frappet/docker/bma-ehr-faq
TOKEN_LINE: uxuK5hDzS2DsoC5piJBrWRLiz8GgY7iMZZldOWsDDF0
jobs: jobs:
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
release-test: release-test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# skip Set up QEMU because it fail on act and container # skip Set up QEMU because it fail on act and container
# Gen Version try to get version from tag or inut # Gen Version try to get version from tag or inut
- name: Gen Version - name: Gen Version
id: gen_ver id: gen_ver
run: | run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER='${GITHUB_REF/refs\/tags\//}' IMAGE_VER='${GITHUB_REF/refs\/tags\//}'
else else
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
fi fi
if [[ $IMAGE_VER == '' ]]; then if [[ $IMAGE_VER == '' ]]; then
IMAGE_VER='test-vBeta' IMAGE_VER='test-vBeta'
fi fi
echo '::set-output name=image_ver::'$IMAGE_VER echo '::set-output name=image_ver::'$IMAGE_VER
- name: Check Version - name: Check Version
run: | run: |
echo $GITHUB_REF echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }} echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Login in to registry - name: Login in to registry
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
registry: ${{env.REGISTRY}} registry: ${{env.REGISTRY}}
username: ${{secrets.DOCKER_USER}} username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASS}} password: ${{secrets.DOCKER_PASS}}
- name: Build and push docker image - name: Build and push docker image
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: . context: .
platforms: linux/amd64 platforms: linux/amd64
push: true push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Remote Deployment - name: Remote Deployment
uses: appleboy/ssh-action@v0.1.8 uses: appleboy/ssh-action@v0.1.8
with: with:
host: ${{env.DEPLOY_HOST}} host: ${{env.DEPLOY_HOST}}
username: frappet username: frappet
password: ${{ secrets.SSH_PASSWORD }} password: ${{ secrets.SSH_PASSWORD }}
port: 22 port: 22
script: | script: |
cd "${{env.COMPOSE_PATH}}" cd "${{env.COMPOSE_PATH}}"
docker-compose pull docker-compose pull
docker-compose up -d docker-compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- uses: snow-actions/line-notify@v1.1.0 - uses: snow-actions/line-notify@v1.1.0
if: success() if: success()
with: with:
access_token: ${{ env.TOKEN_LINE }} access_token: ${{ secrets.TOKEN_LINE }}
message: | message: |
-Success✅✅✅ -Success✅✅✅
Image: ${{env.IMAGE_NAME}} Image: ${{env.IMAGE_NAME}}
Version: ${{ github.event.inputs.IMAGE_VER }} Version: ${{ github.event.inputs.IMAGE_VER }}
By: ${{secrets.DOCKER_USER}} By: ${{secrets.DOCKER_USER}}
- uses: snow-actions/line-notify@v1.1.0 - uses: snow-actions/line-notify@v1.1.0
if: failure() if: failure()
with: with:
access_token: ${{ env.TOKEN_LINE }} access_token: ${{ secrets.TOKEN_LINE }}
message: | message: |
-Failure❌❌❌ -Failure❌❌❌
Image: ${{env.IMAGE_NAME}} Image: ${{env.IMAGE_NAME}}
Version: ${{ github.event.inputs.IMAGE_VER }} Version: ${{ github.event.inputs.IMAGE_VER }}
By: ${{secrets.DOCKER_USER}} By: ${{secrets.DOCKER_USER}}