From be976bc78a4315c1b3d041b07477abc572914886 Mon Sep 17 00:00:00 2001 From: namdh861 Date: Tue, 22 Sep 2026 22:44:24 +0700 Subject: [PATCH] fix: deploy.yaml --- .gitea/workflows/deploy.yaml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 99682c9..3df72bd 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -15,16 +15,22 @@ env: jobs: build: runs-on: ubuntu-latest + outputs: + sha_short: ${{ steps.vars.outputs.sha_short }} steps: - name: Checkout code uses: actions/checkout@v4 + - name: Set short SHA + id: vars + run: echo "sha_short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT + - name: Build Docker image run: | IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}" docker build \ --build-arg VITE_API_BASE_URL="${{ env.VITE_API_BASE_URL }}" \ - -t "$IMAGE_BASE:${{ github.sha }}" \ + -t "$IMAGE_BASE:${{ steps.vars.outputs.sha_short }}" \ -t "$IMAGE_BASE:latest" . push: @@ -34,21 +40,23 @@ jobs: - name: Login and push to Docker Hub run: | IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}" + SHA="${{ needs.build.outputs.sha_short }}" echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin - docker push "$IMAGE_BASE:${{ github.sha }}" + docker push "$IMAGE_BASE:$SHA" docker push "$IMAGE_BASE:latest" docker logout deploy: - needs: push + needs: build runs-on: ubuntu-latest steps: - - name: Pull & run new container + - name: Pull and run new container run: | IMAGE_BASE="${{ secrets.REGISTRY_USER }}/${{ env.DOCKERHUB_REPO }}" + SHA="${{ needs.build.outputs.sha_short }}" echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USER }}" --password-stdin - docker pull "$IMAGE_BASE:${{ github.sha }}" + docker pull "$IMAGE_BASE:$SHA" docker logout docker stop "${{ env.CONTAINER_NAME }}" 2>/dev/null || true @@ -58,8 +66,8 @@ jobs: --name "${{ env.CONTAINER_NAME }}" \ --restart unless-stopped \ -p "${{ env.HOST_PORT }}:${{ env.CONTAINER_PORT }}" \ - "$IMAGE_BASE:${{ github.sha }}" + "$IMAGE_BASE:$SHA" docker images "$IMAGE_BASE" --format '{{.Repository}}:{{.Tag}}' \ - | grep -v -e ':latest$' -e ":${{ github.sha }}$" \ + | grep -v -e ':latest$' -e ":$SHA$" \ | xargs -r docker rmi || true \ No newline at end of file