Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
220 changes: 220 additions & 0 deletions .github/workflows/api-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
name: API CI/CD Pipeline

# Trigger: At every push or pull request to dev, dev-api or main branches affecting the api/ directory or this workflow file
on:
push:
branches:
- dev-api
- dev
- main
paths:
- 'api/**'
- '.github/workflows/api-ci.yml'
pull_request:
branches:
- dev-api
- dev
- main
paths:
- 'api/**'
- '.github/workflows/api-ci.yml'

jobs:
# Job 1: Build and Test
test:
name: Build & Test
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]

steps:
# Step 1: Checkout Repository
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Setup Node.js
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: api/package-lock.json

# Step 3: Create .env file from secrets
- name: Create .env file
working-directory: api
run: |
cat > .env << EOF
# Server Configuration
PORT=3000
NODE_ENV=test

# Database Configuration
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
DB_NAME=${{ secrets.DB_NAME }}
DB_USER=${{ secrets.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DB_SSL=false

# Connection Pool Configuration
DB_POOL_MAX=20
DB_POOL_MIN=2
DB_IDLE_TIMEOUT=30000
DB_CONNECTION_TIMEOUT=10000

# CORS Configuration
CORS_ORIGIN=*

# API Configuration
API_TITLE=STAC Atlas
API_DESCRIPTION=A centralized platform for managing, indexing, and providing STAC Collection metadata
API_VERSION=1.0.0
EOF

# Step 4: Install dependencies
- name: Install dependencies
run: |
cd api
npm ci

# Step 5: Linting (ESLint)
- name: Run ESLint
run: |
cd api
npm run lint --if-present
continue-on-error: true

# Step 6: Run tests
- name: Run tests
run: |
cd api
# Run Jest in-band (single process) with a higher default test timeout
npm test -- --runInBand --testTimeout=30000

# Step 7: Generate coverage report
- name: Generate coverage report
run: |
cd api
npm test -- --runInBand --testTimeout=30000 --coverage --coverageReporters=text --coverageReporters=lcov
continue-on-error: true

# Step 8: Upload coverage as artifact
- name: Upload coverage reports
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report
path: api/coverage/
retention-days: 30

# Step 9: Upload test results as artifact
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: api/test-results/
retention-days: 30

# Job 2: Validate build
build:
name: Validate Build
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
cache-dependency-path: api/package-lock.json

- name: Create .env file
working-directory: api
run: |
cat > .env << EOF
# Server Configuration
PORT=3000
NODE_ENV=test

# Database Configuration
DB_HOST=${{ secrets.DB_HOST }}
DB_PORT=${{ secrets.DB_PORT }}
DB_NAME=${{ secrets.DB_NAME }}
DB_USER=${{ secrets.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DB_SSL=false

# Connection Pool Configuration
DB_POOL_MAX=20
DB_POOL_MIN=2
DB_IDLE_TIMEOUT=30000
DB_CONNECTION_TIMEOUT=10000

# CORS Configuration
CORS_ORIGIN=*

# API Configuration
API_TITLE=STAC Atlas
API_DESCRIPTION=A centralized platform for managing, indexing, and providing STAC Collection metadata
API_VERSION=1.0.0
EOF

- name: Install dependencies
run: |
cd api
npm ci

- name: Validate application starts
run: |
cd api
timeout 10s npm start || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi
continue-on-error: false

# Job 3: Security Audit
security:
name: Security Audit
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
cache-dependency-path: api/package-lock.json

- name: Run npm audit
run: |
cd api
npm audit --audit-level=moderate
continue-on-error: true

# Job 4: Status-Check for Branch Protection
ci-success:
name: CI Success
runs-on: ubuntu-latest
needs: [test, build]
if: always()

steps:
- name: Check all jobs succeeded
run: |
if [ "${{ needs.test.result }}" != "success" ] || [ "${{ needs.build.result }}" != "success" ]; then
echo "CI Pipeline failed!"
echo "Test status: ${{ needs.test.result }}"
echo "Build status: ${{ needs.build.result }}"
exit 1
else
echo "All CI checks passed successfully!"
fi
31 changes: 31 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Server Configuration
PORT=3000
NODE_ENV=development


# Database Configuration (Debian Server)
# Option 1: Use DATABASE_URL (PostgreSQL connection string)
# add DB_USER and DB_PASSWORD values
DATABASE_URL= postgresql://[**DB_USER**]:[**DB_PASSWORD**]@atlas.stacindex.org:5432/stac_db

# Option 2: Use individual variables (currently active)
DB_HOST=atlas.stacindex.org
DB_PORT=5433 # 5432 for production
DB_NAME=stac_db
DB_USER=
DB_PASSWORD=
DB_SSL=false

# Connection Pool Configuration
DB_POOL_MAX=20
DB_POOL_MIN=2
DB_IDLE_TIMEOUT=30000
DB_CONNECTION_TIMEOUT=10000

# CORS Configuration
CORS_ORIGIN=*

# API Configuration
API_TITLE=STAC Atlas
API_DESCRIPTION=A centralized platform for managing, indexing, and providing STAC Collection metadata
API_VERSION=1.0.0
18 changes: 18 additions & 0 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
env: {
node: true,
es2022: true,
jest: true
},
extends: ['eslint:recommended'],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module'
},
rules: {
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'no-console': ['warn', { allow: ['warn', 'error'] }],
'prefer-const': 'warn',
'no-var': 'error'
}
};
61 changes: 61 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
8 changes: 8 additions & 0 deletions api/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 100,
"arrowParens": "avoid"
}
Loading
Loading