Files
mozo-backend/drb_counter/rebuild-docker.sh
T

68 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# This script rebuilds the whole environment and starts a new container
#
# Set the prompt message
environments=("production" "development" "test" "Quit")
echo "Choose the environment (1-3): "
for i in "${!environments[@]}"; do
echo "$((i+1))) ${environments[$i]}"
done
read -p "Enter number: " choice
if [[ $choice -eq ${#environments[@]} ]]; then
exit 0
fi
# Validate and use the choice (subtract 1 for 0-based array index)
if [[ $choice -gt 0 && $choice -lt ${#environments[@]} ]]; then
environment=${environments[$((choice-1))]}
echo "You selected: $environment"
else
echo "Invalid selection."
exit 0
fi
# 1. ensure this script is run from the project's root, not the drb_counter directory
pwd_dirname=$(basename $(pwd));
script_dirname="drb_counter";
arch=$(uname)
# Check for sanity, was debugging database mismatch
if [ "$#" -lt 1 ]; then
nodename=$(uname -n)
known_development_machines=("fedorasahi" "blackview")
for item in "${known_development_machines[@]}"; do
if [[ "$item" == "$nodename" ]]; then
echo "Stupid Error: You are on a known development device: $nodename. As a developer, always explicitly supply the environment as the first argument" >&2
echo "Usage: ./drb_counter/rebuild-docker.sh development"
exit 1
fi
done
fi
# 2. stop and remove all running/existing containers
docker rm $(docker stop $(docker ps -a -q --filter ancestor=mozo_drb_counter))
# 3. remove the previously built images
docker rmi mozo_drb_counter
# 4. rebuild a fresh image from the latest code
docker build -f drb_counter/Dockerfile -t mozo_drb_counter .
# debug docker and enter the bash:
# docker run --network=host --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD -t -i --rm mozo_drb_counter bash
# 5. Spin up the counter container from the generated image
if [ $arch == "Darwin" ]; then
echo "Running the created image using the Mac Darwin port exposing"
docker run -p 9022:9022 --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --add-host=host.docker.internal:host-gateway --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
else
# docker run --network=host --env DRB_ENV=production --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --add-host=host.docker.internal:host-gateway --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
docker run --network=host --env DRB_ENV=$environment --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
#docker run -p 9022:9022 --env DRB_ENV=$environment --env COUCHDB_ADMIN_PASSWORD=$COUCHDB_ADMIN_PASSWORD --restart unless-stopped --detach --name=mozo_drb_counter mozo_drb_counter
fi
# To just start the container created through al these steps without rebuilding them:
# docker container start $(docker ps -a -q --filter ancestor=mozo_drb_counter)