fix: use Nexus for CI/CD build

This commit is contained in:
2026-09-07 14:12:58 +07:00
parent 894ba4c124
commit 29785df970
+78 -293
View File
@@ -1,312 +1,97 @@
name: CI/CD SIDATA - Rancher
steps:
on:
push:
branches:
- main
# ============================================================
# 1. Cek Docker / Podman API
# ============================================================
- name: Check Container Engine
shell: bash
run: |
set -e
jobs:
build-and-deploy:
runs-on: ubuntu-latest
echo "=========================================="
echo "CONTAINER ENGINE"
echo "=========================================="
env:
# ==========================================================
# Proxy
# ==========================================================
HTTP_PROXY: http://10.15.3.20:80
HTTPS_PROXY: http://10.15.3.20:80
http_proxy: http://10.15.3.20:80
https_proxy: http://10.15.3.20:80
docker version
# ==========================================================
# Internal network bypass proxy
# ==========================================================
NO_PROXY: >-
localhost,
127.0.0.1,
10.81.2.10,
10.15.39.186,
registry-nexus-bpkd.drc-bpkd.data-center.id,
registry-bpkd.drc-bpkd.data-center.id,
.drc-bpkd.data-center.id,
.bpkd.jakarta.go.id
# ============================================================
# 2. Login Nexus
# ============================================================
- name: Login Container Registry
shell: bash
run: |
set -e
no_proxy: >-
localhost,
127.0.0.1,
10.81.2.10,
10.15.39.186,
registry-nexus-bpkd.drc-bpkd.data-center.id,
registry-bpkd.drc-bpkd.data-center.id,
.drc-bpkd.data-center.id,
.bpkd.jakarta.go.id
echo "=========================================="
echo "LOGIN NEXUS"
echo "=========================================="
steps:
echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login \
registry-bpkd.drc-bpkd.data-center.id \
--username "${{ secrets.REGISTRY_USER }}" \
--password-stdin
# ==========================================================
# 1. Informasi Runner
# ==========================================================
- name: Check Runner
shell: bash
run: |
set -e
# ============================================================
# 3. Pull Base Image
# ============================================================
- name: Pull Base Image
shell: bash
run: |
set -e
echo "=========================================="
echo "RUNNER"
echo "=========================================="
echo "=========================================="
echo "PULL BASE IMAGE"
echo "=========================================="
hostname
uname -a
docker pull \
registry-nexus-bpkd.drc-bpkd.data-center.id/php74-fpm-oci8-lengkap:1.0
echo ""
echo "Docker:"
docker --version || true
# ============================================================
# 4. Build
# ============================================================
- name: Build Docker Image
shell: bash
run: |
set -e
echo ""
echo "Podman:"
podman --version || true
echo "=========================================="
echo "BUILD SIDATA"
echo "=========================================="
echo ""
echo "Buildah:"
buildah --version || true
docker build \
--build-arg http_proxy="$HTTP_PROXY" \
--build-arg https_proxy="$HTTPS_PROXY" \
--build-arg HTTP_PROXY="$HTTP_PROXY" \
--build-arg HTTPS_PROXY="$HTTPS_PROXY" \
--build-arg no_proxy="$NO_PROXY" \
--build-arg NO_PROXY="$NO_PROXY" \
-t sidata:latest .
echo ""
echo "Curl:"
curl --version || true
echo "BUILD BERHASIL"
# ==========================================================
# 2. Check Nexus
# ==========================================================
- name: Check Nexus
shell: bash
run: |
set -e
# ============================================================
# 5. Tag
# ============================================================
- name: Tag Image
shell: bash
run: |
set -e
echo "=========================================="
echo "CHECK NEXUS"
echo "=========================================="
IMAGE="registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata"
getent hosts registry-nexus-bpkd.drc-bpkd.data-center.id
docker tag sidata:latest "${IMAGE}:latest"
docker tag sidata:latest "${IMAGE}:${{ gitea.sha }}"
echo ""
echo "Testing Nexus Registry..."
# ============================================================
# 6. Push
# ============================================================
- name: Push Image
shell: bash
run: |
set -e
curl -k -I \
--connect-timeout 10 \
https://registry-nexus-bpkd.drc-bpkd.data-center.id/v2/ \
|| true
IMAGE="registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata"
# ==========================================================
# 3. Login Nexus
# ==========================================================
- name: Login Nexus
shell: bash
run: |
set -e
echo "=========================================="
echo "LOGIN NEXUS"
echo "=========================================="
echo "${{ secrets.NEXUS_PASSWORD }}" | \
docker login \
registry-nexus-bpkd.drc-bpkd.data-center.id \
--username "${{ secrets.NEXUS_USER }}" \
--password-stdin
# ==========================================================
# 4. Login Registry BPKD
# ==========================================================
- name: Login BPKD Registry
shell: bash
run: |
set -e
echo "=========================================="
echo "LOGIN BPKD REGISTRY"
echo "=========================================="
echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login \
registry-bpkd.drc-bpkd.data-center.id \
--username "${{ secrets.REGISTRY_USER }}" \
--password-stdin
# ==========================================================
# 5. Build Image
# ==========================================================
- name: Build SIDATA
shell: bash
run: |
set -e
echo "=========================================="
echo "BUILD SIDATA"
echo "=========================================="
IMAGE="registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata"
docker build \
--build-arg http_proxy="$HTTP_PROXY" \
--build-arg https_proxy="$HTTPS_PROXY" \
--build-arg HTTP_PROXY="$HTTP_PROXY" \
--build-arg HTTPS_PROXY="$HTTPS_PROXY" \
--build-arg no_proxy="$NO_PROXY" \
--build-arg NO_PROXY="$NO_PROXY" \
-t "${IMAGE}:latest" \
-t "${IMAGE}:${GITHUB_SHA:-latest}" \
.
echo ""
echo "IMAGE:"
docker images | grep sidata
# ==========================================================
# 6. Push Image
# ==========================================================
- name: Push SIDATA
shell: bash
run: |
set -e
IMAGE="registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata"
echo "=========================================="
echo "PUSH SIDATA"
echo "=========================================="
docker push "${IMAGE}:latest"
docker push "${IMAGE}:${GITHUB_SHA:-latest}"
# ==========================================================
# 7. Install kubectl
# ==========================================================
- name: Setup kubectl
shell: bash
run: |
set -e
echo "=========================================="
echo "KUBECTL"
echo "=========================================="
if command -v kubectl >/dev/null 2>&1; then
echo "kubectl already available"
kubectl version --client
exit 0
fi
echo "kubectl tidak ditemukan."
if [ -x /usr/local/bin/kubectl ]; then
export PATH="/usr/local/bin:$PATH"
kubectl version --client
exit 0
fi
echo "ERROR: kubectl belum tersedia di runner."
echo "Install kubectl di image/host runner terlebih dahulu."
exit 1
# ==========================================================
# 8. Configure Rancher
# ==========================================================
- name: Configure Rancher
shell: bash
run: |
set -e
echo "=========================================="
echo "CONFIGURE RANCHER"
echo "=========================================="
kubectl config set-cluster rancher-cluster \
--server="${{ secrets.RANCHER_URL }}/k8s/clusters/${{ secrets.RANCHER_CLUSTER_ID }}" \
--insecure-skip-tls-verify=true
kubectl config set-credentials rancher-user \
--token="${{ secrets.RANCHER_TOKEN }}"
kubectl config set-context rancher-context \
--cluster=rancher-cluster \
--user=rancher-user
kubectl config use-context rancher-context
# ==========================================================
# 9. Test Rancher
# ==========================================================
- name: Test Rancher
shell: bash
run: |
set -e
echo "=========================================="
echo "RANCHER"
echo "=========================================="
kubectl cluster-info
kubectl get nodes
# ==========================================================
# 10. Deploy Kubernetes
# ==========================================================
- name: Deploy SIDATA
shell: bash
run: |
set -e
echo "=========================================="
echo "DEPLOY SIDATA"
echo "=========================================="
if [ -f "k8s/deploy.yaml" ]; then
kubectl apply -f k8s/deploy.yaml
elif [ -f "deploy.yaml" ]; then
kubectl apply -f deploy.yaml
else
echo "ERROR: deploy.yaml tidak ditemukan."
exit 1
fi
# ==========================================================
# 11. Update Image
# ==========================================================
- name: Update Image
shell: bash
run: |
set -e
IMAGE="registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata:latest"
kubectl set image \
deployment/sidata \
sidata="${IMAGE}" \
--record=false
# ==========================================================
# 12. Wait Rollout
# ==========================================================
- name: Wait Rollout
shell: bash
run: |
set -e
kubectl rollout status \
deployment/sidata \
--timeout=300s
# ==========================================================
# 13. Status
# ==========================================================
- name: Deployment Status
shell: bash
run: |
echo "=========================================="
echo "DEPLOYMENT STATUS"
echo "=========================================="
kubectl get deployment sidata -o wide
kubectl get pods -l app=sidata -o wide
kubectl get service sidata
kubectl get ingress
docker push "${IMAGE}:latest"
docker push "${IMAGE}:${{ gitea.sha }}"