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 old mode 100644 new mode 100755 index cee4b4a..a9cb5f3 --- 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