From ffce060c7a5aa2a4d1b2944a1abc24a34572d788 Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Thu, 8 Aug 2024 13:48:37 +0530 Subject: [PATCH 1/2] Updated the Dockerfile and sandbox deployment script --- Dockerfile | 17 ++++++++++++----- deploy-sandbox.sh | 21 +++++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a9842d..8219673 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ FROM node:18.14.0-alpine3.17 +# Create and set the working directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app +# Copy package.json and package-lock.json COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application code COPY . ./ +# List files in the working directory RUN ls -ltrh -RUN npm install -RUN npm i -g pm2 -RUN npm run build - +# Expose the application port EXPOSE 3000 -CMD [ "pm2-runtime", "ecosystem.config.js" ] + +# Command to start the application +CMD ["npm", "start"] diff --git a/deploy-sandbox.sh b/deploy-sandbox.sh index cee4b4a..a9cb5f3 100644 --- a/deploy-sandbox.sh +++ b/deploy-sandbox.sh @@ -1,7 +1,20 @@ #!/bin/bash -cp Dockerfile-sandbox ~/beckn-sandbox/Dockerfile +set -e # Exit immediately if a command exits with a non-zero status + +# Navigate to the sandbox directory cd ~/beckn-sandbox/ -docker build -t sandbox-api . -docker stop sandbox-api && docker rm sandbox-api -docker run --name sandbox-api -it -d --network host sandbox-api:latest + +# Build the Docker image +if docker build -t sandbox-api .; then + # Stop and remove the existing Docker container if it is running + if docker ps | grep -q sandbox-api; then + docker stop sandbox-api && docker rm sandbox-api + fi + + # Run the Docker container if the build succeeds + docker run --name sandbox-api -it -d -p 3000:3000 sandbox-api:latest + echo "Deployment successful: sandbox-api is running on port 3000." +else + echo "Docker build failed. The existing sandbox-api container has not been stopped or removed." +fi From 8c4633c06d35aac7d4ac12aa4af9a0c06645a087 Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Thu, 8 Aug 2024 13:48:54 +0530 Subject: [PATCH 2/2] Updated the Dockerfile and sandbox deployment script --- deploy-sandbox.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 deploy-sandbox.sh diff --git a/deploy-sandbox.sh b/deploy-sandbox.sh old mode 100644 new mode 100755