Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Via docker #465

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pipeline {
agent any
environment {
SONAR_HOME = tool name: 'SonarQube', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
}
stages {
stage("Clone Code from GitHub") {
steps {
git url: 'https://github.com/574n13y/wanderlust.git', branch: 'via-docker'
}
}
stage("SonarQube Quality Analysis") {
steps {
withSonarQubeEnv('SonarQube') {
sh "${SONAR_HOME}/bin/sonar-scanner -Dsonar.projectName=wanderlust -Dsonar.projectKey=wanderlust"
}
}
}
stage("OWASP Dependency Check") {
steps {
dependencyCheck additionalArguments: '--scan ./', odcInstallation: 'OWASP Dependency Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage("Sonar Quality Gate Scan") {
steps {
timeout(time: 2, unit: 'MINUTES') {
waitForQualityGate abortPipeline: false
}
}
}
stage("Trivy File System Scan") {
steps {
sh 'trivy fs --format table -o trivy-fs-report.html .'
}
}
stage("Deploy using Docker Compose") {
steps {
sh 'docker-compose up -d'
}
}
}
}
42 changes: 42 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Stage 1: Build the application
FROM node:21 AS backend-builder

# Setup the working directory
WORKDIR /app

# Copy package.json and package-lock.json separately for better caching
COPY package*.json ./

# Install dependencies
RUN npm ci --no-optional

# Copy the rest of the source code to the container
COPY . .

# Run tests (if applicable)
RUN npm run test

# Stage 2: Create a slim production image
FROM node:21-slim

# Set the working directory in the container
WORKDIR /app

# Copy only the necessary files from the build stage
COPY --from=backend-builder /app .

# Ensure production environment variables are set correctly
COPY .env.docker .env

# Install production dependencies only
RUN npm ci --only=production

# Expose the application port
EXPOSE 5080

# Run the application as a non-root user for security
RUN useradd --no-log-init --user-group --create-home --shell /bin/bash appuser
USER appuser

# Start the application
CMD ["npm", "start"]
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3.8"

services:
mongodb:
container_name: mongo
image: mongo:latest
volumes:
- data:/data/db
ports:
- "27017:27017"

backend:
container_name: backend
build: ./backend
env_file:
- ./backend/.env.docker
ports:
- "5080:5080"
depends_on:
- mongodb
- redis

frontend:
container_name: frontend
build: ./frontend
env_file:
- ./frontend/.env.docker
ports:
- "5173:5173"

redis:
container_name: redis
restart: unless-stopped
image: redis:7.0.5-alpine
expose:
- "6379"
depends_on:
- mongodb

volumes:
data:
38 changes: 38 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# ------------------- Stage 1: Build Stage ------------------------------
# Use the official Node.js 21 image as the base for building
FROM node:21 AS frontend-builder

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json (if available) separately to leverage Docker cache
COPY package*.json ./

# Increase memory limit for Node.js during dependency installation
RUN node --max-old-space-size=4096 /usr/local/bin/npm install

# Copy the rest of the application files
COPY . .

# Run the build process (uncomment if applicable, e.g., using a build tool like Vite)
# RUN npm run build

# ------------------- Stage 2: Final Stage ------------------------------
# Use a slim version of Node.js 21 for the final image to reduce size
FROM node:21-slim

# Set the working directory to /app
WORKDIR /app

# Copy built assets and necessary files from the build stage
COPY --from=frontend-builder /app .

# Copy environment variables for the Docker environment
COPY .env.docker .env.local

# Expose the port for the Node.js application
EXPOSE 5173

# Define the default command to run the application in development mode
CMD ["npm", "run", "dev", "--", "--host"]
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"dependencies": {
"concurrently": "^8.2.2",
"js-cookie": "^3.0.5"
},
"scripts": {
"start-frontend": "cd frontend && npm run dev",
"start-backend": "cd backend && npm start",
"start": "concurrently -n \"FRONTEND,BACKEND\" -c \"bgBlue,bgYellow\" -p \"[{name}]\" \"npm run start-frontend\" \"npm run start-backend\"",
"install-frontend": "cd frontend && npm i",
"install-backend": "cd backend && npm i",
"installer": "npm i && npm run install-backend && npm run install-frontend",
"prepare": "husky install && chmod ug+x .husky/*"
},
"devDependencies": {
"husky": "^8.0.0"
}
"dependencies": {
"concurrently": "^8.2.2",
"js-cookie": "^3.0.5"
},
"scripts": {
"start-frontend": "cd frontend && npm run dev",
"start-backend": "cd backend && npm start",
"start": "concurrently -n \"FRONTEND,BACKEND\" -c \"bgBlue,bgYellow\" -p \"[{name}]\" \"npm run start-frontend\" \"npm run start-backend\"",
"install-frontend": "cd frontend && npm i",
"install-backend": "cd backend && npm i",
"installer": "npm i && npm run install-backend && npm run install-frontend",
"prepare": "husky install || echo 'Husky skipped'",
"postinstall": "[ -d .husky ] && chmod ug+x .husky/* || echo 'No Husky directory, skipping chmod'"
},
"devDependencies": {
"husky": "^8.0.0"
}
}