Alternative Usage

The above is our recommended way to run the app for the smoothest user experience. However, users may install and run the app manually if they wish.

Alternative setups

Unlike the setup and rerun scripts, manually building or running the app will not include automated installation of all required programs. Users should expect to have to troubleshoot errors due to missing requirements.

Manual Docker PanelSearch setup — These steps can also be found in docker_setup.sh, and involve creating the SQL database and PanelSearch app within Docker containers. Users must already have installed docker and mysql for these commands to work.

To create the SQL database within a docker container, a network for the two containers to connect via, and a volume for data persistence. If the user wishes to connect to the cloud SQL database instead of a local docker SQL database, omit this step:

# create docker network for containers to connect via
docker network create panelsearch-network
echo "panelsearch-network created"

# create docker volume for sql data to be stored on
docker volume create panelsearch-volume
echo "panelsearch-volume created"

# create mysql server in the panelsearch-database container
docker run --name panelsearch-database\
             --network panelsearch-network \
            --volume panelsearch-volume \
            -e MYSQL_ROOT_PASSWORD=password \
          -d mysql:8
echo "panelsearch-database container created"

# start mysql
#echo "mySQL running"
sudo service mysql start
sudo chmod -R 755 /var/run/mysqld

# create panelsearch database and tables on the mysql server

# Set the maximum number of attempts
max_attempts=100

# Set a counter for the number of attempts
attempt_num=1

# Set a flag to indicate whether the command was successful
success=false

# Loop until the command is successful or the maximum number of attempts is reached
while [ $success = false ] && [ $attempt_num -le $max_attempts ]; do
  # Execute the command
  docker exec panelsearch-database mysql -uroot -ppassword -e \
"CREATE DATABASE IF NOT EXISTS panelsearch;\
 CREATE TABLE IF NOT EXISTS panelsearch.patients( \
                id int PRIMARY KEY NOT NULL AUTO_INCREMENT,\
                patient_id varchar(50),\
                search_id int);\
 CREATE TABLE IF NOT EXISTS panelsearch.searches( \
                id int KEY AUTO_INCREMENT, \
                panel_id int, \
                panel_name varchar(500),\
                panel_version varchar(50),\
                GMS varchar(50),\
                gene_number int,\
                r_code varchar(5),\
                transcript varchar(50),\
                genome_build varchar(50),\
                bed_file varchar(50),\
                UNIQUE (panel_id, panel_name, panel_version, GMS, gene_number, r_code, \
                     transcript, genome_build, bed_file)\
                );"

  # Check the exit code of the command
  if [ $? -eq 0 ]; then
    # The command was successful
    success=true
  else
    # The command was not successful
    echo "Attempt $attempt_num failed. Trying again..."
    sleep 5
    # Increment the attempt counter
    attempt_num=$(( attempt_num + 1 ))
  fi
done

# Check if the command was successful
if [ $success = true ]; then
  # The command was successful
  echo "The command was successful after $attempt_num attempts."
else
  # The command was not successful
  echo "The command failed after $max_attempts attempts."
  exit "Setup aborted. Please try again"
fi



echo "panelsearch database created"
echo "database tables 'searches' and 'patients' created"

# make sure user has docker permissions
#sudo groupadd docker
#sudo usermod -aG docker ${USER}
#newgrp docker
#echo "User permissions for docker enabled"

sudo chmod 777 PanelSearch/panel_search.log
echo "permissions enabled"

To build the docker image:

# build the app docker container using the Dockerfile in the repo
docker buildx build -t panelsearch .
echo "panelsearch app container created"

To run the docker container for the first time when using a docker SQL database:

# run the docker container for the first time
echo "running panelsearch app... "
docker run -it --name panelsearch --volume panelsearch-volume \
--network panelsearch-network panelsearch

To run the docker container for the first time when using a cloud SQL database:

# run the docker container for the first time
echo "running panelsearch app... "
docker run -it --name panelsearch panelsearch

To run the docker container subsequently when using either SQL database:

docker exec -it panelsearch bash -c "python PanelSearch/main.py"

Troubleshooting

Troubleshooting error messsage: ‘docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:’:

sudo groupadd docker

sudo usermod -aG docker $USER

newgrp docker

Troubleshooting error message: ‘ERROR: Cannot connect to the Docker daemon at unix://?var/run/docker.sock. Is the docker daemon running?:

sudo systemct1 start docker
Troubleshooting error message: ‘ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’

Try:

sudo apt install mysql-server
sudo service mysql start

References

https://docs.docker.com/guides/walkthroughs/containerize-your-app/#:~:text=Containerize%20your%20application%201%20Step%201%3A%20Run%20the,4%20Step%204%3A%20Update%20the%20Docker%20assets%20

https://www.docker.com/blog/how-to-dockerize-your-python-applications/