From 0f3d3fa5c6309d933d5a05497461dbd6def40edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:19:17 +0300 Subject: [PATCH 01/12] fix --- .github/workflows/ci-cd.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index be71e68..e115992 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: Mentora CI/CD Pipeline on: push: - branches: [ main, dev ] + branches: [ main, dev, fix ] pull_request: branches: [ main ] @@ -137,6 +137,13 @@ jobs: echo -n "${{ secrets.K8S_DEV_CONFIG }}" | base64 -d > $HOME/.kube/config chmod 600 $HOME/.kube/config + - name: Debug kubectl config + run: | + echo "--- Kubeconfig file content ---" + cat $HOME/.kube/config + echo "--- kubectl config view ---" + kubectl config view --kubeconfig=$HOME/.kube/config + - name: Deploy to Kubernetes env: POSTGRES_USER: ${{ secrets.POSTGRES_USER }} From 21eb4c6c83ba231d4deced26b256e13b5ea2ec54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:23:57 +0300 Subject: [PATCH 02/12] fix --- .github/workflows/ci-cd.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index e115992..825e0a9 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: Mentora CI/CD Pipeline on: push: - branches: [ main, dev, fix ] + branches: [ main, dev, 'fix/**' ] pull_request: branches: [ main ] @@ -75,8 +75,7 @@ jobs: # Docker Build and Push dev-build-docker-image: runs-on: ubuntu-latest - needs: [dev-frontend-build, dev-backend-build] - if: github.ref == 'refs/heads/dev' + if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix/') permissions: contents: read packages: write @@ -121,7 +120,7 @@ jobs: dev-apply-deployment: runs-on: ubuntu-latest needs: dev-build-docker-image - if: github.ref == 'refs/heads/dev' + if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix/') steps: - name: Checkout code uses: actions/checkout@v4 From e2cf3921d38ec87d35d2b9b938a2b19ba182324b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:25:00 +0300 Subject: [PATCH 03/12] fix --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 825e0a9..eb90495 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: Mentora CI/CD Pipeline on: push: - branches: [ main, dev, 'fix/**' ] + branches: [ main, dev, fix ] pull_request: branches: [ main ] @@ -75,7 +75,7 @@ jobs: # Docker Build and Push dev-build-docker-image: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix/') + if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix') permissions: contents: read packages: write @@ -120,7 +120,7 @@ jobs: dev-apply-deployment: runs-on: ubuntu-latest needs: dev-build-docker-image - if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix/') + if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix') steps: - name: Checkout code uses: actions/checkout@v4 From 57f8f5ee8f0b8fb4932310afe4b9911d7a02d2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:29:01 +0300 Subject: [PATCH 04/12] fix --- .github/workflows/ci-cd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index eb90495..c39f8a8 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,7 @@ name: Mentora CI/CD Pipeline on: push: - branches: [ main, dev, fix ] + branches: [ main, dev, 'fix' ] pull_request: branches: [ main ] @@ -75,7 +75,7 @@ jobs: # Docker Build and Push dev-build-docker-image: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix') + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix' permissions: contents: read packages: write @@ -120,7 +120,7 @@ jobs: dev-apply-deployment: runs-on: ubuntu-latest needs: dev-build-docker-image - if: github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/fix') + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix' steps: - name: Checkout code uses: actions/checkout@v4 From f3c7a662e61166dcfddf53ee25058bb526f3dc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:40:13 +0300 Subject: [PATCH 05/12] fix --- .github/workflows/ci-cd.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index c39f8a8..ee0ce15 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -125,12 +125,20 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Create KinD cluster (local testing only) + if: env.LOCAL_K8S_TEST == 'true' + uses: helm/kind-action@v1 + with: + install_only: false + cluster_name: mentora-dev + - name: Setup kubectl uses: azure/setup-kubectl@v3 with: version: 'latest' - - name: Configure kubectl + - name: Configure kubectl for remote + if: env.LOCAL_K8S_TEST != 'true' run: | mkdir -p $HOME/.kube echo -n "${{ secrets.K8S_DEV_CONFIG }}" | base64 -d > $HOME/.kube/config @@ -139,9 +147,9 @@ jobs: - name: Debug kubectl config run: | echo "--- Kubeconfig file content ---" - cat $HOME/.kube/config + cat $HOME/.kube/config || echo "Using KinD default kubeconfig" echo "--- kubectl config view ---" - kubectl config view --kubeconfig=$HOME/.kube/config + kubectl config view - name: Deploy to Kubernetes env: @@ -154,5 +162,5 @@ jobs: IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-dev:${{ env.VERSION }}-${{ github.run_id }}" export IMAGE="${IMAGE_TAG}" envsubst < kubernetes/deployment.yaml > kubernetes/deployment.generated.yaml - kubectl apply -f kubernetes/deployment.generated.yaml --validate=false --kubeconfig=$HOME/.kube/config + kubectl apply -f kubernetes/deployment.generated.yaml --validate=false echo "Application deployed with image: ${IMAGE_TAG}" \ No newline at end of file From 3e7a18409497e88b4dd2ee8573acf2c1dff192ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:49:16 +0300 Subject: [PATCH 06/12] fix --- .github/workflows/ci-cd.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ee0ce15..c07aed7 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -125,8 +125,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Create KinD cluster (local testing only) - if: env.LOCAL_K8S_TEST == 'true' + - name: Create KinD cluster uses: helm/kind-action@v1 with: install_only: false @@ -137,13 +136,6 @@ jobs: with: version: 'latest' - - name: Configure kubectl for remote - if: env.LOCAL_K8S_TEST != 'true' - run: | - mkdir -p $HOME/.kube - echo -n "${{ secrets.K8S_DEV_CONFIG }}" | base64 -d > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - name: Debug kubectl config run: | echo "--- Kubeconfig file content ---" From 201ace54e4081d0c78522c76cff4cd815143d098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 16:55:50 +0300 Subject: [PATCH 07/12] fix --- .github/workflows/ci-cd.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index c07aed7..e4d01fe 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -75,6 +75,7 @@ jobs: # Docker Build and Push dev-build-docker-image: runs-on: ubuntu-latest + needs: [dev-frontend-build, dev-backend-build] if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/fix' permissions: contents: read @@ -136,6 +137,10 @@ jobs: with: version: 'latest' + - name: Set kubeconfig context to KinD + run: | + kubectl config use-context kind-mentora-dev + - name: Debug kubectl config run: | echo "--- Kubeconfig file content ---" From 3d13ccb9fc8552323d0dc871d7fd90ef5adbc5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 17:00:43 +0300 Subject: [PATCH 08/12] fix --- .github/workflows/ci-cd.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index e4d01fe..0cd4073 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -117,7 +117,7 @@ jobs: docker push ${IMAGE_TAG} echo "image ${IMAGE_TAG} pushed" - # Kubernetes Deployment + # Kubernetes Deployment dev-apply-deployment: runs-on: ubuntu-latest needs: dev-build-docker-image @@ -137,9 +137,19 @@ jobs: with: version: 'latest' + - name: List kubectl contexts + run: kubectl config get-contexts + - name: Set kubeconfig context to KinD run: | + # Check if context exists before setting it + if kubectl config get-contexts | grep -q "kind-mentora-dev"; then kubectl config use-context kind-mentora-dev + else + echo "ERROR: KinD context 'kind-mentora-dev' not found. Available contexts:" + kubectl config get-contexts + exit 1 + fi - name: Debug kubectl config run: | From e177183c3844fda818895892c7f6482fe64d14e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 17:10:27 +0300 Subject: [PATCH 09/12] fix --- .github/workflows/ci-cd.yml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 0cd4073..4003a11 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -126,30 +126,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Create KinD cluster - uses: helm/kind-action@v1 - with: - install_only: false - cluster_name: mentora-dev - - - name: Setup kubectl - uses: azure/setup-kubectl@v3 - with: - version: 'latest' + - name: Install KinD + uses: engineerd/setup-kind@v0.5.0 - - name: List kubectl contexts - run: kubectl config get-contexts + - name: Create KinD cluster + run: | + kind create cluster --name mentora-dev - name: Set kubeconfig context to KinD run: | - # Check if context exists before setting it - if kubectl config get-contexts | grep -q "kind-mentora-dev"; then kubectl config use-context kind-mentora-dev - else - echo "ERROR: KinD context 'kind-mentora-dev' not found. Available contexts:" - kubectl config get-contexts - exit 1 - fi - name: Debug kubectl config run: | From 17a89384adbec7cce5b6496fcbe204991873fc40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 17:17:22 +0300 Subject: [PATCH 10/12] fix --- .github/workflows/ci-cd.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 4003a11..ae7016c 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -126,8 +126,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install KinD - uses: engineerd/setup-kind@v0.5.0 + - name: Install latest kind + run: | + curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64 + chmod +x ./kind + sudo mv ./kind /usr/local/bin/kind - name: Create KinD cluster run: | From cf233b0795a5a9c8216a7d8699d2ed51c41cdb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 17:43:47 +0300 Subject: [PATCH 11/12] fix --- .github/workflows/ci-cd.yml | 38 ++++++++++++++++++++++++++++++++----- kubernetes/deployment.yaml | 18 +++++++++--------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ae7016c..8a6f348 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -117,7 +117,7 @@ jobs: docker push ${IMAGE_TAG} echo "image ${IMAGE_TAG} pushed" - # Kubernetes Deployment + # Kubernetes Deployment dev-apply-deployment: runs-on: ubuntu-latest needs: dev-build-docker-image @@ -147,16 +147,44 @@ jobs: echo "--- kubectl config view ---" kubectl config view + - name: Create namespace + run: | + kubectl create namespace ${{ env.NAMESPACE_DEV }} --dry-run=client -o yaml | kubectl apply -f - + + - name: Create secrets + env: + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + kubectl create secret generic app-secrets \ + --from-literal=POSTGRES_USER="${POSTGRES_USER}" \ + --from-literal=POSTGRES_PASSWORD="${POSTGRES_PASSWORD}" \ + --from-literal=OPENAI_API_KEY="${OPENAI_API_KEY}" \ + --namespace=${{ env.NAMESPACE_DEV }} \ + --dry-run=client -o yaml | kubectl apply -f - + - name: Deploy to Kubernetes env: POSTGRES_USER: ${{ secrets.POSTGRES_USER }} POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - APP: ${{ env.APP }} - NAMESPACE: ${{ env.NAMESPACE_DEV }} run: | IMAGE_TAG="${{ env.DOCKER_SERVER }}/${{ github.repository }}-dev:${{ env.VERSION }}-${{ github.run_id }}" + export IMAGE="${IMAGE_TAG}" + export NAMESPACE="${{ env.NAMESPACE_DEV }}" + envsubst < kubernetes/deployment.yaml > kubernetes/deployment.generated.yaml - kubectl apply -f kubernetes/deployment.generated.yaml --validate=false - echo "Application deployed with image: ${IMAGE_TAG}" \ No newline at end of file + + echo "Generated deployment file:" + cat kubernetes/deployment.generated.yaml + + kubectl apply -f kubernetes/deployment.generated.yaml + echo "Application deployed with image: ${IMAGE_TAG}" + + - name: Verify deployment + run: | + kubectl get pods -n ${{ env.NAMESPACE_DEV }} + kubectl get services -n ${{ env.NAMESPACE_DEV }} + kubectl rollout status deployment/mentora-app -n ${{ env.NAMESPACE_DEV }} --timeout=300s \ No newline at end of file diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml index 21aa8d8..f062edf 100644 --- a/kubernetes/deployment.yaml +++ b/kubernetes/deployment.yaml @@ -1,35 +1,35 @@ apiVersion: v1 kind: Service metadata: - name: #APP# - namespace: #NAMESPACE# + name: mentora-app + namespace: ${NAMESPACE} spec: ports: - port: 8080 targetPort: 8080 selector: - app: #APP# + app: mentora-app --- apiVersion: apps/v1 kind: Deployment metadata: - name: #APP# - namespace: #NAMESPACE# + name: mentora-app + namespace: ${NAMESPACE} spec: selector: matchLabels: - app: #APP# + app: mentora-app replicas: 1 template: metadata: labels: - app: #APP# + app: mentora-app spec: containers: - - image: #IMAGE# - name: #APP# + - image: ${IMAGE} + name: mentora-app imagePullPolicy: Always ports: - containerPort: 8080 From b457afb595970a090383121d2a0f0ca570fa4bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Enes=20Akal=C4=B1n?= Date: Thu, 18 Sep 2025 17:55:17 +0300 Subject: [PATCH 12/12] finale fix i promise --- .github/workflows/ci-cd.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 8a6f348..f1c9509 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -181,10 +181,4 @@ jobs: cat kubernetes/deployment.generated.yaml kubectl apply -f kubernetes/deployment.generated.yaml - echo "Application deployed with image: ${IMAGE_TAG}" - - - name: Verify deployment - run: | - kubectl get pods -n ${{ env.NAMESPACE_DEV }} - kubectl get services -n ${{ env.NAMESPACE_DEV }} - kubectl rollout status deployment/mentora-app -n ${{ env.NAMESPACE_DEV }} --timeout=300s \ No newline at end of file + echo "Application deployed with image: ${IMAGE_TAG}" \ No newline at end of file