Compare commits
43 Commits
ae96b79fb2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b98642cd4 | |||
| 49f9a383db | |||
| 8429b666e1 | |||
| d072e18124 | |||
| c356fca133 | |||
| 0205a5f90b | |||
| 50d41b7da5 | |||
| 811885a258 | |||
| 2ff402a68c | |||
| 02d671d1f0 | |||
| 986ed7f72d | |||
| 7b541269a1 | |||
| cb404c8faa | |||
| 612b204c9a | |||
| 9f58cec1e4 | |||
| a286600240 | |||
| 669c3ce985 | |||
| a12faab953 | |||
| 9fc2316459 | |||
| 0c5eaa19cd | |||
| ea335c96d0 | |||
| 09af728f80 | |||
| a8699e2eb4 | |||
| e6921d00f5 | |||
| 35522c3f8d | |||
| 1f2e223b42 | |||
| c473ffbd16 | |||
| 340d3ed95c | |||
| 717b059670 | |||
| 428b11e37a | |||
| 95dd832303 | |||
| deeada2479 | |||
| 78da8a061f | |||
| 44926969ce | |||
| b3a9f19501 | |||
| a7940b2044 | |||
| fcd328ca2b | |||
| c442b16a45 | |||
| af30ff772b | |||
| 134b3d7538 | |||
| 7b85004b70 | |||
| 5a2ca2c037 | |||
| 913e7f531a |
@@ -1,20 +1,96 @@
|
|||||||
name: Build and Deploy Demo App
|
# .gitea/workflows/cicd.yaml
|
||||||
|
name: Build and Deploy Demo App (Artifacts, GHES/Gitea-safe)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ main ]
|
||||||
- main
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
# ---------- TEST ----------
|
||||||
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
|
||||||
|
- name: Install deps
|
||||||
|
run: pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Run tests (SQLite fallback)
|
||||||
|
env:
|
||||||
|
DB_USER: "" # force SQLite fallback in app.py
|
||||||
|
DB_PASS: ""
|
||||||
|
DB_NAME: ""
|
||||||
|
run: pytest
|
||||||
|
|
||||||
|
# ---------- BUILD ----------
|
||||||
|
build:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
run: docker build -t demo-app:latest .
|
run: docker build -t demo-app:latest .
|
||||||
|
|
||||||
- name: Save Docker image to tar
|
- name: Save Docker image to tar
|
||||||
run: docker save demo-app:latest > demo-app.tar
|
run: docker save demo-app:latest > demo-app.tar
|
||||||
|
|
||||||
|
# IMPORTANT: use v3 on Gitea/GHES
|
||||||
|
- name: Upload image artifact
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: demo-image
|
||||||
|
path: demo-app.tar
|
||||||
|
if-no-files-found: error
|
||||||
|
# retention-days: 7 # optional; depends on your Gitea settings
|
||||||
|
|
||||||
|
# ---------- SCAN ----------
|
||||||
|
scan:
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# IMPORTANT: use v3 on Gitea/GHES
|
||||||
|
- name: Download image artifact
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: demo-image
|
||||||
|
path: . # place demo-app.tar in the workspace root
|
||||||
|
|
||||||
|
- name: Load Docker image from artifact
|
||||||
|
run: docker load -i demo-app.tar
|
||||||
|
|
||||||
|
- name: Scan image with Trivy
|
||||||
|
run: |
|
||||||
|
docker run --rm \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
aquasec/trivy:latest \
|
||||||
|
image --exit-code 1 --severity CRITICAL,HIGH --no-progress demo-app:latest
|
||||||
|
|
||||||
|
# ---------- DEPLOY ----------
|
||||||
|
deploy:
|
||||||
|
needs: [build, scan]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# IMPORTANT: use v3 on Gitea/GHES
|
||||||
|
- name: Download image artifact
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: demo-image
|
||||||
|
path: .
|
||||||
|
|
||||||
- name: Set up SSH
|
- name: Set up SSH
|
||||||
run: |
|
run: |
|
||||||
apt update && apt install -y openssh-client
|
apt update && apt install -y openssh-client
|
||||||
@@ -24,41 +100,42 @@ jobs:
|
|||||||
eval "$(ssh-agent -s)"
|
eval "$(ssh-agent -s)"
|
||||||
ssh-add ~/.ssh/id_ed25519
|
ssh-add ~/.ssh/id_ed25519
|
||||||
ssh-keyscan -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
|
ssh-keyscan -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
|
||||||
- name: Copy files to server via SCP
|
|
||||||
|
- name: Copy files to server
|
||||||
run: |
|
run: |
|
||||||
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} demo-app.tar ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}demo-app.tar
|
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} \
|
||||||
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} docker-compose.yml ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}docker-compose.yml
|
demo-app.tar \
|
||||||
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} -r nginx_user_conf.d ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}nginx_user_conf.d
|
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:"${{ secrets.DEPLOY_PATH }}/demo-app.tar"
|
||||||
- name: Deploy on server via SSH
|
|
||||||
|
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} \
|
||||||
|
docker-compose.yml \
|
||||||
|
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:"${{ secrets.DEPLOY_PATH }}/docker-compose.yml"
|
||||||
|
|
||||||
|
scp -o StrictHostKeyChecking=no -P ${{ secrets.SERVER_PORT }} -r \
|
||||||
|
nginx_user_conf.d \
|
||||||
|
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:"${{ secrets.DEPLOY_PATH }}/nginx_user_conf.d"
|
||||||
|
|
||||||
|
- name: Deploy on server
|
||||||
run: |
|
run: |
|
||||||
ssh -o StrictHostKeyChecking=no -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << EOF
|
ssh -o StrictHostKeyChecking=no -p ${{ secrets.SERVER_PORT }} \
|
||||||
cd ${{ secrets.DEPLOY_PATH }}
|
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
|
||||||
|
set -e
|
||||||
|
cd "${{ secrets.DEPLOY_PATH }}"
|
||||||
|
|
||||||
# Check and install Docker if not present (Ubuntu/Debian assumed)
|
# Write DB secrets for compose
|
||||||
if ! command -v docker &> /dev/null; then
|
echo "DB_USER=${{ secrets.DB_USER }}" > .env
|
||||||
sudo apt update -y
|
echo "DB_PASS=${{ secrets.DB_PASS }}" >> .env
|
||||||
sudo apt install -y ca-certificates curl
|
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
|
||||||
sudo install -m 0755 -d /etc/apt/keyrings
|
|
||||||
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
|
|
||||||
sudo chmod a+r /etc/apt/keyrings/docker.asc
|
|
||||||
echo "deb [arch=\$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \$(. /etc/os-release && echo "\$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
||||||
sudo apt update -y
|
|
||||||
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
||||||
sudo systemctl start docker
|
|
||||||
sudo systemctl enable docker
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check and install Docker Compose if not present
|
# Load image and restart stack
|
||||||
if ! command -v docker-compose &> /dev/null; then
|
|
||||||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-\$(uname -s)-\$(uname -m)" -o /usr/local/bin/docker-compose
|
|
||||||
sudo chmod +x /usr/local/bin/docker-compose
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Load image and deploy with Compose
|
|
||||||
docker load -i demo-app.tar
|
docker load -i demo-app.tar
|
||||||
docker-compose down || true # Graceful stop
|
if [ ! -f docker-compose.yml ]; then
|
||||||
docker-compose up -d
|
echo "ERROR: docker-compose.yml not found in $(pwd)" >&2
|
||||||
|
ls -la
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker compose -f docker-compose.yml down
|
||||||
|
docker compose -f docker-compose.yml --env-file .env up -d --remove-orphans
|
||||||
|
|
||||||
# Cleanup
|
rm -f demo-app.tar
|
||||||
rm demo-app.tar
|
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
20
Dockerfile
20
Dockerfile
@@ -1,9 +1,21 @@
|
|||||||
FROM python:3.12-slim
|
# Build stage
|
||||||
|
FROM python:3.12-slim AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY app.py .
|
|
||||||
|
# Runtime stage
|
||||||
|
FROM python:3.12-slim
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
||||||
|
# NEW: Copy binaries like gunicorn
|
||||||
|
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||||
|
COPY app.py models.py .
|
||||||
COPY templates ./templates
|
COPY templates ./templates
|
||||||
|
# NEW: Install wget for healthcheck (run as root, before switching user)
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/*
|
||||||
|
RUN useradd -m appuser
|
||||||
|
USER appuser
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
CMD ["python", "app.py"]
|
HEALTHCHECK --interval=30s --timeout=3s CMD wget --no-verbose --tries=1 --spider http://localhost:5000/ || exit 1
|
||||||
|
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
# devops
|
# tags: DevOps CI/CD Pipeline Gitea Docker
|
||||||
|
|
||||||
DevOps PPC
|
DevOps CI/CD Pipeline Demo Application
|
||||||
|
|
||||||
|
Prod project implementation
|
||||||
|
|||||||
34
app.py
34
app.py
@@ -1,12 +1,38 @@
|
|||||||
|
import os
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
from flask_bootstrap import Bootstrap5 # Updated import for Bootstrap 5 support
|
from flask_bootstrap import Bootstrap5
|
||||||
|
from models import db, Feature
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Database config
|
||||||
|
db_user = os.getenv('DB_USER')
|
||||||
|
db_pass = os.getenv('DB_PASS')
|
||||||
|
db_name = os.getenv('DB_NAME')
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = (
|
||||||
|
f'postgresql://{db_user}:{db_pass}@db:5432/{db_name}'
|
||||||
|
if db_user else 'sqlite:///:memory:'
|
||||||
|
)
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
bootstrap = Bootstrap5(app)
|
bootstrap = Bootstrap5(app)
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
# ────────────────────────────────
|
||||||
|
# THIS IS THE MISSING PART:
|
||||||
|
# Create tables + seed data ONCE at startup
|
||||||
|
# ────────────────────────────────
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all() # ← Creates the "feature" table if missing
|
||||||
|
Feature.seed_db() # ← Now works without error
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
features = Feature.query.all()
|
||||||
|
return render_template('index.html', features=features)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app.run(host='0.0.0.0', port=5000)
|
# Optional: nice health endpoint that doesn't touch DB
|
||||||
|
@app.route('/health')
|
||||||
|
def health():
|
||||||
|
return "OK", 200
|
||||||
|
|||||||
@@ -1,8 +1,36 @@
|
|||||||
services:
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
container_name: demo-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${DB_USER}
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASS}
|
||||||
|
POSTGRES_DB: ${DB_NAME}
|
||||||
|
volumes:
|
||||||
|
- db-data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
app:
|
app:
|
||||||
image: demo-app:latest
|
image: demo-app:latest
|
||||||
container_name: demo-app
|
container_name: demo-app
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
- DB_USER=${DB_USER}
|
||||||
|
- DB_PASS=${DB_PASS}
|
||||||
|
- DB_NAME=${DB_NAME}
|
||||||
|
depends_on:
|
||||||
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "http://localhost:5000"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: jonasal/nginx-certbot:latest
|
image: jonasal/nginx-certbot:latest
|
||||||
@@ -12,13 +40,26 @@ services:
|
|||||||
- 8008:80
|
- 8008:80
|
||||||
- 4433:443
|
- 4433:443
|
||||||
environment:
|
environment:
|
||||||
- CERTBOT_EMAIL=your@email.com
|
- CERTBOT_EMAIL=the.dark.mist23@gmail.com
|
||||||
- ENVSUBST_TEMPLATE_SUFFIX=.tmpl # Enables template processing if needed
|
- ENVSUBST_TEMPLATE_SUFFIX=.tmpl
|
||||||
|
- CERTBOT_DISABLED=true
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx_user_conf.d:/etc/nginx/user_conf.d:ro
|
- ./nginx_user_conf.d:/etc/nginx/conf.d/
|
||||||
- letsencrypt:/etc/letsencrypt
|
- letsencrypt:/etc/letsencrypt
|
||||||
|
- /home/devroot/demo/certs/fullchain.pem:/etc/nginx/ssl/origin_cert.pem:ro
|
||||||
|
- /home/devroot/demo/certs/prvkey.pem:/etc/nginx/ssl/origin_key.key:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
- app
|
app:
|
||||||
|
condition: service_healthy
|
||||||
|
logging:
|
||||||
|
driver: json-file
|
||||||
|
options:
|
||||||
|
max-size: 10m
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
letsencrypt:
|
letsencrypt:
|
||||||
|
db-data:
|
||||||
|
|||||||
31
models.py
Normal file
31
models.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
|
||||||
|
class Feature(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
title = db.Column(db.String(100), nullable=False)
|
||||||
|
description = db.Column(db.String(200), nullable=False)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def seed_db():
|
||||||
|
# Seed only if empty
|
||||||
|
if Feature.query.count() == 0:
|
||||||
|
features = [
|
||||||
|
Feature(
|
||||||
|
title="Responsive Design",
|
||||||
|
description="Adapts seamlessly to mobile, tablet, and desktop devices.",
|
||||||
|
),
|
||||||
|
Feature(
|
||||||
|
title="Modern UI",
|
||||||
|
description="Uses Bootstrap 5 for clean, professional styling.",
|
||||||
|
),
|
||||||
|
Feature(
|
||||||
|
title="Easy Deployment",
|
||||||
|
description="Containerized with Docker for quick setup on any server.",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
db.session.bulk_save_objects(features)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
@@ -1,9 +1,21 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
|
server_name demo.networkwizard.xyz;
|
||||||
|
location / {
|
||||||
|
return 301 https://$host:4433$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
listen 443 ssl;
|
listen 443 ssl;
|
||||||
server_name demo.networkwizard.xyz;
|
server_name demo.networkwizard.xyz;
|
||||||
|
ssl_certificate /etc/nginx/ssl/origin_cert.pem;
|
||||||
# SSL config handled by the container image
|
ssl_certificate_key /etc/nginx/ssl/origin_key.key;
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
client_max_body_size 2g; # allow big artifacts
|
||||||
|
proxy_read_timeout 600s;
|
||||||
|
proxy_send_timeout 600s;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://app:5000;
|
proxy_pass http://app:5000;
|
||||||
@@ -13,5 +25,8 @@ server {
|
|||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redirect HTTP to HTTPS (handled automatically by the image after certs are obtained)
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
flask==3.0.3
|
flask==3.0.3
|
||||||
bootstrap-flask==2.5.0
|
bootstrap-flask==2.5.0
|
||||||
|
gunicorn==22.0.0
|
||||||
|
flask-sqlalchemy==3.1.1
|
||||||
|
psycopg2-binary==2.9.9 # Postgres driver
|
||||||
|
pytest==8.3.3 # For tests
|
||||||
|
|||||||
@@ -1,89 +1,72 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<!-- Required meta tags -->
|
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
<title>Professional Demo Site</title>
|
<title>Professional Demo Site</title>
|
||||||
|
|
||||||
<!-- Bootstrap CSS -->
|
|
||||||
{{ bootstrap.load_css() }}
|
{{ bootstrap.load_css() }}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body { padding-top: 60px; } /* Space for fixed navbar */
|
body { padding-top: 60px; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="/">Demo Pro Site</a>
|
<a class="navbar-brand" href="/">DevOps Course Demo Website V2</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
||||||
|
data-bs-target="#navbarNav" aria-controls="navbarNav"
|
||||||
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav ms-auto">
|
<ul class="navbar-nav ms-auto">
|
||||||
<li class="nav-item">
|
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||||
<a class="nav-link" href="/">Home</a>
|
<li class="nav-item"><a class="nav-link" href="#features">Features</a></li>
|
||||||
</li>
|
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#features">Features</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#about">About</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<!-- Hero Section -->
|
|
||||||
<div class="bg-primary text-white py-5 mt-4 rounded text-center">
|
<div class="bg-primary text-white py-5 mt-4 rounded text-center">
|
||||||
<h1 class="display-4">Welcome to the Professional Demo Site</h1>
|
<h1 class="display-4">Professional Demo Site V1</h1>
|
||||||
<p class="lead">This is a realistic, Bootstrap-powered Flask application for demonstration purposes. It features responsive design and modern UI elements.</p>
|
<p class="lead">
|
||||||
|
This is a realistic, Bootstrap-powered Flask application with DB integration for demonstration.
|
||||||
|
</p>
|
||||||
<a class="btn btn-light btn-lg" href="#features" role="button">Learn More</a>
|
<a class="btn btn-light btn-lg" href="#features" role="button">Learn More</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Features Section -->
|
|
||||||
<section id="features" class="py-5">
|
<section id="features" class="py-5">
|
||||||
<h2 class="text-center mb-4">Key Features</h2>
|
<h2 class="text-center mb-4">Key Features (from DB)</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
|
{% for feature in features %}
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">Responsive Design</h5>
|
<h5 class="card-title">{{ feature.title }}</h5>
|
||||||
<p class="card-text">Adapts seamlessly to mobile, tablet, and desktop devices.</p>
|
<p class="card-text">{{ feature.description }}</p>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">Modern UI</h5>
|
|
||||||
<p class="card-text">Uses Bootstrap 5 for clean, professional styling.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">Easy Deployment</h5>
|
|
||||||
<p class="card-text">Containerized with Docker for quick setup on any server.</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- About Section -->
|
|
||||||
<section id="about" class="py-5 bg-light">
|
<section id="about" class="py-5 bg-light">
|
||||||
<h2 class="text-center mb-4">About This Demo</h2>
|
<h2 class="text-center mb-4">About This Demo</h2>
|
||||||
<p class="text-center">This site serves as a starting point for building more complex web applications. Extend it with databases, APIs, or user authentication as needed.</p>
|
<p class="text-center">
|
||||||
|
Now with PostgreSQL for data persistence. Extend with more models and queries.
|
||||||
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bootstrap JS -->
|
|
||||||
{{ bootstrap.load_js() }}
|
{{ bootstrap.load_js() }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
40
test_app.py
Normal file
40
test_app.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
# Ensure tests always use the in-memory SQLite DB, even if CI sets DB_* secrets
|
||||||
|
for var in ("DB_USER", "DB_PASS", "DB_NAME"):
|
||||||
|
os.environ.pop(var, None)
|
||||||
|
|
||||||
|
from app import app
|
||||||
|
from models import db, Feature
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
app.config["TESTING"] = True
|
||||||
|
# app was already initialised with SQLite because DB_USER is now unset
|
||||||
|
|
||||||
|
# Fresh DB per test
|
||||||
|
with app.app_context():
|
||||||
|
db.drop_all()
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
with app.test_client() as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
|
# Clean up after test
|
||||||
|
with app.app_context():
|
||||||
|
db.drop_all()
|
||||||
|
|
||||||
|
|
||||||
|
def test_index(client):
|
||||||
|
response = client.get("/")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert b"Professional Demo Site" in response.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_seed_db(client):
|
||||||
|
with app.app_context():
|
||||||
|
Feature.seed_db()
|
||||||
|
assert Feature.query.count() == 3
|
||||||
|
|
||||||
Reference in New Issue
Block a user