70 lines
2.0 KiB
YAML
70 lines
2.0 KiB
YAML
name: CI/CD Pipeline to Rancher - SIDATA
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# ============================================================
|
|
# Checkout
|
|
# ============================================================
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
|
|
# ============================================================
|
|
# Login Registry
|
|
# ============================================================
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: registry-bpkd.drc-bpkd.data-center.id
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
# ============================================================
|
|
# Build & Push
|
|
# ============================================================
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata:latest
|
|
registry-bpkd.drc-bpkd.data-center.id/${{ secrets.REGISTRY_USER }}/sidata:${{ gitea.sha }}
|
|
|
|
# ============================================================
|
|
# Deploy ke Rancher
|
|
# ============================================================
|
|
- name: Deploy to Rancher Cluster
|
|
shell: bash
|
|
run: |
|
|
set -e
|
|
|
|
echo "=== Download kubectl ==="
|
|
|
|
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
|
|
|
|
curl -fLO \
|
|
"https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
|
|
|
|
chmod +x kubectl
|
|
|
|
echo "kubectl version:"
|
|
./kubectl version --client
|
|
|
|
echo "=== Configure Rancher Kubeconfig ==="
|
|
|
|
./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 }}"
|
|
|
|
./ |