commit 19ad3e04262c9541510bce0902cc13970167297b Author: Vikas Nale Date: Mon May 19 11:12:24 2025 +0530 Add release scripts to repsitory diff --git a/prod/config.env b/prod/config.env new file mode 100644 index 0000000..b1a1a58 --- /dev/null +++ b/prod/config.env @@ -0,0 +1,9 @@ +# config.env +ENVIRONMENT=production +WEB_BRANCH_NAME=Issue_May_2W +WEB_IMAGE_NAME=marco.web.prod:v1.1 +WEB_CONTAINER_NAME=marco.web.prod +API_BRANCH_NAME=Issues_May_2W +API_IMAGE_NAME=marco.api.prod:v1.1 +API_CONTAINER_NAME=marco.api.prod +API_URL=https://api.marcoaiot.com diff --git a/prod/publish-api.sh b/prod/publish-api.sh new file mode 100644 index 0000000..18317b6 --- /dev/null +++ b/prod/publish-api.sh @@ -0,0 +1,52 @@ +# #!/bin/bash + +# Load config file +source ./config.env + +# Step 1: set branch Name +IMAGE_NAME=$API_IMAGE_NAME +CONTAINER_NAME=$API_CONTAINER_NAME +REPO_DIR="marco.pms.api" + +# Navigate into the project directory + +if [ -d "$REPO_DIR" ]; then + cd "$REPO_DIR" || exit + echo "Changed directory to $REPO_DIR" +else + echo "Folder '$REPO_DIR' does not exist. Exiting..." + exit 1 +fi + + +# Step 2: Build the Docker image +echo "Building the Docker image..." +# docker build -t $IMAGE_NAME -f Marco.Pms.Services/Dockerfile . +echo "?? Building Docker image: $IMAGE_NAME" +if ! docker build -t "$IMAGE_NAME" -f Marco.Pms.Services/Dockerfile .; then + echo "? Docker build failed for image: $IMAGE_NAME" + exit 1 +fi + + + +echo "Image Name:$IMAGE_NAME" +echo "Container Name: $CONTAINER_NAME" + + +# Step 3: Stop and remove any existing container with the same name + +if sudo docker ps -q --filter "name=$CONTAINER_NAME"; then + echo "Stopping and removing existing container..." + sudo docker stop "$CONTAINER_NAME" + sudo docker rm "$CONTAINER_NAME" +fi + + +# Step 5: Run the Docker containerer +echo "Running Docker container..." + +docker run -d --name $CONTAINER_NAME --network mynetwork -p 8085:8080 -p 8086:8081 $IMAGE_NAME + +# Step 6: Final Message +echo "Successfully Running $CONTAINER_NAME" diff --git a/prod/publish-client.sh b/prod/publish-client.sh new file mode 100644 index 0000000..e66e130 --- /dev/null +++ b/prod/publish-client.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Load config file +source ./config.env + + +# Set the name for the Docker image and container +IMAGE_NAME=$WEB_IMAGE_NAME +CONTAINER_NAME=$WEB_CONTAINER_NAME +REPO_DIR="marco.pms.web" +VITE_API_URL=$API_URL + + +# Navigate into the cloned project directory + +if [ -d "$REPO_DIR" ]; then + cd "$REPO_DIR" || exit + echo "------------ Changed directory to $REPO_DIR" +else + echo "------------ Folder '$REPO_DIR' does not exist. Exiting..." + exit 1 +fi + +#cd marco.pms.web || exit + +# Step 2: Install dependencies +echo "------------ Installing dependencies using npm..." +npm install + +# Step 3: Build the Client app +echo "------------ Building the React app..." +npm run build + + +# Step 4: Delete Existing Container +if sudo docker ps -q --filter "name=$CONTAINER_NAME"; then + echo "------------ Stopping existing container..." + sudo docker stop "$CONTAINER_NAME" + sudo docker rm "$CONTAINER_NAME" +else + echo "------------ No existing container found for: $CONTAINER_NAME" +fi + + +# Step 5: Delete Existing Image +# Check if the image exists +if docker images | awk '{print $1}' | grep -q "^$IMAGE_NAME"; then + echo "------------ Deleting existing Docker image: $IMAGE_NAMEE" + docker rmi -f $IMAGE_NAME +else + echo "------------ No existing image found for: $IMAGE_NAME" +fi + + +echo "------------ Image Name:$IMAGE_NAME" +echo "------------ Container Name: $CONTAINER_NAME" +echo "------------ Image Name: $IMAGE_NAME" +echo "------------ VITE_API_URL:$VITE_API_URL" + + +# Step 6: Build New Client Image + +echo "------------ Building Docker image..." +sudo docker build -t "$IMAGE_NAME" . + +# Go to outer directory +cd ../ + +# Step 7: Run the Docker containerer +echo "------------ Running Docker container..." +docker run -d --name "$CONTAINER_NAME" -p 4175:4173 \ + -e VITE_API_URL="$VITE_API_URL" "$IMAGE_NAME" + + +# Final message +echo "------------ Successfully Running $CONTAINER_NAME" diff --git a/prod/pull-api.sh b/prod/pull-api.sh new file mode 100644 index 0000000..af3017e --- /dev/null +++ b/prod/pull-api.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Load config file +source ./config.env + +#set branch Name +BRANCH_NAME=$API_BRANCH_NAME + +# Repository URL +REPO_URL="https://git.marcoaiot.com/admin/marco.pms.api.git" +REPO_DIR="marco.pms.api" + +# Step 1: Clone the GitHub repository (use the branch defined) +if [ -d "$REPO_DIR" ]; then + echo "Repository already exists. Pulling latest changes from branch $BRANCH_NAME..." + cd "$REPO_DIR" || exist 1 + + # ensure we are on correct branch + git fetch origin + git checkout "$BRANCH_NAME" + git pull origin "$BRANCH_NAME" + +else + echo "Cloning the Git repository from branch $BRANCH_NAME..." + git clone -b "$BRANCH_NAME" "$REPO_URL" + cd "$REPO_DIR" || exit 1 + +fi + +echo "Successfully pull $BRANCH_NAME" diff --git a/prod/pull-client.sh b/prod/pull-client.sh new file mode 100644 index 0000000..906bbbb --- /dev/null +++ b/prod/pull-client.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Load config file +source ./config.env + + +#set branch Name +BRANCH_NAME=$WEB_BRANCH_NAME + +# Repository URL +REPO_URL="https://git.marcoaiot.com/admin/marco.pms.web.git" +REPO_DIR="marco.pms.web" + +# Step 1: Clone the GitHub repository (use the branch defined) +if [ -d "$REPO_DIR" ]; then + echo "Repository already exists. Pulling latest changes from branch $BRANCH_NAME..." + cd "$REPO_DIR" || exist 1 + + # ensure we are on correct branch + git fetch origin + git checkout "$BRANCH_NAME" + git pull origin "$BRANCH_NAME" + +else + echo "Cloning the Git repository from branch $BRANCH_NAME..." + git clone -b "$BRANCH_NAME" "$REPO_URL" + cd "$REPO_DIR" || exit 1 + +fi + +echo "Successfully pull $BRANCH_NAME" diff --git a/stage/config.env b/stage/config.env new file mode 100644 index 0000000..7c869a3 --- /dev/null +++ b/stage/config.env @@ -0,0 +1,9 @@ +# config.env +ENVIRONMENT=staging +WEB_BRANCH_NAME=Issue_May_2W +WEB_IMAGE_NAME=marco.web +WEB_CONTAINER_NAME=marco.web +API_BRANCH_NAME=Issues_May_2W +API_IMAGE_NAME=marco.api +API_CONTAINER_NAME=marco.api +API_URL=https://stageapi.marcoaiot.com diff --git a/stage/publish-api.sh b/stage/publish-api.sh new file mode 100644 index 0000000..81ce6e1 --- /dev/null +++ b/stage/publish-api.sh @@ -0,0 +1,52 @@ +# #!/bin/bash + +# Load config file +source ./config.env + +# Step 1: set branch Name +IMAGE_NAME=$API_IMAGE_NAME +CONTAINER_NAME=$API_CONTAINER_NAME +REPO_DIR="marco.pms.api" + +# Navigate into the project directory + +if [ -d "$REPO_DIR" ]; then + cd "$REPO_DIR" || exit + echo "Changed directory to $REPO_DIR" +else + echo "Folder '$REPO_DIR' does not exist. Exiting..." + exit 1 +fi + + +# Step 2: Build the Docker image +echo "Building the Docker image..." +# docker build -t $IMAGE_NAME -f Marco.Pms.Services/Dockerfile . +echo "?? Building Docker image: $IMAGE_NAME" +if ! docker build -t "$IMAGE_NAME" -f Marco.Pms.Services/Dockerfile .; then + echo "? Docker build failed for image: $IMAGE_NAME" + exit 1 +fi + + + +echo "Image Name:$IMAGE_NAME" +echo "Container Name: $CONTAINER_NAME" + + +# Step 3: Stop and remove any existing container with the same name + +if sudo docker ps -q --filter "name=$CONTAINER_NAME"; then + echo "Stopping and removing existing container..." + sudo docker stop "$CONTAINER_NAME" + sudo docker rm "$CONTAINER_NAME" +fi + + +# Step 5: Run the Docker containerer +echo "Running Docker container..." + +docker run -d --name $CONTAINER_NAME --network mynetwork -p 8080:8080 -p 8081:8081 $IMAGE_NAME + +# Step 6: Final Message +echo "Successfully Running $CONTAINER_NAME" diff --git a/stage/publish-client.sh b/stage/publish-client.sh new file mode 100644 index 0000000..380178e --- /dev/null +++ b/stage/publish-client.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# Load config file +source ./config.env + + +# Set the name for the Docker image and container +IMAGE_NAME=$WEB_IMAGE_NAME +CONTAINER_NAME=$WEB_CONTAINER_NAME +REPO_DIR="marco.pms.web" +VITE_API_URL=$API_URL + + +# Navigate into the cloned project directory + +if [ -d "$REPO_DIR" ]; then + cd "$REPO_DIR" || exit + echo "------------ Changed directory to $REPO_DIR" +else + echo "------------ Folder '$REPO_DIR' does not exist. Exiting..." + exit 1 +fi + +#cd marco.pms.web || exit + +# Step 2: Install dependencies +echo "------------ Installing dependencies using npm..." +npm install + +# Step 3: Build the Client app +echo "------------ Building the React app..." +npm run build + + +# Step 4: Delete Existing Container +if sudo docker ps -q --filter "name=$CONTAINER_NAME"; then + echo "------------ Stopping existing container..." + sudo docker stop "$CONTAINER_NAME" + sudo docker rm "$CONTAINER_NAME" +else + echo "------------ No existing container found for: $CONTAINER_NAME" +fi + + +# Step 5: Delete Existing Image +# Check if the image exists +if docker images | awk '{print $1}' | grep -q "^$IMAGE_NAME"; then + echo "------------ Deleting existing Docker image: $IMAGE_NAMEE" + docker rmi -f $IMAGE_NAME +else + echo "------------ No existing image found for: $IMAGE_NAME" +fi + + +echo "------------ Image Name:$IMAGE_NAME" +echo "------------ Container Name: $CONTAINER_NAME" +echo "------------ Image Name: $IMAGE_NAME" +echo "------------ VITE_API_URL:$VITE_API_URL" + + +# Step 6: Build New Client Image + +echo "------------ Building Docker image..." +sudo docker build -t "$IMAGE_NAME" . + +# Go to outer directory +cd ../ + +# Step 7: Run the Docker containerer +echo "------------ Running Docker container..." +docker run -d --name "$CONTAINER_NAME" -p 4173:4173 \ + -e VITE_API_URL="$VITE_API_URL" "$IMAGE_NAME" + + +# Final message +echo "------------ Successfully Running $CONTAINER_NAME" diff --git a/stage/pull-api.sh b/stage/pull-api.sh new file mode 100644 index 0000000..af3017e --- /dev/null +++ b/stage/pull-api.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Load config file +source ./config.env + +#set branch Name +BRANCH_NAME=$API_BRANCH_NAME + +# Repository URL +REPO_URL="https://git.marcoaiot.com/admin/marco.pms.api.git" +REPO_DIR="marco.pms.api" + +# Step 1: Clone the GitHub repository (use the branch defined) +if [ -d "$REPO_DIR" ]; then + echo "Repository already exists. Pulling latest changes from branch $BRANCH_NAME..." + cd "$REPO_DIR" || exist 1 + + # ensure we are on correct branch + git fetch origin + git checkout "$BRANCH_NAME" + git pull origin "$BRANCH_NAME" + +else + echo "Cloning the Git repository from branch $BRANCH_NAME..." + git clone -b "$BRANCH_NAME" "$REPO_URL" + cd "$REPO_DIR" || exit 1 + +fi + +echo "Successfully pull $BRANCH_NAME" diff --git a/stage/pull-client.sh b/stage/pull-client.sh new file mode 100644 index 0000000..906bbbb --- /dev/null +++ b/stage/pull-client.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Load config file +source ./config.env + + +#set branch Name +BRANCH_NAME=$WEB_BRANCH_NAME + +# Repository URL +REPO_URL="https://git.marcoaiot.com/admin/marco.pms.web.git" +REPO_DIR="marco.pms.web" + +# Step 1: Clone the GitHub repository (use the branch defined) +if [ -d "$REPO_DIR" ]; then + echo "Repository already exists. Pulling latest changes from branch $BRANCH_NAME..." + cd "$REPO_DIR" || exist 1 + + # ensure we are on correct branch + git fetch origin + git checkout "$BRANCH_NAME" + git pull origin "$BRANCH_NAME" + +else + echo "Cloning the Git repository from branch $BRANCH_NAME..." + git clone -b "$BRANCH_NAME" "$REPO_URL" + cd "$REPO_DIR" || exit 1 + +fi + +echo "Successfully pull $BRANCH_NAME"