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
This commit is contained in:
parent
9e28d37256
commit
27261f107b
2 changed files with 38 additions and 65 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
Loading…
Add table
Reference in a new issue