75 lines
2.2 KiB
YAML
75 lines
2.2 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: git.fpmoz.sum.ba
|
|
IMAGE: git.fpmoz.sum.ba/${{ github.repository }}
|
|
|
|
jobs:
|
|
# ── JOB 1: Build ──────────────────────────────────────
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout koda
|
|
uses: actions/checkout@v3 # Vraćeno na v3
|
|
|
|
- name: Login u Gitea registry
|
|
run: |
|
|
echo ${{ secrets.REGISTRY_PASS }} | \
|
|
docker login $REGISTRY \
|
|
-u ${{ secrets.REGISTRY_USER }} --password-stdin
|
|
|
|
- name: Build i Push image
|
|
run: |
|
|
TAG=${{ github.sha }}
|
|
docker build -t $IMAGE:$TAG -t $IMAGE:latest .
|
|
docker push $IMAGE:$TAG
|
|
docker push $IMAGE:latest
|
|
echo $TAG > tag.txt
|
|
|
|
- name: Spremi image tag
|
|
uses: actions/upload-artifact@v3 # OVO JE BITNO: v3 umjesto v4
|
|
with:
|
|
name: image-tag
|
|
path: tag.txt
|
|
|
|
# ── JOB 2: Deploy ─────────────────────────────────────
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout koda
|
|
uses: actions/checkout@v3 # Vraćeno na v3
|
|
|
|
- name: Preuzmi image tag
|
|
uses: actions/download-artifact@v3 # OVO JE BITNO: v3 umjesto v4
|
|
with:
|
|
name: image-tag
|
|
|
|
- name: Instaliraj kubectl
|
|
uses: azure/setup-kubectl@v3
|
|
with:
|
|
version: 'latest'
|
|
|
|
- name: Postavi kubeconfig
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
|
|
- name: Update image tag u manifestu
|
|
run: |
|
|
TAG=$(cat tag.txt)
|
|
sed -i "s|image:.*|image: $IMAGE:$TAG|" k8s/deployment.yaml
|
|
|
|
- name: Deploy na k3s
|
|
run: |
|
|
# Koristimo eksplicitnu putanju i gasimo validaciju
|
|
kubectl --kubeconfig=$HOME/.kube/config apply -f k8s/ --validate=false
|
|
|
|
# Provjera statusa za tvoj namespace sz11zs
|
|
kubectl --kubeconfig=$HOME/.kube/config rollout status deployment/hello-cicd \
|
|
-n student-sz11zs --timeout=120s |