Containerize k8s #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🚗 Dealership App CI/CD | |
on: | |
push: | |
branches: [ main, develop ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📥 Checkout code | |
uses: actions/checkout@v4 | |
- name: 🐳 Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: 🔧 Create .env file | |
run: | | |
cp .env.template .env | |
echo "DJANGO_SECRET_KEY=github-actions-test-key" >> .env | |
- name: 🏗️ Build and start services | |
run: | | |
docker-compose up -d --build | |
- name: ⏳ Wait for services to be ready | |
run: | | |
# Wait for Django to be ready | |
timeout 120 bash -c 'until curl -f http://localhost:8000/; do sleep 2; done' | |
# Wait for API to be ready | |
timeout 60 bash -c 'until curl -f http://localhost:3030/health; do sleep 2; done' | |
- name: 🧪 Run application tests | |
run: | | |
# Test Django application | |
echo "Testing Django application..." | |
curl -f http://localhost:8000/ || exit 1 | |
# Test API endpoints | |
echo "Testing API endpoints..." | |
curl -f http://localhost:3030/health || exit 1 | |
curl -f http://localhost:3030/fetchDealers | jq length || exit 1 | |
# Test admin panel | |
echo "Testing admin panel..." | |
curl -f http://localhost:8000/admin/ || exit 1 | |
- name: 🔍 Check service logs | |
if: failure() | |
run: | | |
echo "=== Django Logs ===" | |
docker-compose logs dealership_django | |
echo "=== API Logs ===" | |
docker-compose logs dealership_api | |
echo "=== MongoDB Logs ===" | |
docker-compose logs mongodb | |
- name: 🧹 Cleanup | |
if: always() | |
run: | | |
docker-compose down -v | |
build-and-push: | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: 📥 Checkout code | |
uses: actions/checkout@v4 | |
- name: 🐳 Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: 🏗️ Build Django image | |
run: | | |
docker build -t dealership-django ./server | |
- name: 🏗️ Build API image | |
run: | | |
docker build -t dealership-api ./server/database | |
- name: ✅ Verify builds | |
run: | | |
docker images | grep dealership |