diff --git a/devops/deploy.sh b/devops/deploy.sh index b22a0ae..2f32400 100755 --- a/devops/deploy.sh +++ b/devops/deploy.sh @@ -7,6 +7,9 @@ MIN_MSGSIZE_MAX=8000 ARG1=$1 +#Set production environment as default +docker_compose_file="docker-compose.yml" + cd "$(dirname "$0")/.." initial_deploy () { @@ -14,9 +17,9 @@ initial_deploy () { 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" @@ -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 ################################# ################################################################################ @@ -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" @@ -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") @@ -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 diff --git a/devops/dev-docker-compose.yml b/devops/dev-docker-compose.yml new file mode 100644 index 0000000..ff54cc7 --- /dev/null +++ b/devops/dev-docker-compose.yml @@ -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 diff --git a/devops/mn_manager/Dockerfile.mn_manager b/devops/mn_manager/Dockerfile.mn_manager index 12b7dab..cfa4498 100644 --- a/devops/mn_manager/Dockerfile.mn_manager +++ b/devops/mn_manager/Dockerfile.mn_manager @@ -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"] diff --git a/devops/web_server/Dockerfile.web_server b/devops/web_server/Dockerfile.web_server index d7545b6..93eb9ae 100644 --- a/devops/web_server/Dockerfile.web_server +++ b/devops/web_server/Dockerfile.web_server @@ -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/ diff --git a/venv/web_server/requirements.txt b/venv/web_server/requirements.txt index 1e4fbd3..7480cb6 100644 --- a/venv/web_server/requirements.txt +++ b/venv/web_server/requirements.txt @@ -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 \ No newline at end of file +# mysql-connector-python==8.0.26 # Disabled due to wattrex-mn-manager (it installs newer version) \ No newline at end of file