From 77d2bc18073f2e21e0fefe8d159b016bd6fb1b06 Mon Sep 17 00:00:00 2001 From: rock Date: Tue, 8 Sep 2026 19:23:35 -0700 Subject: [PATCH] =?UTF-8?q?ci:=20add=20deploy=20workflow=20=E2=80=94=20ret?= =?UTF-8?q?ag=20SHA=20as=20latest=20on=20main=20merge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deploy.yaml (main push only): - Pull image by SHA tag (already pushed during PR CI) - Tag as :latest and push - No rebuild needed --- .gitea/workflows/build.yaml | 10 ++------ .gitea/workflows/deploy.yaml | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 .gitea/workflows/deploy.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index d4cf924..04abc22 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -50,19 +50,13 @@ jobs: REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - - name: Build Docker image + - name: Build and push Docker image (SHA tag only) run: | docker build --no-cache --progress=plain \ -t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \ - -t "${IMAGE}:latest" \ -f Dockerfile . - - - name: Push Docker image - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' - run: | docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}" - docker push "${IMAGE}:latest" - echo "✓ Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" + echo "Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" - name: Prune unused images run: docker image prune -a --force 2>&1 | tail -3 || true diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..52db832 --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,44 @@ +name: Deploy + +on: + push: + branches: [main] + workflow_dispatch: + +env: + REGISTRY: forgejo.riotpiao.com + IMAGE: forgejo.riotpiao.com/riotpiao-poimen/poimen-memory + DOCKER_HOST: tcp://localhost:2375 + +jobs: + deploy: + name: Tag & Push Latest + runs-on: rust + steps: + - name: Install Docker + run: apt-get update && apt-get install -y docker.io + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get short SHA + id: sha + run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Registry login + run: | + echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \ + --username "${REGISTRY_USER}" --password-stdin + env: + REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} + REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} + + - name: Pull SHA image and tag as latest + run: | + docker pull "${IMAGE}:${{ steps.sha.outputs.short_sha }}" && \ + docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest" && \ + docker push "${IMAGE}:latest" && \ + echo "Tagged and pushed: ${IMAGE}:latest (from ${{ steps.sha.outputs.short_sha }})" + + - name: Prune images + run: docker image prune -a --force 2>&1 | tail -3 || true