diff --git a/.env b/.env old mode 100644 new mode 100755 index 73ce2f40..cbe6c293 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ -CLOUDINARY_CLOUD_NAME= -CLOUDINARY_KEY= -CLOUDINARY_SECRET= -MAPBOX_TOKEN= -DB_URL=" " +CLOUDINARY_CLOUD_NAME=dmwaef1yg +CLOUDINARY_KEY=174288424886845 +CLOUDINARY_SECRET=IRnxIvuIwVWAnS3daNUFVRT8N7c +MAPBOX_TOKEN=sk.eyJ1IjoicmFuaml0cjAwMSIsImEiOiJjbHg0aXRlcncxM2xkMmtzNDkwcm8zbWZpIn0._-Z0itv0q7xhScy6BsZKzg +DB_URL="mongodb+srv://rrvox001:EvEJrmvliVZmMfkC@ranjit.yeaglht.mongodb.net/?retryWrites=true&w=majority&appName=ranjit" SECRET=devopsshack diff --git a/Dockerfile b/Dockerfile index 6a594cc3..9fb3661b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,23 @@ -# Use Node 18 as parent image -FROM node:18 +# Use an official Node.js runtime as the base image +FROM node:14 -# Change the working directory on the Docker image to /app -WORKDIR /app +# Set the working directory in the container +WORKDIR /usr/src/app -# Copy package.json and package-lock.json to the /app directory -COPY package.json package-lock.json ./ +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ -# Install dependencies -RUN npm install +# Install project dependencies +RUN npm install --quiet -# Copy the rest of project files into this image +# Upgrade multer to the specified version +RUN npm install multer@1.4.4-lts.1 --quiet + +# Copy the rest of the application code COPY . . -# Expose application port +# Expose the port the app runs on EXPOSE 3000 -# Start the application -CMD npm start +# Start the Node.js application +CMD ["node", "app.js"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..9b7c21dc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,77 @@ +pipeline { + agent any + + tools { + nodejs 'node21' + } + + environment { + SCANNER_HOME = tool 'sonar-scanner' + } + + stages { + stage('Git Checkout') { + steps { + git branch: 'main', url: 'https://github.com/ranjitrupnawar/3-Tier-Full-Stack.git' + } + } + + stage('Install dependency package') { + steps { + sh 'npm install' + } + } + + stage('Trivy FS Scan') { + steps { + sh 'trivy fs --format table -o fs-report.html .' + } + } + + stage('SonarQube Analysis') { + steps { + withCredentials([string(credentialsId: 'sonar-token', variable: 'SONAR_TOKEN')]) { + sh "$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectKey=campground -Dsonar.projectName=campground -Dsonar.login=$SONAR_TOKEN" + } + } + } + + stage('Docker build and tag') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker build -t ranjitrupnawar/camp:latest ." + } + } + } + } + + stage('Trivy Image scan') { + steps { + sh 'trivy image --format table -o image-report.html ranjitrupnawar/camp:latest' + } + } + + stage('Docker push') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker push ranjitrupnawar/camp:latest" + } + } + } + } + + stage('Docker deployment') { + steps { + script { + withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') { + sh "docker run -d -p 3000:3000 ranjitrupnawar/camp:latest" + } + } + } + } + } + + +} diff --git a/Manifests/dss.yml b/Manifests/dss.yml index 966aeca4..54376f35 100644 --- a/Manifests/dss.yml +++ b/Manifests/dss.yml @@ -5,11 +5,11 @@ metadata: name: yelp-camp-secrets type: Opaque data: - CLOUDINARY_CLOUD_NAME: ZGlpMnJvenRw - CLOUDINARY_KEY: NzU3NjQzMjU3ODkxMzY0 - CLOUDINARY_SECRET: SHpBeTdPU3VCZjJhSUFSUm5Fd0tIcEVtc01N + CLOUDINARY_CLOUD_NAME: ZG13YWVmMXlnCg== + CLOUDINARY_KEY: MTc0Mjg4NDI0ODg2ODQ1Cg== + CLOUDINARY_SECRET: SVJueEl2dUl3VldBblMzZGFOVUZWUlQ4TjdjCg== MAPBOX_TOKEN: cGsuZXlKMUlqb2lZV1JwYW1GcGMzZGhiQ0lzSW1FaU9pSmpiSFl3TnpKemVHNHhaRzR5TW1wd1ltWm1OSFZ3YlhObUluMC5SVlFZc3UwUnZKZ0NGNTRrMjJkWDBB - DB_URL: bW9uZ29kYitzcnY6Ly9qYWlzd2FsYWRpMjQ2OnNjN1ZHU3lkN2RRQ2NMeTFAY2x1c3RlcjAuaXE2bXV0aC5tb25nb2RiLm5ldC8/cmV0cnlXcml0ZXM9dHJ1ZSZ3PW1ham9yaXR5JmFwcE5hbWU9Q2x1c3RlcjA= + DB_URL: bW9uZ29kYitzcnY6Ly9ycnZveDAwMTpFdkVKcm12bGlWWm1NZmtDQHJhbmppdC55ZWFnbGh0Lm1vbmdvZGIubmV0Lz9yZXRyeVdyaXRlcz10cnVlJnc9bWFqb3JpdHkmYXBwTmFtZT1yYW5qaXQK SECRET: ZGV2b3Bzc2hhY2s= --- @@ -29,7 +29,7 @@ spec: spec: containers: - name: yelp-camp-container - image: adijaiswal/campa:latest + image: ranjitrupnawar/camp:latest ports: - containerPort: 3000 env: