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

Devops #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 17 additions & 4 deletions deploy-sandbox.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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