86 lines
2.5 KiB
YAML
86 lines
2.5 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
DOCKER_BUILDKIT: 1
|
|
DOCKER_TLS_CERTDIR: ""
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to container registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
run: |
|
|
echo "image=${{ secrets.REGISTRY_URL }}/${{ github.repository }}" >> $GITHUB_OUTPUT
|
|
echo "sha_tag=${{ secrets.REGISTRY_URL }}/${{ github.repository }}:${{ github.sha }}" >> $GITHUB_OUTPUT
|
|
echo "latest_tag=${{ secrets.REGISTRY_URL }}/${{ github.repository }}:latest" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: k8s/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ steps.meta.outputs.sha_tag }}
|
|
${{ steps.meta.outputs.latest_tag }}
|
|
cache-from: type=registry,ref=${{ steps.meta.outputs.latest_tag }}
|
|
cache-to: type=inline
|
|
build-args: |
|
|
BUILDKIT_INLINE_CACHE=1
|
|
|
|
deploy:
|
|
runs-on: self-hosted
|
|
needs: build
|
|
environment:
|
|
name: production
|
|
steps:
|
|
- name: Set up kubectl
|
|
run: |
|
|
# Verify kubectl is available
|
|
kubectl version --client
|
|
|
|
- name: Configure kubectl
|
|
run: |
|
|
# Configure kubectl context
|
|
kubectl config get-contexts
|
|
kubectl config use-context towerops/towerops:home-cluster-agent
|
|
|
|
- name: Deploy to Kubernetes
|
|
run: |
|
|
# 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=${{ secrets.REGISTRY_URL }}/${{ github.repository }}:${{ github.sha }} \
|
|
-n towerops
|
|
|
|
kubectl set env deployment/towerops \
|
|
DEPLOY_TIMESTAMP=$DEPLOY_TIMESTAMP \
|
|
-n towerops
|
|
|
|
echo "Deployment initiated. Kubernetes will handle rollout asynchronously."
|