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

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]

jobs:
security:
runs-on: ubuntu-latest
name: Security Audit
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run security audit
run: npm audit --audit-level high

- name: Check for secrets in code
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: main
head: HEAD

lint:
runs-on: ubuntu-latest
name: Code Quality
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Lint code
run: |
# Check for console.log statements
! grep -r "console\.log" --include="*.js" . || (echo "Found console.log statements" && exit 1)

# Check for TODO/FIXME comments
grep -r "TODO\|FIXME" --include="*.js" . || true

- name: Check file structure
run: |
# Ensure no sensitive files are committed
if [ -f "config/config.json" ]; then
echo "❌ config.json should not be in version control"
exit 1
fi

if find . -name "*.backup" -o -name "config.backup*" | grep -q .; then
echo "❌ Backup files found in repository"
exit 1
fi

test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 18, 20]
name: Test (Node ${{ matrix.node-version }})
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Create test config
run: |
mkdir -p config
echo '{"test": true}' > config/config.json

- name: Run tests
run: |
# Placeholder for actual tests
node -e "console.log('βœ… Basic syntax check passed')"

- name: Validate package.json
run: npm ls

docker-build:
runs-on: ubuntu-latest
name: Docker Build Test
needs: [security, lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build Docker image
run: |
docker build -t anchorr:test .

- name: Test Docker image
run: |
# Test that the image can start (will fail without config but that's expected)
timeout 10s docker run anchorr:test || [ $? -eq 124 ]
66 changes: 66 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Deploy to Development

on:
push:
branches: [dev]
workflow_dispatch:

jobs:
deploy-dev:
runs-on: ubuntu-latest
environment: development
name: Deploy to Dev Environment
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build application
run: |
echo "Building for development..."
# Add any build steps here

- name: Log in to Docker Hub
if: github.ref == 'refs/heads/dev'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image (dev)
if: github.ref == 'refs/heads/dev'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/anchorr:dev
${{ secrets.DOCKERHUB_USERNAME }}/anchorr:dev-${{ github.sha }}
labels: |
org.opencontainers.image.title=Anchorr
org.opencontainers.image.description=Development build
org.opencontainers.image.version=dev-${{ github.sha }}
org.opencontainers.image.revision=${{ github.sha }}

- name: Deploy to development server
if: github.ref == 'refs/heads/dev'
run: |
echo "πŸš€ Deploying to development environment"
echo "Image: ${{ secrets.DOCKERHUB_USERNAME }}/anchorr:dev-${{ github.sha }}"
# Add deployment commands here
# Example: kubectl set image deployment/anchorr-dev anchorr=${{ secrets.DOCKERHUB_USERNAME }}/anchorr:dev-${{ github.sha }}

- name: Post deployment checks
if: github.ref == 'refs/heads/dev'
run: |
echo "βœ… Development deployment completed"
echo "Environment: Development"
echo "Commit: ${{ github.sha }}"
50 changes: 47 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
name: Docker Publish
name: Deploy to Production

on:
push:
branches: ["main"]
branches: [main]
release:
types: [published]
workflow_dispatch:

jobs:
docker:
# Run tests before deployment
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run security audit
run: npm audit --audit-level high

- name: Build test
run: |
docker build -t anchorr:test .

deploy-production:
runs-on: ubuntu-latest
needs: test
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -24,6 +50,12 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/anchorr
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v5
Expand All @@ -32,3 +64,15 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Deploy to production
run: |
echo "πŸš€ Deploying to production environment"
echo "Image tags: ${{ steps.meta.outputs.tags }}"
# Add production deployment commands here

- name: Post deployment verification
run: |
echo "βœ… Production deployment completed"
echo "Version: ${{ steps.meta.outputs.version }}"
echo "Tags: ${{ steps.meta.outputs.tags }}"
116 changes: 116 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Security Scan

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
schedule:
# Run weekly security scans
- cron: '0 2 * * 1'

jobs:
secrets-scan:
runs-on: ubuntu-latest
name: Scan for Secrets
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run Trufflehog
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified

dependency-scan:
runs-on: ubuntu-latest
name: Dependency Security Scan
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install dependencies
run: npm ci

- name: Run npm audit
run: |
npm audit --audit-level high --production

- name: Run Snyk security test
uses: snyk/actions/node@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

config-security:
runs-on: ubuntu-latest
name: Configuration Security
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check for sensitive files
run: |
echo "πŸ” Checking for sensitive configuration files..."

# Check for config files that shouldn't be committed
if [ -f "config/config.json" ]; then
echo "❌ config/config.json found in repository!"
echo "This file contains sensitive data and should be in .gitignore"
exit 1
fi

# Check for backup files
if find . -name "*.backup" -o -name "config.backup*" -o -name "*.bak" | grep -q .; then
echo "❌ Backup files found in repository:"
find . -name "*.backup" -o -name "config.backup*" -o -name "*.bak"
exit 1
fi

# Check for common sensitive patterns
if grep -r "password.*=" --include="*.js" --include="*.json" . | grep -v node_modules; then
echo "❌ Potential hardcoded passwords found"
exit 1
fi

if grep -r "token.*=" --include="*.js" --include="*.json" . | grep -v node_modules; then
echo "⚠️ Potential hardcoded tokens found - please verify these are not sensitive"
fi

if grep -r "api_key.*=" --include="*.js" --include="*.json" . | grep -v node_modules; then
echo "⚠️ Potential hardcoded API keys found - please verify these are not sensitive"
fi

echo "βœ… Configuration security check completed"

- name: Validate .gitignore coverage
run: |
echo "πŸ” Validating .gitignore patterns..."

# Required patterns for this project
required_patterns=(
"config/config.json"
"config/*.backup"
"config/backup/"
".env"
"*.log"
"logs/"
)

for pattern in "${required_patterns[@]}"; do
if ! grep -q "^${pattern}" .gitignore; then
echo "⚠️ Missing .gitignore pattern: $pattern"
fi
done

echo "βœ… .gitignore validation completed"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Environment variables
.env
config.json
config/config.json
config/*.backup
config/backup/

# Logs
logs/
Expand Down
Loading
Loading