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

Remove x64 architecture specification from deploy job in workflow #18

Remove x64 architecture specification from deploy job in workflow

Remove x64 architecture specification from deploy job in workflow #18

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
- x64
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker tags
id: docker_tags
run: |
BRANCH="${GITHUB_REF_NAME}"
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
IMAGE_BASE="ghcr.io/${{ github.repository }}"
TAGS=""
if [ "$BRANCH" = "main" ]; then
TAGS+="${IMAGE_BASE}:main,${IMAGE_BASE}:latest,${IMAGE_BASE}:main-${SHORT_SHA}"
elif [ "$BRANCH" = "dev" ]; then
TAGS+="${IMAGE_BASE}:dev,${IMAGE_BASE}:dev-${SHORT_SHA}"
else
TAGS+="${IMAGE_BASE}:${BRANCH},${IMAGE_BASE}:${BRANCH}-${SHORT_SHA}"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- 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: ${{ steps.docker_tags.outputs.tags }}
deploy:
runs-on:
- self-hosted
needs: build-and-push
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Set up kustomize
uses: imranismail/setup-kustomize@v2
with:
kustomize-version: '5.0.0'
- 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
env:
BRANCH_NAME: ${{ github.ref_name }}
SHORT_SHA: ${{ github.sha }}
run: |
if [ "$BRANCH_NAME" = "main" ]; then
OVERLAY=main
IMAGE_TAG="main"
elif [ "$BRANCH_NAME" = "dev" ]; then
OVERLAY=dev
IMAGE_TAG="dev"
else
echo "Branch is not main or dev, skipping deployment."
exit 1
fi
cd k8s/overlays/$OVERLAY
# Create a temporary kustomization that uses the exact image from this build
cp kustomization.yml kustomization.yml.bak
# Update the image tag to use the branch-specific tag
sed -i "s/newTag: .*/newTag: $IMAGE_TAG/" kustomization.yml
echo "Deploying to $OVERLAY environment..."
echo "Using image tag: $IMAGE_TAG"
# Build and apply
kustomize build . | kubectl apply -f -
# Verify deployment
kubectl rollout status deployment/$(kubectl get deployment -n wiki-$OVERLAY -o name | head -1 | cut -d'/' -f2) -n wiki-$OVERLAY --timeout=300s
# Restore original kustomization
mv kustomization.yml.bak kustomization.yml