Skip to content
Open
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
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Backend Environment Variables
DJANGO_DEBUG=False
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,backend
DJANGO_CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
DJANGO_SECRET_KEY=your-secret-key-here-change-in-production

# Frontend Environment Variables
VITE_API_URL=http://localhost:8000

# Docker Hub (for CI/CD)
# DOCKERHUB_USERNAME=your-dockerhub-username
# DOCKERHUB_TOKEN=your-dockerhub-token
112 changes: 112 additions & 0 deletions .github/workflows/docker-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Docker Build and Deploy

on:
push:
branches:
- main
workflow_dispatch:

env:
REGISTRY: docker.io
BACKEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/devops-backend
FRONTEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/devops-frontend

jobs:
build-and-push:
name: Build and Push Docker Images
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for backend
id: backend-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.BACKEND_IMAGE }}
tags: |
type=raw,value=latest
type=sha,prefix={{branch}}-

- name: Build and push backend image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ steps.backend-meta.outputs.tags }}
labels: ${{ steps.backend-meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE }}:buildcache,mode=max

- name: Extract metadata for frontend
id: frontend-meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FRONTEND_IMAGE }}
tags: |
type=raw,value=latest
type=sha,prefix={{branch}}-

- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.frontend-meta.outputs.tags }}
labels: ${{ steps.frontend-meta.outputs.labels }}
build-args: |
VITE_API_URL=${{ secrets.VITE_API_URL || 'http://localhost:8000' }}
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE }}:buildcache,mode=max

- name: Image digest
run: |
echo "Backend image pushed with tags: ${{ steps.backend-meta.outputs.tags }}"
echo "Frontend image pushed with tags: ${{ steps.frontend-meta.outputs.tags }}"

deploy:
name: Deploy Application
needs: build-and-push
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Deploy to Local/Self-Hosted
run: |
echo "Deployment step - Configure based on your target environment"
echo "For cloud deployment (AWS/Azure/GCP), add cloud-specific deployment steps here"
echo "For self-hosted deployment, ensure a GitHub runner is configured on your server"

# Example for self-hosted deployment:
# docker-compose pull
# docker-compose up -d

# Example for AWS ECS:
# aws ecs update-service --cluster <cluster> --service <service> --force-new-deployment

# Example for Azure Container Instances:
# az container create --resource-group <rg> --name <name> --image ${{ env.FRONTEND_IMAGE }}:latest

# Example for GCP Cloud Run:
# gcloud run deploy <service> --image ${{ env.FRONTEND_IMAGE }}:latest --platform managed

- name: Deployment Summary
run: |
echo "✅ Docker images built and pushed to Docker Hub"
echo "📦 Backend: ${{ env.BACKEND_IMAGE }}:latest"
echo "📦 Frontend: ${{ env.FRONTEND_IMAGE }}:latest"
echo "🚀 Deployment completed successfully"
87 changes: 87 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: PR Check

on:
pull_request:
branches:
- main

jobs:
build-test:
name: Build and Test Docker Images
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build backend image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile
push: false
load: true
tags: devops-backend:test

- name: Build frontend image
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: false
load: true
tags: devops-frontend:test
build-args: |
VITE_API_URL=http://localhost:8000

- name: Test backend container
run: |
docker run -d --name test-backend -p 8000:8000 \
-e DJANGO_DEBUG=False \
-e DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 \
devops-backend:test

sleep 10

# Check if container is running
docker ps | grep test-backend

# Check health
curl -f http://localhost:8000/api/hello/ || exit 1

docker stop test-backend
docker rm test-backend

- name: Test frontend container
run: |
docker run -d --name test-frontend -p 3000:80 devops-frontend:test

sleep 5

# Check if container is running
docker ps | grep test-frontend

# Check health
curl -f http://localhost:3000/health || exit 1

docker stop test-frontend
docker rm test-frontend

- name: Check image sizes
run: |
echo "Backend image size:"
docker images devops-backend:test --format "{{.Size}}"

echo "Frontend image size:"
docker images devops-frontend:test --format "{{.Size}}"

- name: Security scan
uses: aquasecurity/trivy-action@master
with:
image-ref: devops-backend:test
format: 'table'
exit-code: '0'
severity: 'CRITICAL,HIGH'
Loading