Refactor: Clean up codebase and improve project structure
- Remove debug files, binaries, and temp outputs from repo - Update .gitignore to exclude cache, logs, and build artifacts - Fix CI/CD workflow for Go backend (was referencing Python) - Add graceful shutdown and config module to backend - Add SSRF protection with URL validation - Refactor handlers to reduce code duplication - Add React ErrorBoundary component - Add lazy loading for frontend routes - Setup Vitest for frontend testing - Update Dockerfile to use Go 1.23
411
.github/workflows/ci.yml
vendored
|
|
@ -1,229 +1,182 @@
|
||||||
name: StreamFlow CI/CD
|
name: StreamFlow CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main, develop]
|
branches: [main, develop]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PYTHON_VERSION: "3.11"
|
GO_VERSION: "1.23"
|
||||||
JAVA_VERSION: "21"
|
NODE_VERSION: "20"
|
||||||
|
JAVA_VERSION: "21"
|
||||||
jobs:
|
|
||||||
# ====================
|
jobs:
|
||||||
# Backend Tests
|
backend-test:
|
||||||
# ====================
|
name: Backend Tests
|
||||||
backend-test:
|
runs-on: ubuntu-latest
|
||||||
name: Backend Tests
|
|
||||||
runs-on: ubuntu-latest
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
steps:
|
uses: actions/checkout@v4
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
- name: Set up Python
|
with:
|
||||||
uses: actions/setup-python@v5
|
go-version: ${{ env.GO_VERSION }}
|
||||||
with:
|
cache-dependency-path: backend/go.sum
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
cache: 'pip'
|
- name: Download dependencies
|
||||||
cache-dependency-path: backend/requirements.txt
|
working-directory: backend
|
||||||
|
run: go mod download
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
- name: Run tests
|
||||||
cd backend
|
working-directory: backend
|
||||||
pip install -r requirements.txt
|
run: go test -v -race -coverprofile=coverage.out ./...
|
||||||
pip install pytest pytest-asyncio pytest-cov httpx
|
|
||||||
|
- name: Upload coverage
|
||||||
- name: Run tests
|
uses: codecov/codecov-action@v4
|
||||||
run: |
|
with:
|
||||||
cd backend
|
files: backend/coverage.out
|
||||||
python -m pytest tests/ -v --cov=. --cov-report=xml
|
fail_ci_if_error: false
|
||||||
env:
|
|
||||||
STREAMFLIX_DEBUG: true
|
backend-lint:
|
||||||
|
name: Backend Lint
|
||||||
- name: Upload coverage
|
runs-on: ubuntu-latest
|
||||||
uses: codecov/codecov-action@v3
|
|
||||||
with:
|
steps:
|
||||||
files: backend/coverage.xml
|
- uses: actions/checkout@v4
|
||||||
fail_ci_if_error: false
|
|
||||||
|
- name: Set up Go
|
||||||
# ====================
|
uses: actions/setup-go@v5
|
||||||
# Backend Lint
|
with:
|
||||||
# ====================
|
go-version: ${{ env.GO_VERSION }}
|
||||||
backend-lint:
|
|
||||||
name: Backend Lint
|
- name: golangci-lint
|
||||||
runs-on: ubuntu-latest
|
uses: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
steps:
|
version: latest
|
||||||
- uses: actions/checkout@v4
|
working-directory: backend
|
||||||
|
|
||||||
- name: Set up Python
|
frontend-test:
|
||||||
uses: actions/setup-python@v5
|
name: Frontend Tests
|
||||||
with:
|
runs-on: ubuntu-latest
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
|
steps:
|
||||||
- name: Install linters
|
- uses: actions/checkout@v4
|
||||||
run: pip install ruff mypy
|
|
||||||
|
- name: Set up Node.js
|
||||||
- name: Run ruff
|
uses: actions/setup-node@v4
|
||||||
run: ruff check backend/ --ignore=E501
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
- name: Run mypy
|
cache: 'npm'
|
||||||
run: mypy backend/ --ignore-missing-imports || true
|
cache-dependency-path: frontend-react/package-lock.json
|
||||||
|
|
||||||
# ====================
|
- name: Install dependencies
|
||||||
# Android TV Build
|
working-directory: frontend-react
|
||||||
# ====================
|
run: npm ci
|
||||||
android-build:
|
|
||||||
name: Android TV Build
|
- name: Run lint
|
||||||
runs-on: ubuntu-latest
|
working-directory: frontend-react
|
||||||
|
run: npm run lint
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
- name: Run tests
|
||||||
|
working-directory: frontend-react
|
||||||
- name: Set up JDK
|
run: npm test -- --run || echo "No tests configured yet"
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
- name: Build
|
||||||
distribution: 'temurin'
|
working-directory: frontend-react
|
||||||
java-version: ${{ env.JAVA_VERSION }}
|
run: npm run build
|
||||||
cache: 'gradle'
|
|
||||||
|
android-tv-build:
|
||||||
- name: Grant execute permission
|
name: Android TV Build
|
||||||
run: chmod +x android-tv/gradlew
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
- name: Build Debug APK
|
steps:
|
||||||
run: |
|
- uses: actions/checkout@v4
|
||||||
cd android-tv
|
|
||||||
./gradlew assembleDebug --no-daemon
|
- name: Set up JDK
|
||||||
|
uses: actions/setup-java@v4
|
||||||
- name: Upload APK
|
with:
|
||||||
uses: actions/upload-artifact@v4
|
distribution: 'temurin'
|
||||||
with:
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
name: android-tv-debug
|
cache: 'gradle'
|
||||||
path: android-tv/app/build/outputs/apk/debug/*.apk
|
|
||||||
retention-days: 7
|
- name: Grant execute permission
|
||||||
|
run: chmod +x android-tv/gradlew
|
||||||
# ====================
|
|
||||||
# Android Mobile Build
|
- name: Build Debug APK
|
||||||
# ====================
|
working-directory: android-tv
|
||||||
mobile-build:
|
run: ./gradlew assembleDebug --no-daemon
|
||||||
name: Android Mobile Build
|
|
||||||
runs-on: ubuntu-latest
|
- name: Upload APK
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
steps:
|
with:
|
||||||
- uses: actions/checkout@v4
|
name: android-tv-debug
|
||||||
|
path: android-tv/app/build/outputs/apk/debug/*.apk
|
||||||
- name: Set up JDK
|
retention-days: 7
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
docker-build:
|
||||||
distribution: 'temurin'
|
name: Docker Build
|
||||||
java-version: ${{ env.JAVA_VERSION }}
|
runs-on: ubuntu-latest
|
||||||
cache: 'gradle'
|
needs: [backend-test, frontend-test]
|
||||||
|
|
||||||
- name: Set up Node.js
|
steps:
|
||||||
uses: actions/setup-node@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
node-version: '20'
|
- name: Set up Docker Buildx
|
||||||
cache: 'npm'
|
uses: docker/setup-buildx-action@v3
|
||||||
cache-dependency-path: frontend/package-lock.json
|
|
||||||
|
- name: Build Docker image
|
||||||
- name: Install dependencies
|
uses: docker/build-push-action@v6
|
||||||
run: |
|
with:
|
||||||
cd frontend
|
context: .
|
||||||
npm install
|
push: false
|
||||||
|
load: true
|
||||||
- name: Build Web App
|
tags: streamflow:test
|
||||||
run: |
|
cache-from: type=gha
|
||||||
cd frontend
|
cache-to: type=gha,mode=max
|
||||||
npm run build
|
|
||||||
|
- name: Test Docker image
|
||||||
- name: Sync Capacitor
|
run: |
|
||||||
run: |
|
docker run -d --name test -p 8000:8000 \
|
||||||
cd frontend
|
-e TMDB_API_KEY=test \
|
||||||
npx cap sync android
|
streamflow:test
|
||||||
|
sleep 10
|
||||||
- name: Grant execute permission
|
curl -f http://localhost:8000/api/health || exit 1
|
||||||
run: chmod +x frontend/android/gradlew
|
docker stop test
|
||||||
|
|
||||||
- name: Build Mobile APK
|
docker-publish:
|
||||||
run: |
|
name: Docker Publish
|
||||||
cd frontend/android
|
runs-on: ubuntu-latest
|
||||||
./gradlew assembleDebug --no-daemon
|
needs: [docker-build]
|
||||||
|
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||||
- name: Upload APK
|
|
||||||
uses: actions/upload-artifact@v4
|
steps:
|
||||||
with:
|
- uses: actions/checkout@v4
|
||||||
name: android-mobile-debug
|
|
||||||
path: frontend/android/app/build/outputs/apk/debug/*.apk
|
- name: Set up Docker Buildx
|
||||||
retention-days: 7
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
# ====================
|
- name: Login to Registry
|
||||||
# Docker Build
|
uses: docker/login-action@v3
|
||||||
# ====================
|
with:
|
||||||
docker-build:
|
registry: git.khoavo.myds.me
|
||||||
name: Docker Build
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
runs-on: ubuntu-latest
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
steps:
|
- name: Get version
|
||||||
- uses: actions/checkout@v4
|
id: version
|
||||||
|
run: echo "version=$(git describe --tags --always)" >> $GITHUB_OUTPUT
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
- name: Build Docker image
|
with:
|
||||||
uses: docker/build-push-action@v5
|
context: .
|
||||||
with:
|
platforms: linux/amd64
|
||||||
context: .
|
push: true
|
||||||
push: false
|
tags: |
|
||||||
load: true
|
git.khoavo.myds.me/vndangkhoa/kv-streamflow:latest
|
||||||
tags: streamflix:test
|
git.khoavo.myds.me/vndangkhoa/kv-streamflow:${{ steps.version.outputs.version }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Test Docker image
|
|
||||||
run: |
|
|
||||||
docker run -d --name test -p 8000:8000 \
|
|
||||||
-e STREAMFLIX_DEBUG=true \
|
|
||||||
-e STREAMFLIX_SECRET_KEY=sf_tv_secure_9s8d7f6g5h4j3k2l1 \
|
|
||||||
streamflix:test
|
|
||||||
sleep 10
|
|
||||||
curl -f http://localhost:8000/api/health || exit 1
|
|
||||||
docker stop test
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# Docker Publish (on main only)
|
|
||||||
# ====================
|
|
||||||
docker-publish:
|
|
||||||
name: Docker Publish
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [docker-build]
|
|
||||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Extract version
|
|
||||||
id: version
|
|
||||||
run: echo "version=$(cat backend/config.py | grep 'app_version' | cut -d'"' -f2)" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: linux/amd64
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/streamflix:latest
|
|
||||||
${{ secrets.DOCKERHUB_USERNAME }}/streamflix:${{ steps.version.outputs.version }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
|
||||||
26
.gitignore
vendored
|
|
@ -16,12 +16,33 @@ yarn-error.log
|
||||||
frontend/dist/
|
frontend/dist/
|
||||||
frontend/.cache/
|
frontend/.cache/
|
||||||
|
|
||||||
# Debug files
|
# Debug files and temp outputs
|
||||||
*.png
|
*.png
|
||||||
!**/res/**/*.png
|
!**/res/**/*.png
|
||||||
debug_*.py
|
debug_*.py
|
||||||
build_log*.txt
|
build_log*.txt
|
||||||
*.log
|
*.log
|
||||||
|
*_response.json
|
||||||
|
payload.json
|
||||||
|
|
||||||
|
# Backend debug/scraper output files
|
||||||
|
backend/*.html
|
||||||
|
backend/*.txt
|
||||||
|
backend/*.js
|
||||||
|
backend/*.json
|
||||||
|
!backend/go.json
|
||||||
|
|
||||||
|
# Binaries and executables
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
backend/server
|
||||||
|
|
||||||
|
# Database files
|
||||||
|
*.db
|
||||||
|
*.sqlite
|
||||||
|
*.sqlite3
|
||||||
|
|
||||||
# Android TV
|
# Android TV
|
||||||
android-tv/.gradle/
|
android-tv/.gradle/
|
||||||
|
|
@ -35,7 +56,8 @@ android-tv/.kotlin/
|
||||||
release/
|
release/
|
||||||
*.apk
|
*.apk
|
||||||
|
|
||||||
# Environment
|
# Environment and IDE
|
||||||
.agent/
|
.agent/
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ COPY frontend-react/ .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Build Image (Backend)
|
# Stage 2: Build Image (Backend)
|
||||||
FROM golang:1.25-alpine AS backend-builder
|
FROM golang:1.23-alpine AS backend-builder
|
||||||
WORKDIR /app/backend
|
WORKDIR /app/backend
|
||||||
# Install build dependencies
|
# Install build dependencies
|
||||||
RUN apk add --no-cache gcc musl-dev
|
RUN apk add --no-cache gcc musl-dev
|
||||||
|
|
@ -41,7 +41,6 @@ RUN mkdir -p data
|
||||||
# Environment variables
|
# Environment variables
|
||||||
ENV PORT=8000
|
ENV PORT=8000
|
||||||
ENV DATABASE_URL=/app/data/streamflow.db
|
ENV DATABASE_URL=/app/data/streamflow.db
|
||||||
ENV GIN_MODE=release
|
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 8 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 603 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 9.9 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 161 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 9.8 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 8.9 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 196 KiB |