From 1ec6fa68a138e6a55ed45a869c8586b2b60176d7 Mon Sep 17 00:00:00 2001 From: Flook Date: Tue, 28 Apr 2026 20:45:14 +0700 Subject: [PATCH] chore: improve ci --- .gitea/workflows/ci-docker.yml | 93 ++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/.gitea/workflows/ci-docker.yml b/.gitea/workflows/ci-docker.yml index b1ab031..e251119 100644 --- a/.gitea/workflows/ci-docker.yml +++ b/.gitea/workflows/ci-docker.yml @@ -1,45 +1,48 @@ -name: Build & Push Docker Image (Backend) - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout source - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: | - satitprompunjai/lms-backend:${{ gitea.sha }} - - - name: Update image tag in lms-k8s - env: - GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - run: | - git clone https://admin:${GIT_TOKEN}@gitea.panmodel.com/admin/lms-k8s.git - cd lms-k8s - - sed -i "s|satitprompunjai/lms-backend:.*|satitprompunjai/lms-backend:${{ gitea.sha }}|g" apps/backend/deployment.yaml - - git config user.name "lms-backend-ci" - git config user.email "ci@panmodel.com" - git commit -am "chore: update lms-backend image to ${{ gitea.sha }}" - git push +name: Build & Push Docker Image (Backend) + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # Checkout แบบไม่พึ่ง GitHub + - name: Checkout source (manual) + run: | + set -e + git clone https://gitea.panmodel.com/admin/lms-backend.git . + git checkout ${{ gitea.sha }} + + # Login Docker Hub แบบตรง + - name: Login to Docker Hub + run: | + set -e + echo "${{ secrets.DOCKERHUB_TOKEN }}" \ + | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + + # Build & Push image แบบตรง + - name: Build and push Docker image + run: | + set -e + docker build -t satitprompunjai/lms-backend:${{ gitea.sha }} . + docker push satitprompunjai/lms-backend:${{ gitea.sha }} + + # Update GitOps repo + - name: Update image tag in lms-k8s + env: + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + run: | + set -e + git clone https://admin:${GIT_TOKEN}@gitea.panmodel.com/admin/lms-k8s.git + cd lms-k8s + + sed -i "s|satitprompunjai/lms-backend:.*|satitprompunjai/lms-backend:${{ gitea.sha }}|g" apps/backend/deployment.yaml + + git config user.name "lms-backend-ci" + git config user.email "ci@panmodel.com" + git diff --quiet || git commit -am "chore: update lms-backend image to ${{ gitea.sha }}" + git push \ No newline at end of file