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 i Push Docker image ────────────────── build: runs-on: ubuntu-latest steps: - name: Checkout koda uses: actions/checkout@v4 - 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 }} IMAGE_LC=$(echo "$IMAGE" | tr '[:upper:]' '[:lower:]') docker build -t $IMAGE_LC:$TAG -t $IMAGE_LC:latest . docker push $IMAGE_LC:$TAG docker push $IMAGE_LC:latest echo $TAG > tag.txt - name: Spremi image tag uses: actions/upload-artifact@v3 with: name: image-tag path: tag.txt # ── JOB 2: Deploy na k3s ─────────────────────────────── deploy: needs: build runs-on: ubuntu-latest steps: - name: Checkout koda uses: actions/checkout@v4 - name: Preuzmi image tag uses: actions/download-artifact@v3 with: name: image-tag - name: Instaliraj kubectl run: | curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" chmod +x kubectl mv kubectl /usr/local/bin/ - name: Postavi kubeconfig run: | mkdir -p ~/.kube cat <<'EOF' > ~/.kube/config.base64 ${{ secrets.KUBE_CONFIG }} EOF tr -d '[:space:]' < ~/.kube/config.base64 | base64 -d > ~/.kube/config chmod 600 ~/.kube/config - name: Update image tag u manifestu run: | TAG=$(cat tag.txt) IMAGE_LC=$(echo "$IMAGE" | tr '[:upper:]' '[:lower:]') sed -i "s|image:.*|image: $IMAGE_LC:$TAG|" k8s/deployment.yaml - name: Deploy na k3s run: | kubectl apply -f k8s/ -n student-ivanivso7 kubectl rollout status deployment/hello-cicd \ -n student-ivanivso7 --timeout=120s