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
73 changes: 73 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI Pipeline

on:
push:
branches:
- develop

jobs:
backend-tests:
name: Backend Tests
runs-on: ubuntu-latest

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

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install backend dependencies
run: |
cd backend
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

- name: Run backend tests
run: |
cd backend
source venv/bin/activate
pytest

frontend-tests:
name: Frontend E2E Tests
runs-on: ubuntu-latest
needs: backend-tests

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

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Install frontend dependencies
run: |
cd frontend
npm ci

- name: Install Playwright browsers
run: |
cd frontend
npx playwright install --with-deps

- name: Start backend
run: |
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
nohup uvicorn app.main:app --host 0.0.0.0 --port 8000 &

- name: Run frontend E2E tests
run: |
cd frontend
npm run dev &
sleep 10
npx playwright test
27 changes: 27 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -------- Builder stage --------
FROM python:3.12-slim AS builder

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt

# -------- Runtime stage --------
FROM python:3.12-slim

WORKDIR /app

# Create non-root user
RUN useradd -m appuser

COPY --from=builder /usr/local/lib/python3.12 /usr/local/lib/python3.12
COPY --from=builder /usr/local/bin /usr/local/bin

COPY app ./app

USER appuser

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.9"

services:
backend:
build: ./backend
ports:
- "8000:8000"

frontend:
build: ./frontend
ports:
- "3000:3000"
environment:
- NEXT_PUBLIC_API_URL=http://backend:8000
depends_on:
- backend
23 changes: 23 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -------- Builder stage --------
FROM node:18-alpine AS builder

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
RUN npm run build

# -------- Runtime stage --------
FROM node:18-alpine

WORKDIR /app

ENV NODE_ENV=production

COPY --from=builder /app ./

EXPOSE 3000

CMD ["npm", "run", "start"]
60 changes: 60 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"lint": "next lint"
},
"dependencies": {
"axios": "^1.6.0",
"next": "^14.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"axios": "^1.6.0"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@playwright/test": "^1.57.0",
"eslint": "^8.54.0",
"eslint-config-next": "14.0.0"
}
Expand Down
14 changes: 14 additions & 0 deletions frontend/tests/home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { test, expect } = require('@playwright/test');

test('homepage loads', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page).toHaveTitle(/DevOps Assignment/);
});

test('backend message is visible', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(
page.locator('text=Backend Message')
).toBeVisible();
});