Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fa329d6
fb CI/CD fix
Njeriiii Jan 25, 2025
f7117ba
remove some files from repo
Njeriiii Jan 25, 2025
18078e4
workflow directory structure fix
Njeriiii Jan 25, 2025
9f35fef
CI/CD fix
Njeriiii Jan 25, 2025
bffa279
CI/CD fix
Njeriiii Jan 25, 2025
1827be9
CI/CD fix
Njeriiii Jan 25, 2025
8d68d23
CI/CD fix
Njeriiii Jan 25, 2025
5ec87d5
CI/CD fix
Njeriiii Jan 25, 2025
8890b89
CI/CD fix
Njeriiii Jan 25, 2025
79e2351
sync main to deployment action
Njeriiii Jan 25, 2025
68bbab0
cloudrun CI/CD
Njeriiii Jan 25, 2025
3df2309
add 'run workflow' button
Njeriiii Jan 25, 2025
a0a9e9d
CI/CD fix
Njeriiii Jan 25, 2025
0c06d0d
CI/CD fix
Njeriiii Jan 25, 2025
f55b983
CI/CD fix
Njeriiii Jan 25, 2025
df98ba9
cloudsql actions
Njeriiii Jan 25, 2025
c8b0384
CI/CD fix
Njeriiii Jan 25, 2025
7e2ffbc
CI/CD fix
Njeriiii Jan 25, 2025
8e5c64e
CI/CD fix
Njeriiii Jan 25, 2025
56c8604
CI/CD fix
Njeriiii Jan 25, 2025
5d5025a
CI/CD fix
Njeriiii Jan 25, 2025
dd8ebc2
CI/CD fix
Njeriiii Jan 25, 2025
a666df3
CI/CD fix
Njeriiii Jan 25, 2025
7ff1e29
CI/CD fix
Njeriiii Jan 25, 2025
37526de
CI/CD fix
Njeriiii Jan 25, 2025
4ccb5e8
CI/CD fix
Njeriiii Jan 26, 2025
fdcaff6
CI/CD fix
Njeriiii Jan 26, 2025
5d53b05
CI/CD fix
Njeriiii Jan 27, 2025
b06dcf9
CI/CD fix
Njeriiii Jan 27, 2025
6134e6e
CI/CD fix
Njeriiii Jan 27, 2025
ab7305c
CI/CD fix
Njeriiii Jan 27, 2025
1a11edd
CI/CD fix
Njeriiii Jan 27, 2025
a7634d6
CI/CD fix
Njeriiii Jan 27, 2025
7ba675c
CI/CD fix
Njeriiii Jan 27, 2025
dadaa90
CI/CD fix
Njeriiii Jan 27, 2025
283c561
migrations config
Njeriiii Jan 27, 2025
1ef3284
minor bug fixes
Njeriiii Jan 31, 2025
aef7ce3
modify to deploy from main
Njeriiii Jan 31, 2025
6154506
small bug fix
Njeriiii Jan 31, 2025
22e7636
directory fix
Njeriiii Jan 31, 2025
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
64 changes: 64 additions & 0 deletions .github/workflows/cloudrun-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Deploy to Cloud Run

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'Backend/**'
- '.github/workflows/cloudrun-deploy.yml'

jobs:
deploy:
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.11'

# Add explicit pip install step
- name: Install pip dependencies
working-directory: Backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt

- id: auth
name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
token_format: 'access_token'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
project_id: gohub-92b6b

- name: Build and Push Container
env:
REGION: us-west1
PROJECT_ID: gohub-92b6b
run: |
# Configure docker to use gcloud credentials
gcloud auth configure-docker us-west1-docker.pkg.dev

# Build the container
docker build -t us-west1-docker.pkg.dev/$PROJECT_ID/cloud-run-source-deploy/ngo-connect-backend:${{ github.sha }} ./Backend

# Push to Artifact Registry
docker push us-west1-docker.pkg.dev/$PROJECT_ID/cloud-run-source-deploy/ngo-connect-backend:${{ github.sha }}

# Deploy to Cloud Run
gcloud run deploy ngo-connect-backend \
--image us-west1-docker.pkg.dev/$PROJECT_ID/cloud-run-source-deploy/ngo-connect-backend:${{ github.sha }} \
--region $REGION \
--platform managed \
--allow-unauthenticated \
--set-env-vars "DATABASE_URL=${{ secrets.DATABASE_URL }},FLASK_APP=${{ secrets.FLASK_APP }},JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}"
148 changes: 148 additions & 0 deletions .github/workflows/cloudsql-migrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Database Migrations

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'Backend/migrations/**'
- 'Backend/app/models.py' # Path to match actual models location
- 'Backend/app/models/**' # Watch for any future model files in a models directory
- 'Backend/manage_db.py'

- '.github/workflows/cloudsql-migrate.yml'

jobs:
migrate:
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.11'
cache: 'pip'
cache-dependency-path: 'Backend/requirements.dev.txt'

- name: Setup GCP Credentials
run: |
echo '${{ secrets.GCP_SA_KEY }}' > gcp-credentials.json
chmod 600 gcp-credentials.json

- name: Install and start Cloud SQL Proxy v2
run: |
# Download and setup Cloud SQL Proxy
curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.8.1/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy

