392e038913
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 10m11s
- Modified the kub-deploy.yml to remove cached images using containerd's ctr command, ensuring that both IfNotPresent and Always image pull policies work correctly. - Updated frontoffice-deployment.yaml to set imagePullPolicy to Always, preventing stale node cache issues with the :latest tag. These changes improve the deployment process and ensure that the latest images are always used in the staging environment.
87 lines
3.1 KiB
YAML
87 lines
3.1 KiB
YAML
name: Build and Deploy to Kubernetes
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- kub-stage
|
|
|
|
env:
|
|
REGISTRY: 185.252.31.44:30080
|
|
IMAGE_NAME: admin/frontoffice
|
|
K8S_SERVER: 185.252.31.44
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: 185.252.31.44:32082/docker-sshpass:latest
|
|
options: --privileged
|
|
steps:
|
|
- name: Start Docker daemon
|
|
run: |
|
|
mkdir -p /etc/docker
|
|
cat > /etc/docker/daemon.json << 'DAEMON'
|
|
{
|
|
"insecure-registries": ["185.252.31.44:30080", "185.252.31.44:32500", "185.252.31.44:32082"]
|
|
}
|
|
DAEMON
|
|
echo "🚀 Starting Docker daemon..."
|
|
dockerd --iptables=false --ip6tables=false --bridge=none --storage-driver=vfs &
|
|
|
|
# Wait up to 3 minutes for Docker to be ready
|
|
for i in $(seq 1 90); do
|
|
if docker info >/dev/null 2>&1; then
|
|
echo "✅ Docker daemon is ready (attempt $i)"
|
|
docker version
|
|
break
|
|
else
|
|
echo "⏳ Waiting for Docker daemon... (attempt $i/90)"
|
|
sleep 2
|
|
fi
|
|
done
|
|
|
|
# Final check
|
|
if ! docker info >/dev/null 2>&1; then
|
|
echo "❌ Docker daemon failed to start after 3 minutes"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Checkout code
|
|
run: |
|
|
git clone --depth 1 --branch kub-stage http://gitea-svc:3000/admin/FrontOffice.git .
|
|
|
|
- name: Login to Docker registries
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login 185.252.31.44:32082 -u admin --password-stdin
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
|
|
|
|
- name: Build Docker Image
|
|
run: |
|
|
cd src
|
|
DOCKER_BUILDKIT=0 docker build --network host -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -f FrontOffice.Main/Dockerfile .
|
|
|
|
- name: Push to Registry
|
|
run: |
|
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
|
|
- name: Deploy to Kubernetes
|
|
run: |
|
|
export SSHPASS="${{ secrets.SERVER_PASSWORD }}"
|
|
|
|
# Copy K8s manifests to server
|
|
sshpass -e scp -o StrictHostKeyChecking=no k8s/staging/frontoffice-deployment.yaml root@${{ env.K8S_SERVER }}:/tmp/frontoffice-deployment.yaml
|
|
|
|
# Apply manifests and restart
|
|
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ env.K8S_SERVER }} "
|
|
kubectl apply -n kbs-stage -f /tmp/frontoffice-deployment.yaml &&
|
|
# Drop cached :latest so IfNotPresent/Always both pick the new digest
|
|
# (crictl is broken on this host — use containerd ctr)
|
|
ctr -n k8s.io images ls -q | grep -E 'frontoffice(:latest|@)' | while read -r ref; do
|
|
ctr -n k8s.io images rm \"\$ref\" 2>/dev/null || true
|
|
done
|
|
kubectl -n kbs-stage rollout restart deployment/frontoffice &&
|
|
kubectl -n kbs-stage rollout status deployment/frontoffice --timeout=180s &&
|
|
rm -f /tmp/frontoffice-deployment.yaml
|
|
"
|
|
echo "✅ Deployed!"
|