5ed2ef0958
Build and Deploy Platform / build-push-deploy (push) Has been cancelled
Harbor in-cluster builds via Kaniko, ArgoCD auto-sync, and production Helm values for abrban.com domains. Co-authored-by: Cursor <cursoragent@cursor.com>
79 lines
2.7 KiB
Bash
Executable File
79 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Trigger in-cluster Kaniko build → Harbor. No local docker build/push.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
NAMESPACE="${BUILD_NAMESPACE:-cloudhost-builds}"
|
|
JOB_NAME="${JOB_NAME:-build-platform-images}"
|
|
GIT_REPO="${GIT_REPO:-http://gitea-http.gitea.svc.cluster.local:3000/abrban/cloud-host.git}"
|
|
GIT_REF="${GIT_REF:-main}"
|
|
IMAGE_TAG="${IMAGE_TAG:-$(date +%Y%m%d-%H%M)}"
|
|
|
|
echo "==> Applying Kaniko build job (tag=${IMAGE_TAG}, ref=${GIT_REF})"
|
|
kubectl -n "${NAMESPACE}" delete job "${JOB_NAME}" --ignore-not-found
|
|
|
|
kubectl apply -f - <<EOF
|
|
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: ${JOB_NAME}
|
|
namespace: ${NAMESPACE}
|
|
spec:
|
|
ttlSecondsAfterFinished: 3600
|
|
backoffLimit: 1
|
|
template:
|
|
spec:
|
|
restartPolicy: Never
|
|
imagePullSecrets:
|
|
- name: registry-pull-secret
|
|
initContainers:
|
|
- name: git-clone
|
|
image: registry.abrban.com/proxy-dockerhub/alpine/git:2.43.0
|
|
command:
|
|
- sh
|
|
- -ec
|
|
- |
|
|
git clone --depth=1 --branch "${GIT_REF}" "${GIT_REPO}" /workspace
|
|
ls -la /workspace
|
|
volumeMounts:
|
|
- name: workspace
|
|
mountPath: /workspace
|
|
containers:
|
|
- name: kaniko
|
|
image: registry.abrban.com/proxy-gcr/kaniko-project/executor:v1.23.2
|
|
command:
|
|
- sh
|
|
- -ec
|
|
- |
|
|
set -eux
|
|
REG="harbor-registry.cloudhost.svc.cluster.local:5000/abrban"
|
|
/kaniko/executor \
|
|
--dockerfile=/workspace/backend/Dockerfile \
|
|
--context=dir:///workspace/backend \
|
|
--destination="${REG}/cloudhost-backend:${IMAGE_TAG}" \
|
|
--insecure --skip-tls-verify
|
|
/kaniko/executor \
|
|
--dockerfile=/workspace/frontend/Dockerfile \
|
|
--context=dir:///workspace/frontend \
|
|
--build-arg=NEXT_PUBLIC_API_URL=https://api.abrban.com \
|
|
--destination="${REG}/cloudhost-frontend:${IMAGE_TAG}" \
|
|
--insecure --skip-tls-verify
|
|
echo "BUILT_TAG=${IMAGE_TAG}"
|
|
volumeMounts:
|
|
- name: workspace
|
|
mountPath: /workspace
|
|
volumes:
|
|
- name: workspace
|
|
emptyDir: {}
|
|
EOF
|
|
|
|
echo "==> Waiting for build job..."
|
|
kubectl -n "${NAMESPACE}" wait --for=condition=complete "job/${JOB_NAME}" --timeout=45m
|
|
|
|
echo "==> Updating values-abrban.yaml tag to ${IMAGE_TAG}"
|
|
sed -i.bak "s|tag: \".*\"|tag: \"${IMAGE_TAG}\"|g" "${ROOT}/gitops/platform/values-abrban.yaml"
|
|
rm -f "${ROOT}/gitops/platform/values-abrban.yaml.bak"
|
|
|
|
echo "==> Build complete. Deploy with:"
|
|
echo " TAG=${IMAGE_TAG} ./scripts/gitops-deploy.sh"
|