Skip to content

Commit e8c718a

Browse files
committed
push
0 parents  commit e8c718a

83 files changed

Lines changed: 10516 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.development

Whitespace-only changes.

.github/workflows/build-push.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags:
7+
- 'v*'
8+
workflow_dispatch:
9+
10+
env:
11+
AWS_REGION: us-east-1
12+
ECR_REPOSITORY_BACKEND: codeguard-backend
13+
ECR_REPOSITORY_FRONTEND: codeguard-frontend
14+
15+
jobs:
16+
build-push:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Configure AWS credentials
24+
uses: aws-actions/configure-aws-credentials@v4
25+
with:
26+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
aws-region: ${{ env.AWS_REGION }}
29+
30+
- name: Login to Amazon ECR
31+
id: login-ecr
32+
uses: aws-actions/amazon-ecr-login@v2
33+
34+
- name: Build and push backend image
35+
env:
36+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
37+
IMAGE_TAG: ${{ github.sha }}
38+
run: |
39+
docker build -f docker/backend.Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:$IMAGE_TAG .
40+
docker build -f docker/backend.Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:latest .
41+
docker push $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:$IMAGE_TAG
42+
docker push $ECR_REGISTRY/$ECR_REPOSITORY_BACKEND:latest
43+
44+
- name: Set up Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: '20'
48+
49+
- name: Build and push frontend image
50+
env:
51+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
52+
IMAGE_TAG: ${{ github.sha }}
53+
run: |
54+
docker build -f docker/frontend.Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:$IMAGE_TAG .
55+
docker build -f docker/frontend.Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:latest .
56+
docker push $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:$IMAGE_TAG
57+
docker push $ECR_REGISTRY/$ECR_REPOSITORY_FRONTEND:latest
58+

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy to AWS
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
env:
9+
AWS_REGION: us-east-1
10+
TF_VERSION: 1.5.0
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Configure AWS credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25+
aws-region: ${{ env.AWS_REGION }}
26+
27+
- name: Setup Terraform
28+
uses: hashicorp/setup-terraform@v3
29+
with:
30+
terraform_version: ${{ env.TF_VERSION }}
31+
32+
- name: Terraform Init
33+
working-directory: ./infra
34+
run: terraform init
35+
36+
- name: Terraform Plan
37+
working-directory: ./infra
38+
run: terraform plan -out=tfplan
39+
40+
- name: Terraform Apply
41+
working-directory: ./infra
42+
run: terraform apply -auto-approve tfplan
43+

.github/workflows/scan-pr.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Scan PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
scan:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.11'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
27+
- name: Run CodeGuard scan
28+
env:
29+
SECRET_KEY: ${{ secrets.SECRET_KEY }}
30+
QDRANT_HOST: localhost
31+
QDRANT_PORT: 6333
32+
run: |
33+
python -m app.cli scan . --format json --output pr-scan-results.json
34+
35+
- name: Comment PR with results
36+
uses: actions/github-script@v7
37+
with:
38+
github-token: ${{ secrets.GITHUB_TOKEN }}
39+
script: |
40+
const fs = require('fs');
41+
const results = JSON.parse(fs.readFileSync('pr-scan-results.json', 'utf8'));
42+
43+
const critical = results.summary.by_severity.critical || 0;
44+
const high = results.summary.by_severity.high || 0;
45+
const medium = results.summary.by_severity.medium || 0;
46+
47+
let comment = `## 🔍 CodeGuard AI Scan Results\n\n`;
48+
comment += `**Total Issues:** ${results.total_issues}\n`;
49+
comment += `- 🔴 Critical: ${critical}\n`;
50+
comment += `- 🟠 High: ${high}\n`;
51+
comment += `- 🟡 Medium: ${medium}\n\n`;
52+
53+
if (critical > 0 || high > 0) {
54+
comment += `⚠️ **Action Required:** Critical or high severity issues found.\n\n`;
55+
}
56+
57+
comment += `\n<details>\n<summary>View all issues</summary>\n\n`;
58+
59+
results.issues.slice(0, 10).forEach(issue => {
60+
comment += `### ${issue.title}\n`;
61+
comment += `**Severity:** ${issue.severity}\n`;
62+
comment += `**Location:** ${issue.location.file_path}:${issue.location.start_line}\n`;
63+
comment += `\n`;
64+
});
65+
66+
comment += `</details>`;
67+
68+
github.rest.issues.createComment({
69+
issue_number: context.issue.number,
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
body: comment
73+
});
74+

