Files
step3/.gitea/workflows/deploy-web.yml
T

86 lines
2.8 KiB
YAML

name: Deploy STEP3 Web Game
on:
push:
branches:
- main
workflow_dispatch: {}
jobs:
deploy:
runs-on: self-hosted
env:
IMAGE_TAR: /tmp/step3-web.tar
NODES: "192.168.86.72 192.168.86.73 192.168.86.74"
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set build identity
run: |
echo "BUILD_TAG=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
- name: Reclaim failed build layers
run: |
rm -f "${IMAGE_TAR}"
docker container prune -f
docker image prune -f
docker image prune -af --filter "until=24h"
docker builder prune -af || true
docker system df
df -h
- name: Build Web game image
run: |
docker build --build-arg BUILD_REVISION="${BUILD_TAG}" -f web/Dockerfile -t "step3-web:${BUILD_TAG}" .
- name: Save image
run: |
docker save "step3-web:${BUILD_TAG}" -o "${IMAGE_TAR}"
- name: Import image on Kubernetes nodes
run: |
for node in ${NODES}; do
scp -o StrictHostKeyChecking=no "${IMAGE_TAR}" hz@"$node":/tmp/step3-web.tar
ssh -o StrictHostKeyChecking=no hz@"$node" "sudo ctr -n k8s.io images import /tmp/step3-web.tar && rm -f /tmp/step3-web.tar"
done
- name: Clean runner build artifacts
if: always()
run: |
rm -f "${IMAGE_TAR}"
if [ -n "${BUILD_TAG}" ]; then
docker image rm "step3-web:${BUILD_TAG}" 2>/dev/null || true
fi
docker image prune -f
- name: Configure kubeconfig
env:
KUBECONFIG_CONTENT: ${{ secrets.KUBECONFIG }}
run: |
if [ -n "$KUBECONFIG_CONTENT" ]; then
mkdir -p /tmp/kube
printf '%s\n' "$KUBECONFIG_CONTENT" > /tmp/kube/config
echo "KUBECONFIG=/tmp/kube/config" >> "$GITHUB_ENV"
fi
- name: Deploy Web game
run: |
for attempt in $(seq 1 30); do
if kubectl get --raw "/api/v1/namespaces/step3-questions/services/step3-questions:http/proxy/api/Auth/legal" >/dev/null; then
echo "Merged authentication API is ready."
break
fi
if [ "$attempt" -eq 30 ]; then
echo "Merged authentication API did not become ready; preserving the current web deployment."
exit 1
fi
sleep 10
done
kubectl create namespace step3-web --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f web/k8s/service.yaml -n step3-web
sed "s|step3-web:latest|step3-web:${BUILD_TAG}|" web/k8s/deployment.yaml | kubectl apply -n step3-web -f -
kubectl rollout status deployment/step3-web -n step3-web --timeout=180s