## Start proxy with structured logging
./cloud-sql-proxy \
--credentials-file=gcp-credentials.json \
--address 0.0.0.0 \
--port 5432 \
--structured-logs \
gohub-92b6b:us-west1:ngo-connect-db > proxy.log 2>&1 &

# Wait for proxy to start and verify
sleep 10
if ! netstat -tlpn | grep :5432 > /dev/null; then
echo "Error: Cloud SQL Proxy failed to start"
cat proxy.log
exit 1
fi
echo "Cloud SQL Proxy started successfully"

- name: Install dependencies
working-directory: Backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt

- name: Create required directories
working-directory: Backend
run: |
mkdir -p migrations/versions
mkdir -p uploads

- name: Setup environment variables
working-directory: Backend
run: |
# Create .env file with all required variables
cat << EOF > .env
FLASK_APP=app:create_app()
FLASK_ENV=production
K_SERVICE=cloud-run
USE_CLOUD_SQL_PROXY=true
DATABASE_URL=postgresql://postgres:${{ secrets.DB_PASSWORD }}@127.0.0.1:5432/ngo_connect
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
GOOGLE_APPLICATION_CREDENTIALS=${{ github.workspace }}/gcp-credentials.json
GOOGLE_CLOUD_PROJECT=gohub-92b6b
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
UPLOAD_FOLDER=${{ github.workspace }}/Backend/uploads
EOF

# Export for immediate use
export $(cat .env | xargs)
export PYTHONPATH="${PWD}:${PYTHONPATH}"

- name: Verify database connection
working-directory: Backend
run: |
python << EOF
import psycopg2
import sys
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()

try:
logger.info("Testing database connection...")
conn = psycopg2.connect(
dbname='ngo_connect',
user='postgres',
password='${{ secrets.DB_PASSWORD }}',
host='127.0.0.1',
port='5432'
)
with conn.cursor() as cur:
cur.execute('SELECT version();')
version = cur.fetchone()
logger.info(f"Connected to PostgreSQL: {version[0]}")
conn.close()
except Exception as e:
logger.error(f"Database connection failed: {e}")
sys.exit(1)
EOF

- name: Run Database Migrations
working-directory: Backend
run: |
echo "Current directory: $(pwd)"
echo "Starting migrations..."
python manage_db.py

- name: Store migration logs
if: always()
uses: actions/upload-artifact@v4
with:
name: migration-logs
path: |
Backend/migration.log
proxy.log
retention-days: 7

- name: Stop Cloud SQL Proxy
if: always()
run: |
pkill cloud-sql-proxy || true

- name: Cleanup
if: always()
run: |
rm -f gcp-credentials.json
rm -f Backend/.env
50 changes: 50 additions & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on merge
on:
push:
branches:
- main

jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Debug step to verify paths
- name: Debug Paths
run: |
echo "Current directory: $(pwd)"
echo "Contents of Frontend directory:"
ls -la Frontend

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'Frontend/package-lock.json'

# Install dependencies and build
- name: Install and Build
working-directory: Frontend
run: |
echo "Installing dependencies..."
npm ci
echo "Building project..."
npm run build
env:
CI: false
REACT_APP_BASE_API_URL: ${{ secrets.REACT_APP_BASE_API_URL }}

# Deploy to production
- name: Deploy to Firebase
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_GOHUB_92B6B }}
channelId: live
projectId: gohub-92b6b
entryPoint: './Frontend'
48 changes: 48 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
on:
pull_request:
branches:
- main
defaults:
run:
working-directory: Frontend

permissions:
checks: write
contents: read
pull-requests: write
jobs:
build_and_preview:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'Frontend/package-lock.json'

# Install dependencies
- name: Install dependencies
run: npm ci

# Build with environment variables
- name: Build
run: npm run build
env:
CI: false # Prevents treating warnings as errors
REACT_APP_BASE_API_URL: ${{ secrets.REACT_APP_BASE_API_URL }}

# Deploy preview
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_GOHUB_92B6B }}
projectId: gohub-92b6b
entryPoint: 'Frontend'
1 change: 1 addition & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __pycache__/

# ignore .env
.env
.env.cloud
```

# Ignore IDE-specific files
Expand Down
5 changes: 5 additions & 0 deletions Backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ python verify_db.py
# Local migration with model changes
```
cd Backend

Ensure DATABASE_URL points to SQLite
```bash
export $(cat .env | xargs) # Contains DATABASE_URL=sqlite:///db.sqlite
```
python manage_db.py

# Commit the migration files
Expand Down
8 changes: 8 additions & 0 deletions Backend/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flask_jwt_extended import JWTManager
from datetime import timedelta
import os
import importlib
from google.oauth2 import service_account

from app.config import AppConfig
Expand Down Expand Up @@ -41,6 +42,13 @@ def create_app(config_class=AppConfig):
"supports_credentials": True # Add this line
}})

# Load config from environment variable or default to AppConfig
config_class = os.getenv('CONFIG_CLASS', 'app.config.AppConfig')
if isinstance(config_class, str):
module_name, class_name = config_class.rsplit('.', 1)
module = importlib.import_module(module_name)
config_class = getattr(module, class_name)

app.config.from_object(config_class)

Session(app)
Expand Down
Loading