diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4aec375 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Use a slim Node.js base image for building +FROM node:18-slim AS builder + +# Set working directory +WORKDIR /app + +# Copy package.json and other package management files +COPY package*.json ./ + +# Install dependencies (use RUN for development, COPY for production) +RUN npm install # For development builds + +# Optional: Copy your application code in a separate stage +FROM node:18-slim + +# Set working directory +WORKDIR /app + +# Copy your application code +COPY . . + +# Expose the port your application uses (replace 8080 with your actual port) +EXPOSE 3000 + +# Start the application (replace "start.js" with your entry point) +CMD [ "npm", "start" ] # Or "node start.js" + diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..0831e71 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,5 @@ +services: + redis: + image: 'dpka531/deepika:latest' + ports: + - '4000:4000' diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..4b335e6 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,71 @@ +pipeline { + agent any + + tools{ + nodejs 'node18' + } + + environment { + SCANNER_HOME=tool 'sonarqube' + } + + stages { + stage('clean workspace'){ + steps{ + cleanWs() + } + } + + stage('Checkout') { + steps { + // Check out the code from Git repository + git credentialsId: 'github', url: 'https://github.com/deepikapwr/node-express-server-rest-api.git' + } + } + + + stage("Sonarqube Analysis "){ + steps{ + withSonarQubeEnv('sonarqube') { + sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=job \ + -Dsonar.projectKey=job ''' + } + } + } + stage("quality gate"){ + when { expression { params.action == 'create'}} + steps{ + script{ + def credentialsId = 'sonarqube' + qualityGate(credentialsId) + } + } + } + + stage('Install Dependencies') { + steps { + // Build your application artifact + sh 'npm install' + } + } + + stage("Docker Build & Push"){ + steps{ + script{ + withDockerRegistry(credentialsId: 'docker', toolName: 'docker'){ + sh "docker build -t deepika ." + sh "docker tag deepika dpka531/deepika:latest " + sh "docker push dpka531/deepika:latest " + } + } + } + } + + stage('Deploy (Optional)') { + steps { + sh 'docker-compose up -d' + } + } + + } +}