.
This commit is contained in:
@@ -6,50 +6,62 @@ on:
|
||||
|
||||
env:
|
||||
REGISTRY: git.fpmoz.sum.ba
|
||||
IMAGE_NAME: blazp04/distribuirani
|
||||
IMAGE: git.fpmoz.sum.ba/${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
# ── JOB 1: Build i Push Docker image ──────────────────
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout koda
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Postavi Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Login u Gitea registry
|
||||
run: |
|
||||
echo ${{ secrets.REGISTRY_PASSWORD }} | \
|
||||
docker login $REGISTRY \
|
||||
-u ${{ secrets.REGISTRY_USER }} --stdin
|
||||
|
||||
- name: Prijava na Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
- 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@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
name: image-tag
|
||||
path: tag.txt
|
||||
|
||||
- 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"
|
||||
# ── JOB 2: Deploy na k3s ───────────────────────────────
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout koda
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build i push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
- name: Preuzmi image tag
|
||||
uses: actions/download-artifact@v4
|
||||
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: image-tag
|
||||
|
||||
- name: Ažuriraj image tag u deployment manifestu
|
||||
- name: Postavi kubeconfig
|
||||
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
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||
chmod 600 ~/.kube/config
|
||||
|
||||
- name: Commit i push ažuriranog manifesta
|
||||
- name: Update image tag u manifestu
|
||||
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)
|
||||
TAG=$(cat tag.txt)
|
||||
sed -i "s|image:.*|image: $IMAGE:$TAG|" k8s/distribuirani/deployment.yaml
|
||||
|
||||
- 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