.github/workflows/test.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:15
16+
env:
17+
POSTGRES_USER: codeguard
18+
POSTGRES_PASSWORD: codeguard
19+
POSTGRES_DB: codeguard
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
- 5432:5432
27+
28+
qdrant:
29+
image: qdrant/qdrant:latest
30+
ports:
31+
- 6333:6333
32+
- 6334:6334
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Set up Python
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: '3.11'
41+
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install -r requirements.txt
46+
pip install pytest pytest-asyncio pytest-cov pytest-mock
47+
48+
- name: Lint with ruff
49+
run: |
50+
pip install ruff
51+
ruff check app/
52+
53+
- name: Type check with mypy
54+
run: |
55+
pip install mypy
56+
mypy app/ --ignore-missing-imports || true
57+
58+
- name: Security check with bandit
59+
run: |
60+
pip install bandit
61+
bandit -r app/ -f json -o bandit-report.json || true
62+
63+
- name: Run tests
64+
env:
65+
DATABASE_URL: postgresql://codeguard:codeguard@localhost:5432/codeguard
66+
QDRANT_HOST: localhost
67+
QDRANT_PORT: 6333
68+
SECRET_KEY: test-secret-key-change-in-production
69+
run: |
70+
pytest tests/ --cov=app --cov-report=xml --cov-report=term
71+
72+
- name: Upload coverage
73+
uses: codecov/codecov-action@v3
74+
with:
75+
file: ./coverage.xml
76+
flags: unittests
77+
name: codecov-umbrella
78+

.gitignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
MANIFEST
23+
24+
# Virtual Environment
25+
venv/
26+
env/
27+
ENV/
28+
.venv
29+
30+
# IDEs
31+
.vscode/
32+
.idea/
33+
*.swp
34+
*.swo
35+
*~
36+
.DS_Store
37+
38+
# Testing
39+
.pytest_cache/
40+
.coverage
41+
htmlcov/
42+
.tox/
43+
.hypothesis/
44+
45+
# Environment
46+
.env
47+
.env.local
48+
.env.*.local
49+
50+
# Logs
51+
*.log
52+
logs/
53+
54+
# Database
55+
*.db
56+
*.sqlite
57+
*.sqlite3
58+
59+
# Docker
60+
.dockerignore
61+
62+
# Terraform
63+
.terraform/
64+
*.tfstate
65+
*.tfstate.*
66+
.terraform.lock.hcl
67+
terraform.tfvars
68+
69+
# AWS
70+
.aws/
71+
72+
# Reports
73+
reports/
74+
*.html
75+
*.pdf
76+
*.sarif
77+
78+
# Temporary
79+
tmp/
80+
temp/
81+
*.tmp
82+
83+
# Node
84+
node_modules/
85+
npm-debug.log*
86+
yarn-debug.log*
87+
yarn-error.log*
88+
.pnpm-debug.log*
89+
90+
# Frontend build
91+
frontend/dist/
92+
frontend/build/
93+
94+
# Qdrant
95+
qdrant_data/
96+
qdrant_storage/
97+
98+
# Cloned repos
99+
repos/
100+
cloned_repos/
101+
102+
# Secrets
103+
secrets/
104+
*.pem
105+
*.key
106+
*.crt
107+
108+
context.md
109+

0 commit comments

Comments
 (0)