Skip to content

LAP-29: Fixed version for minikube and removed sudo priviledges #70

LAP-29: Fixed version for minikube and removed sudo priviledges

LAP-29: Fixed version for minikube and removed sudo priviledges #70

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ LAP-29 ]
pull_request:
branches: [ LAP-29 ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install uv
run: |
pip install uv
- name: Create virtual environment with uv
run: |
uv venv
source .venv/bin/activate
which python
python --version
- name: Install dependencies
run: |
source .venv/bin/activate
pip install ruff
uv pip install -e .
uv pip install pytest pytest-cov
- name: Run linting and formatting
run: |
source .venv/bin/activate
which ruff
ruff check --fix .
ruff format .
- name: Check for test files
id: check_tests
run: |
if [ -d "backend/test" ] && [ "$(ls -A backend/test/*.py 2>/dev/null | wc -l)" -gt 0 ]; then
echo "tests_exist=true" >> $GITHUB_OUTPUT
else
echo "tests_exist=false" >> $GITHUB_OUTPUT
fi
- name: Run tests
if: steps.check_tests.outputs.tests_exist == 'true'
run: |
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:$(pwd)
python -m pytest backend/test/ --cov=backend --cov-report=xml
- name: Skip tests
if: steps.check_tests.outputs.tests_exist == 'false'
run: |
echo "No test files found. Skipping tests."
touch coverage.xml
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: false
- name: Verify application startup
run: |
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:$(pwd)
# Start the application in the background
python run.py &
APP_PID=$!
# Wait for the application to start
sleep 5
# Check if the application is running
if ps -p $APP_PID > /dev/null; then
echo "Application started successfully"
# Test basic API endpoint
curl -f http://localhost:5000/health || exit 1
# Kill the application
kill $APP_PID
else
echo "Application failed to start"
exit 1
fi
build:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/LAP-29'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install uv
run: |
pip install uv
- name: Create virtual environment with uv
run: |
uv venv
source .venv/bin/activate
which python
python --version
- name: Install dependencies
run: |
source .venv/bin/activate
uv pip install -e .
- name: Build Docker image
run: |
docker build -t spreadsheet-app:${{ github.sha }} .
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push Docker image
run: |
docker tag spreadsheet-app:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:${{ github.sha }}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:${{ github.sha }}
docker tag spreadsheet-app:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:latest
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/LAP-29'
steps:
- uses: actions/checkout@v4
- name: Install Minikube
run: |
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
mv minikube /usr/local/bin/
- name: Start Minikube
run: |
sudo minikube start --driver=docker
minikube status
# - name: Set up Minikube
# uses: manuel-packeisen/[email protected]
# with:
# minikube version: 'latest'
# kubernetes version: 'v1.28.0'
# driver: 'docker'
# start args: '--cpus=2 --memory=4g --disk-size=20g'
- name: Configure kubectl
run: |
minikube kubectl -- get nodes
minikube kubectl -- config view --flatten > kubeconfig.yaml
export KUBECONFIG=kubeconfig.yaml
- name: Deploy to Minikube
run: |
# Create namespace if it doesn't exist
minikube kubectl -- create namespace spreadsheet-app --dry-run=client -o yaml | minikube kubectl -- apply -f -
# Deploy application
minikube kubectl -- apply -f kubernetes/ -n spreadsheet-app
# Update deployment with new image
minikube kubectl -- set image deployment/spreadsheet-app spreadsheet-app=${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:${{ github.sha }} -n spreadsheet-app
# Wait for deployment to be ready
minikube kubectl -- rollout status deployment/spreadsheet-app -n spreadsheet-app
# Get the service URL and test the application
SERVICE_URL=$(minikube service spreadsheet-app -n spreadsheet-app --url)
echo "Waiting for service to be available..."
until curl -f $SERVICE_URL/health; do
echo "Service not ready yet, waiting..."
sleep 5
done
echo "Application is available at: $SERVICE_URL"
# Verify all pods are running
minikube kubectl -- get pods -n spreadsheet-app
# Check application logs
minikube kubectl -- logs deployment/spreadsheet-app -n spreadsheet-app
# Verify service is accessible
curl -f $SERVICE_URL/health || exit 1
# Optional: Run additional tests against the deployed application
# Example: curl -f $SERVICE_URL/api/endpoint || exit 1