Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Update deployment workflow to use self-hosted runners and enhance Kub… #2

Update deployment workflow to use self-hosted runners and enhance Kub…

Update deployment workflow to use self-hosted runners and enhance Kub… #2

Workflow file for this run

name: Deploy to Kubernetes
on:
push:
branches:
- main
- dev
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}:${{ github.sha }}
jobs:
build-and-push:
runs-on: self-hosted
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}
deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Kubeconfig
env:
KUBECONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
run: |
mkdir -p ~/.kube
# Decode and write kubeconfig
echo "${KUBECONFIG_DATA}" | base64 -d > ~/.kube/config
# Verify kubeconfig was decoded properly
if [ ! -s ~/.kube/config ]; then
echo "❌ ERROR: Kubeconfig file is empty after decoding!"
echo "Please verify that KUBECONFIG_DATA secret contains valid base64 encoded kubeconfig"
exit 1
fi
# Set proper permissions
chmod 600 ~/.kube/config
# Verify connection
echo "Testing connection to Kubernetes cluster..."
kubectl cluster-info
- name: Deploy to Kubernetes
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
INGRESS_HOST="wiki.coregame.de"
elif [ "${{ github.ref_name }}" = "dev" ]; then
INGRESS_HOST="dev.wiki.coregame.de"
else
echo "Branch is not main or dev, skipping ingress update."
exit 1
fi
sed -i "s|IMAGE_TAG|${{ env.IMAGE_NAME }}|g" k8s/deployment.yml
sed -i "s|INGRESS_HOST|$INGRESS_HOST|g" k8s/ingress.yml
kubectl apply -f k8s/deployment.yml
kubectl apply -f k8s/service.yml
kubectl apply -f k8s/ingress.yml