Replace inline cache with dedicated buildcache tag that stores all intermediate builder layers. Unchanged stages like deps and compile will be pulled from cache instead of rebuilt.
85 lines
2.6 KiB
YAML
85 lines
2.6 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: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- 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
|
|
echo "cache_tag=${{ secrets.REGISTRY_URL }}/${{ github.repository }}:buildcache" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v6
|
|
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.cache_tag }}
|
|
cache-to: type=registry,ref=${{ steps.meta.outputs.cache_tag }},mode=max
|
|
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
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."
|