Skip to content

Commit

Permalink
Add docker dev environment at deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
javibu13 committed Dec 11, 2023
1 parent d4488fd commit d4545c3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 29 deletions.
51 changes: 25 additions & 26 deletions devops/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ MIN_MSGSIZE_MAX=8000

ARG1=$1

#Set production environment as default
docker_compose_file="docker-compose.yml"

cd "$(dirname "$0")/.."

initial_deploy () {
# TODO: Add force_stop to restart the system if it is already running
check_mqueue_sizes
# If ARG1 is equal to "build", execute the build command
if [ "${ARG1}" = "build" ]; then
docker compose -f ./devops/docker-compose.yml up -d --build
docker compose -f ./devops/${docker_compose_file} up -d --build
else
docker compose -f ./devops/docker-compose.yml up -d
docker compose -f ./devops/${docker_compose_file} up -d
fi
if [ $? -eq 0 ]; then
echo "Master node containers deployed"
Expand Down Expand Up @@ -86,6 +89,20 @@ stop_mqtt () {
docker compose -f ./devops/broker_mqtt/docker-compose.yml down
}

ask_for_environment () {
# Ask for input of dev or prod
echo "Do you want to work with the dev or prod version? (dev/prod)"
read -p "Type dev or prod: " dev_or_prod
if [ "${dev_or_prod}" = "dev" ]; then
docker_compose_file="dev-docker-compose.yml"
elif [ "${dev_or_prod}" = "prod" ]; then
docker_compose_file="docker-compose.yml"
else
echo "Invalid input"
exit 1
fi
}

################################################################################
################################# MAIN #################################
################################################################################
Expand All @@ -103,8 +120,8 @@ then
fi

# Check if the required files are present.
required_file_list=("docker-compose.yml" "config_params.yaml" "web_server/.cred.env"
"web_server/log_config.yaml" "mn_manager/log_config.yaml"
required_file_list=("docker-compose.yml" "dev-docker-compose.yml" "config_params.yaml"
"web_server/.cred.env" "web_server/log_config.yaml" "mn_manager/log_config.yaml"
"mn_manager/.cred.yaml" "master_db/.cred.env"
"master_db/createMasterCyclerTables.sql"
"master_db/insertDeviceInfoToMaster.sql" "broker_mqtt/.cred.env"
Expand All @@ -121,9 +138,10 @@ done

# Check command to run depending on the arguments
case ${ARG1} in
"")
""|"build")
# echo "Initial Deploy"
launch_mqtt
ask_for_environment
initial_deploy
;;
"mqtt")
Expand All @@ -137,28 +155,9 @@ case ${ARG1} in
"force-stop")
# echo "Force Stop"
stop_mqtt
docker compose -f ./devops/docker-compose.yml down
ask_for_environment
docker compose -f ./devops/${docker_compose_file} down
;;
# "sniffer")
# # echo "Check Sniffer"
# if [[ "${ARG2}" = "can" ]] || [[ "${ARG2}" = "scpi" ]]; then
# # echo "Cycler ${2}"
# check_sniffer "${ARG2}"
# else
# >&2 echo "[ERROR] Invalid sniffer"
# exit 3
# fi
# ;;
# "stop-cycler")
# # echo "Stop cycler ${ARG2}"
# if [[ ${ARG2} =~ $INT_RE ]]; then
# # echo "Cycler ${2}"
# stop_active_cycler "${ARG2}"
# else
# >&2 echo "[ERROR] Invalid Cycler Station ID"
# exit 3
# fi
# ;;
*)
>&2 echo "[ERROR] Invalid command type: ${ARG1}"
exit 3
Expand Down
41 changes: 41 additions & 0 deletions devops/dev-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.8'

name: wattrex_mn_dev

services:
wattrex_db:
extends:
file: ./docker-compose.yml
service: wattrex_db
ports:
- "3369:3306"
volumes:
- wattrex_db_data_dev:/var/lib/mysql

wattrex_mn_manager:
extends:
file: ./docker-compose.yml
service: wattrex_mn_manager
build:
args:
- test_pypi_flag=--index-url https://test.pypi.org/simple/
depends_on:
- wattrex_db

wattrex_web_server:
extends:
file: ./docker-compose.yml
service: wattrex_web_server
build:
args:
- test_pypi_flag=--index-url https://test.pypi.org/simple/
ports:
- "8869:8000"
depends_on:
- wattrex_db
- wattrex_mn_manager


volumes:
wattrex_db_data_dev:
name: wattrex_db_data_dev
3 changes: 2 additions & 1 deletion devops/mn_manager/Dockerfile.mn_manager
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ ENV CONFIG_FILE_PATH=/code/devops/config_params.yaml

ARG CACHE=1
RUN pip install --upgrade pip
RUN pip install --upgrade wattrex-mn-manager
ARG test_pypi_flag
RUN pip install --upgrade ${test_pypi_flag} wattrex-mn-manager
ADD ./devops/mn_manager/run.py /code/devops/mn_manager/run.py

CMD ["python", "./devops/mn_manager/run.py"]
2 changes: 2 additions & 0 deletions devops/web_server/Dockerfile.web_server
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ARG CACHE=1
ADD ./venv/web_server/requirements.txt /code/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ARG test_pypi_flag
RUN pip install --upgrade ${test_pypi_flag} wattrex-mn-manager
# The following line is needed to avoid a bug in mysql-connector-python installed by wattrex-mn-manager
RUN pip install --upgrade mysql-connector-python==8.0.26
ADD ./ /code/
Expand Down
3 changes: 1 addition & 2 deletions venv/web_server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ protobuf==3.19.1
soupsieve==2.3.1
sqlparse==0.4.2
kaleido==0.2.1
# mysql-connector-python==8.0.26 # Disabled due to wattrex-mn-manager (it installs newer version)
wattrex-mn-manager
# mysql-connector-python==8.0.26 # Disabled due to wattrex-mn-manager (it installs newer version)

0 comments on commit d4545c3

Please sign in to comment.