.
This commit is contained in:
@@ -6,50 +6,62 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.fpmoz.sum.ba
|
REGISTRY: git.fpmoz.sum.ba
|
||||||
IMAGE_NAME: blazp04/distribuirani
|
IMAGE: git.fpmoz.sum.ba/${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
# ── JOB 1: Build i Push Docker image ──────────────────
|
||||||
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout koda
|
- name: Checkout koda
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Postavi Docker Buildx
|
- name: Login u Gitea registry
|
||||||
uses: docker/setup-buildx-action@v3
|
run: |
|
||||||
|
echo ${{ secrets.REGISTRY_PASSWORD }} | \
|
||||||
|
docker login $REGISTRY \
|
||||||
|
-u ${{ secrets.REGISTRY_USER }} --stdin
|
||||||
|
|
||||||
- name: Prijava na Gitea Container Registry
|
- name: Build i Push image
|
||||||
uses: docker/login-action@v3
|
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@v4
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
name: image-tag
|
||||||
username: ${{ secrets.REGISTRY_USER }}
|
path: tag.txt
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Generiraj tagove za image
|
# ── JOB 2: Deploy na k3s ───────────────────────────────
|
||||||
id: meta
|
deploy:
|
||||||
run: |
|
needs: build
|
||||||
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
runs-on: ubuntu-latest
|
||||||
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
|
steps:
|
||||||
echo "tags=${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA},${REGISTRY}/${IMAGE_NAME}:latest" >> "$GITHUB_OUTPUT"
|
- name: Checkout koda
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build i push Docker image
|
- name: Preuzmi image tag
|
||||||
uses: docker/build-push-action@v5
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
context: .
|
name: image-tag
|
||||||
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
|
- name: Postavi kubeconfig
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=${{ steps.meta.outputs.short_sha }}
|
mkdir -p ~/.kube
|
||||||
sed -i "s|image: ${REGISTRY}/${IMAGE_NAME}:.*|image: ${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA}|" k8s/distribuirani/deployment.yaml
|
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||||
cat k8s/distribuirani/deployment.yaml
|
chmod 600 ~/.kube/config
|
||||||
|
|
||||||
- name: Commit i push ažuriranog manifesta
|
- name: Update image tag u manifestu
|
||||||
run: |
|
run: |
|
||||||
git config user.name "Gitea Actions"
|
TAG=$(cat tag.txt)
|
||||||
git config user.email "actions@git.fpmoz.sum.ba"
|
sed -i "s|image:.*|image: $IMAGE:$TAG|" k8s/distribuirani/deployment.yaml
|
||||||
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)
|
- name: Deploy na k3s
|
||||||
|
run: |
|
||||||
|
kubectl apply -f k8s/distribuirani/
|
||||||
|
kubectl rollout status deployment/distribuirani \
|
||||||
|
-n student-${{ github.actor }} --timeout=120s
|
||||||
|
|||||||
Reference in New Issue
Block a user