Skip to content
Merged

Fix #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Mentora CI/CD Pipeline

on:
push:
branches: [ main, dev ]
branches: [ main, dev, 'fix' ]
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a literal branch name 'fix' in the trigger is not maintainable. Consider using a pattern like 'fix/*' to support multiple fix branches, or remove this if it's temporary debugging code.

Suggested change
branches: [ main, dev, 'fix' ]
branches: [ main, dev, 'fix/*' ]

Copilot uses AI. Check for mistakes.
pull_request:
branches: [ main ]

Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
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' || github.ref == 'refs/heads/fix'
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -121,32 +121,64 @@ 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' || github.ref == 'refs/heads/fix'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- 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: |
kind create cluster --name mentora-dev

- name: Set kubeconfig context to KinD
run: |
kubectl config use-context kind-mentora-dev

- name: Debug kubectl config
run: |
echo "--- Kubeconfig file content ---"
cat $HOME/.kube/config || echo "Using KinD default kubeconfig"
echo "--- kubectl config view ---"
kubectl config view

Comment on lines +143 to +149
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug steps should be removed from production CI/CD workflows as they can expose sensitive configuration information and add unnecessary execution time.

Suggested change
- name: Debug kubectl config
run: |
echo "--- Kubeconfig file content ---"
cat $HOME/.kube/config || echo "Using KinD default kubeconfig"
echo "--- kubectl config view ---"
kubectl config view
# Debug step removed to avoid exposing sensitive information

Copilot uses AI. Check for mistakes.
- name: Create namespace
run: |
kubectl create namespace ${{ env.NAMESPACE_DEV }} --dry-run=client -o yaml | kubectl apply -f -

- name: Configure kubectl
- name: Create secrets
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
mkdir -p $HOME/.kube
echo -n "${{ secrets.K8S_DEV_CONFIG }}" | base64 -d > $HOME/.kube/config
chmod 600 $HOME/.kube/config
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 --kubeconfig=$HOME/.kube/config

echo "Generated deployment file:"
cat kubernetes/deployment.generated.yaml

kubectl apply -f kubernetes/deployment.generated.yaml
echo "Application deployed with image: ${IMAGE_TAG}"
18 changes: 9 additions & 9 deletions kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +32
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app name 'mentora-app' is hardcoded in multiple places. Consider using an environment variable like ${APP_NAME} to maintain consistency with the other environment variable substitutions and make the deployment more configurable.

Copilot uses AI. Check for mistakes.
imagePullPolicy: Always
ports:
- containerPort: 8080
Expand Down