refactor: simplified pipeline with offline Nexus + auto deploy
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled

This commit is contained in:
masoodafar-web
2026-01-29 06:12:15 +03:30
parent 66884d8216
commit fc5d81425a
+17 -32
View File
@@ -1,4 +1,4 @@
name: Build and Deploy
name: Build and Deploy to Kubernetes
on:
push:
@@ -6,63 +6,48 @@ on:
- kub-stage
env:
REGISTRY: gitea-svc:3000
REGISTRY: 194.5.195.53:30080
IMAGE_NAME: admin/backoffice
K8S_SERVER: 194.5.195.53
jobs:
build:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: docker:latest
image: 194.5.195.53:32082/docker:latest
options: --privileged
steps:
- name: Start Docker daemon with insecure registry
- name: Start Docker daemon
run: |
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'DAEMON'
{
"insecure-registries": ["194.5.195.53:30080", "194.5.195.53:32500", "194.5.195.53:32082", "gitea-svc:3000"],
"dns": ["0.0.0.0"]
"insecure-registries": ["194.5.195.53:30080", "194.5.195.53:32500", "194.5.195.53:32082"]
}
DAEMON
# بدون اینترنت - استفاده از local registry
dockerd &
for i in $(seq 1 30); do
docker info >/dev/null 2>&1 && break || sleep 2
done
docker info
# بررسی دسترسی به local registry
echo "📊 Checking local registry..."
nc -zv 194.5.195.53 32500 || echo "⚠️ WARNING: Cannot connect to local registry!"
for i in $(seq 1 30); do docker info >/dev/null 2>&1 && break || sleep 2; done
- name: Checkout code
run: |
git clone --depth 1 --branch kub-stage http://gitea-svc:3000/admin/BackOffice.git .
git log -1 --format="%H %s"
- name: Build Docker Image
run: |
cd src
# استفاده از cached base images (بدون دانلود)
DOCKER_BUILDKIT=0 docker build -f BackOffice/Dockerfile \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
.
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest -f BackOffice/Dockerfile .
- name: Push to Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u admin --password-stdin
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Build and Push Complete
- name: Deploy to Kubernetes
run: |
echo "🎉 Build and push completed successfully!"
echo "📦 Image pushed to: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
echo "📦 Latest tag: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
echo ""
echo "🚀 To deploy manually on server:"
echo "kubectl set image deployment/backoffice backoffice=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
which sshpass || apk add --no-cache openssh-client sshpass
export SSHPASS="${{ secrets.SERVER_PASSWORD }}"
sshpass -e ssh -o StrictHostKeyChecking=no root@${{ env.K8S_SERVER }} "
kubectl rollout restart deployment/backoffice
kubectl rollout status deployment/backoffice --timeout=180s
"
echo "✅ Deployed!"