name: CI/CD Pipeline on: push: branches: [main] env: REGISTRY: git.fpmoz.sum.ba IMAGE_NAME: blazp04/distribuirani jobs: build-and-push: runs-on: ubuntu-latest steps: - name: Checkout koda uses: actions/checkout@v4 - name: Postavi Docker Buildx uses: docker/setup-buildx-action@v3 - name: Prijava na Gitea Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Generiraj tagove za image id: meta run: | SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7) echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT" echo "tags=${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA},${REGISTRY}/${IMAGE_NAME}:latest" >> "$GITHUB_OUTPUT" - name: Build i push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest cache-to: type=inline - name: Ažuriraj image tag u deployment manifestu run: | SHORT_SHA=${{ steps.meta.outputs.short_sha }} sed -i "s|image: ${REGISTRY}/${IMAGE_NAME}:.*|image: ${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA}|" k8s/distribuirani/deployment.yaml cat k8s/distribuirani/deployment.yaml - name: Commit i push ažuriranog manifesta run: | git config user.name "Gitea Actions" git config user.email "actions@git.fpmoz.sum.ba" git add k8s/distribuirani/deployment.yaml git diff --cached --quiet && echo "Nema promjena" || (git commit -m "ci: update image tag to ${{ steps.meta.outputs.short_sha }} [skip ci]" && git push)