Skip to content
Merged
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Node.js dependencies
node_modules
coverage
npm-debug.log
yarn-debug.log
yarn-error.log
Expand Down
51 changes: 50 additions & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,53 @@ jobs:
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: docker-scan-results.sarif
category: docker-scout
category: docker-scout

unit-tests:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create coverage directory
run: mkdir -p website/coverage

- name: Build app image
run: docker compose -f docker-compose.yml -f docker-compose.override.yml build

- name: Run tests
run: docker compose -f docker-compose.yml -f docker-compose.override.yml run --rm apostrophe npm run test -- --coverage

- name: Save coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: website/coverage/lcov.info

sonarqube:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
needs: unit-tests
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report

- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@v5.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@v1.1.0
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ RUN apk add --no-cache wget=1.25.0-r0
RUN addgroup -S appgroup && adduser -S appuser -G appgroup

# Copy package files for efficient caching
COPY website/package.json website/package-lock.json* ./
COPY website/ ./

# Install dependencies with specific flags for production
RUN npm ci && \
# Clean npm cache to reduce image size
npm cache clean --force

# Copy the rest of the application
COPY website/ ./


# Set proper ownership
RUN chown -R appuser:appgroup /app
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This repository contains a complete Docker Compose setup for Apostrophe CMS with all required services.

## Status
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=speedandfunction_website&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=speedandfunction_website)

[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=speedandfunction_website&metric=bugs)](https://sonarcloud.io/summary/new_code?id=speedandfunction_website)

[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=speedandfunction_website&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=speedandfunction_website)

[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=speedandfunction_website&metric=coverage)](https://sonarcloud.io/summary/new_code?id=speedandfunction_website)

[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=speedandfunction_website&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=speedandfunction_website)

## Services

- **Apostrophe CMS**: The main web application
Expand Down
1 change: 1 addition & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
apostrophe:
# In development mode, use nodemon instead of normal start
command: npm run dev
user: root
environment:
- NODE_ENV=development
- REDIS_URI=redis://redis:6379
Expand Down
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
# Apostrophe CMS web application
apostrophe:
Expand All @@ -13,9 +11,8 @@ services:
- NODE_ENV=development
- MONGODB_URI=mongodb://mongodb:27017/apostrophe
- SESSION_SECRET=change_this_to_a_secure_secret
volumes:
- ./website:/app
- /app/node_modules

command: ["npm", "start"]
depends_on:
- mongodb
restart: unless-stopped
Expand All @@ -25,6 +22,8 @@ services:
timeout: 5s
retries: 3
start_period: 15s
# Command to run tests: docker compose run --rm apostrophe npm run test
# Command to run tests with coverage: docker compose run --rm apostrophe npm run test -- --coverage

# MongoDB database
mongodb:
Expand Down Expand Up @@ -76,4 +75,4 @@ services:

volumes:
mongodb_data:
redis_data:
redis_data:
20 changes: 20 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sonar.organization=speedandfunction
sonar.projectKey=speedandfunction_website
sonar.sources=website

sonar.javascript.lcov.reportPaths=lcov.info
sonar.coverage.exclusions=\
website/node_modules/**,\
website/coverage/**,\
website/data/**,\
website/public/**,\
website/modules/**,\
website/babel.config.js,\
website/jest.config.js,\
website/package.json,\
website/package-lock.json,\
website/**/*.test.js

sonar.exclusions=\
website/node_modules/**,\
website/coverage/**
12 changes: 12 additions & 0 deletions website/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
20 changes: 20 additions & 0 deletions website/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
testEnvironment: 'node',
collectCoverageFrom: [
'**/*.{ts,tsx,js,jsx}',
'!**/node_modules/**',
'!**/coverage/**',
'!**/babel.config.js',
'!**/jest.config.js',
'!**/public/**',
'!**/data/**'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov'],
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
verbose: true,
transform: {
'^.+\\.(js|jsx)$': 'babel-jest'
},
moduleFileExtensions: ['js', 'jsx', 'json', 'node']
};
3 changes: 3 additions & 0 deletions website/libs/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const stub = () => {
return 'stub';
};
10 changes: 10 additions & 0 deletions website/libs/stub.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Stub test file
*/
import { stub } from './stub';

describe('Stub Test Suite', () => {
test('should pass', () => {
expect(stub()).toBe('stub');
});
});
Loading