Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 build

- name: Run tests
run: docker compose 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 }}
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ 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
# RUN chown -R appuser:appgroup /app

# Switch to non-root user
USER appuser
# # Switch to non-root user
# USER appuser

# Define a health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
Expand Down
10 changes: 5 additions & 5 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 @@ -14,8 +12,8 @@ services:
- MONGODB_URI=mongodb://mongodb:27017/apostrophe
- SESSION_SECRET=change_this_to_a_secure_secret
volumes:
- ./website:/app
- /app/node_modules
- ./website/coverage:/app/coverage
command: ["npm", "start"]
depends_on:
- mongodb
restart: unless-stopped
Expand All @@ -25,6 +23,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 +76,4 @@ services:

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

sonar.javascript.lcov.reportPaths=lcov.info
sonar.coverage.exclusions=

sonar.exclusions=
Loading
Loading