From 27261f107b9db5bbe934da0f30741a7e9db47c18 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 4 Mar 2026 17:26:17 -0600 Subject: [PATCH] feat: migrate deployment to Forgejo Actions from GitLab CI Consolidated build and deployment into Forgejo Actions workflow: - Added deployment job that runs after successful build - Uses kubectl to deploy to Kubernetes cluster - Sets image and deployment timestamp - Removed GitLab CI configuration Required setup: - Add KUBECONFIG secret to Forgejo (base64 encoded kubeconfig file) - Secret should contain context: towerops/towerops:home-cluster-agent --- .forgejo/workflows/build-deploy.yml | 38 +++++++++++++++++ .gitlab-ci.yml | 65 ----------------------------- 2 files changed, 38 insertions(+), 65 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.forgejo/workflows/build-deploy.yml b/.forgejo/workflows/build-deploy.yml index 8d47c1a4..d14c8c63 100644 --- a/.forgejo/workflows/build-deploy.yml +++ b/.forgejo/workflows/build-deploy.yml @@ -62,3 +62,41 @@ jobs: ${{ steps.meta.outputs.latest_tag }} cache-from: type=registry,ref=${{ steps.meta.outputs.cache_tag }} cache-to: type=registry,ref=${{ steps.meta.outputs.cache_tag }},mode=max + + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - name: Extract metadata + id: meta + run: | + TIMESTAMP=$(date +%s) + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) + IMAGE=${{ secrets.REGISTRY_URL }}/${{ github.repository }} + echo "tag=${IMAGE}:main-${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT + + - name: Set up kubectl + uses: https://github.com/azure/setup-kubectl@v4 + with: + version: 'latest' + + - name: Deploy to Kubernetes + env: + KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }} + run: | + # Set up kubeconfig + mkdir -p $HOME/.kube + echo "$KUBECONFIG_DATA" | base64 -d > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + # Verify connection + kubectl config get-contexts + kubectl config use-context towerops/towerops:home-cluster-agent + + # Set deployment timestamp (ISO 8601 format in UTC) + DEPLOY_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "Deploying at $DEPLOY_TIMESTAMP" + + # Deploy new version (migrations run on app start) + kubectl set image deployment/towerops towerops=${{ steps.meta.outputs.tag }} -n towerops + kubectl set env deployment/towerops DEPLOY_TIMESTAMP=$DEPLOY_TIMESTAMP -n towerops diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index dc2cd352..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,65 +0,0 @@ -stages: - - build - - deploy - -variables: - DOCKER_BUILDKIT: 1 - CI_BUILDX_ARCHS: "linux/amd64" - DOCKER_TLS_CERTDIR: "" - -workflow: - auto_cancel: - on_new_commit: interruptible - -build: - stage: build - interruptible: true - tags: - - home - image: docker:27 - services: - - docker:27-dind - before_script: - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - script: - # Pull latest image for layer caching (ignore failures if not exists) - - docker pull $CI_REGISTRY_IMAGE:latest || true - # Build with cache-from for faster builds and inline cache for future builds - - docker build - --cache-from $CI_REGISTRY_IMAGE:latest - --build-arg BUILDKIT_INLINE_CACHE=1 - -f k8s/Dockerfile - -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - -t $CI_REGISTRY_IMAGE:latest - . - - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - - docker push $CI_REGISTRY_IMAGE:latest - rules: - - if: $CI_COMMIT_BRANCH == "main" - -deploy: - stage: deploy - needs: - - job: build - artifacts: false - tags: - - home - image: - name: bitnami/kubectl:latest - entrypoint: [""] - script: - - kubectl config get-contexts - - kubectl config use-context towerops/towerops:home-cluster-agent - # Set deployment timestamp (ISO 8601 format in UTC) - - DEPLOY_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - - echo "Deploying at $DEPLOY_TIMESTAMP" - # Deploy new version (migrations run on app start) - - kubectl set image deployment/towerops towerops=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n towerops - - kubectl set env deployment/towerops DEPLOY_TIMESTAMP=$DEPLOY_TIMESTAMP -n towerops - # Don't wait for rollout completion - let Kubernetes handle it asynchronously - environment: - name: production - kubernetes: - namespace: towerops - rules: - - if: $CI_COMMIT_BRANCH == "main"