Skip to content

Commit

Permalink
Added option to use docker container over ssh tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
frankcorneliusmartin committed Jan 11, 2024
1 parent c29f093 commit 83bb2a4
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 286 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

*.log
/node.tpl
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

This repository contains convenience scripts for installing vantage6 nodes at data stations participating in the BLUEBERRY project.

## TODO
- [ ] Add option to use Docker version of the OMOP database (no SSH tunneling required)

## Getting Started
These instructions will get you a running vantage6 node that is connected to the
BLUEBERRY server.

### Prerequisites

The scripts are designed to run on an Oracle Linux 8 Machine (server edition). During installation it requires internet access to download the necessary packages.
- The scripts are designed to run on an Oracle Linux 8 Machine (server edition).
- During installation it requires internet access to download the necessary packages.
- `sudo` permissions
- Install git:
```
sudo dnf update -y
sudo dnf install git -y
```
Install git:
```
sudo dnf update -y
sudo dnf install git -y
```
It also requires an active internet connection.
### Installing
Expand Down
80 changes: 33 additions & 47 deletions create-node.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /bin/bash
source $SCRIPT_DIR/utils.sh
CONFIG_FILE=$HOME/.config/vantage6/node/blueberry.yaml
CONFIG_FILE_TEMPLATE=$SCRIPT_DIR/node.tpl

WRITE_CONFIG_FILE=true
if [ -f "$CONFIG_FILE" ]; then
Expand All @@ -13,6 +14,7 @@ if [ -f "$CONFIG_FILE" ]; then
fi
fi


if [ "$WRITE_CONFIG_FILE" = true ]; then

# Create config dir
Expand All @@ -29,66 +31,50 @@ if [ "$WRITE_CONFIG_FILE" = true ]; then

mkdir -p $TASK_DIR

# OMOP settings
export OMOP_HOST="omop"
# OMOP database settings
export OMOP_PORT=5432

export OMOP_DATABASE="postgres"
export OMOP_USER="postgres"
export OMOP_PASSWORD="postgres"
export OMOP_CDM_SCHEMA="cmd"
export OMOP_RESULT_SCHEMA="result"

# Check if the vantage6-node user already exists
print_step "Checking if the vantage6-node user already exists"
NEW_USER="vantage6-node"
if id -u "vantage6-node" >/dev/null 2>&1; then
print_warning "The vantage6-node user already exists"
else
print_step "Creating new user: $NEW_USER"
sudo useradd $NEW_USER

# Set password for the new user
PASSWORD=$(openssl rand -base64 16)
echo "$NEW_USER:$PASSWORD" | sudo chpasswd
fi


print_step "Executing some steps as sudo user"
source $SCRIPT_DIR/create-ssh-user.sh

# Tunnel settings
print_step "Setting tunnel settings"
export TUNNEL_HOSTNAME=$OMOP_HOST
export SSH_HOST=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
export SSH_PORT=22
print_step "SSH_HOST: $SSH_HOST, SSH_PORT: $SSH_PORT"


if [ -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
export SSH_HOST_FINGERPRINT=$(cat /etc/ssh/ssh_host_rsa_key.pub)
else
print_error "File /etc/ssh/ssh_host_rsa_key.pub does not exist."
print_error "Is openssh-server installed and running?"
fi

export SSH_USERNAME=$NEW_USER
export SSH_KEY=$PRIVATE_KEY_FILE
print_step "SSH_KEY: $SSH_KEY"

export TUNNEL_BIND_IP="0.0.0.0"
export TUNNEL_BIND_PORT=$OMOP_PORT

export TUNNEL_REMOTE_IP="127.0.0.1"
export TUNNEL_REMOTE_PORT=5432
print_step "TUNNEL_REMOTE_PORT: $TUNNEL_REMOTE_PORT"
# depending on the method selected we need to inject a different block in the
# config file
select_database_method

case "$DB_METHOD" in
"Docker-service")
# Code to execute if DB_METHOD is "docker"
user_input "Please enter the OMOP container name"
export OMOP_HOST=$REPLY
export DOCKER_SERVICE_CONTAINER_LABEL=$REPLY
include_content=$(<$SCRIPT_DIR/templates/docker-service.tpl)

;;
"SSH-tunnel")
# Code to execute if DB_METHOD is "ssh_tunnel"
export OMOP_HOST="omop"
include_content=$(<$SCRIPT_DIR/templates/ssh-tunnel.tpl)
source $SCRIPT_DIR/create-ssh-tunnel.sh
;;
*)
# Code to execute if DB_METHOD is anything else
print_error "Invalid option $DB_METHOD. Exiting..."
exit 1
;;
esac

escaped_content=$(echo "$include_content" | sed -e ':a' -e 'N' -e '$!ba' -e 's/[\/&]/\\&/g' -e 's/\n/NEWLINE/g')
sed "s/{{DATABASE_CONNECTION}}/$escaped_content/g" $SCRIPT_DIR/templates/node-config.tpl | sed 's/NEWLINE/\n/g' > $CONFIG_FILE_TEMPLATE
# sed "s/{{DATABASE_CONNECTION}}/$escaped_content/" $SCRIPT_DIR/templates/node-config.tpl > $CONFIG_FILE_TEMPLATE

# # Create the config file
print_step "Creating the config file"
mkdir -p $HOME/.config/vantage6/node

print_step "Creating the vantage6 config file"
create_config_file $SCRIPT_DIR $CONFIG_FILE
create_config_file $CONFIG_FILE_TEMPLATE $CONFIG_FILE
fi


File renamed without changes.
47 changes: 47 additions & 0 deletions create-ssh-tunnel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#! /bin/bash
source $SCRIPT_DIR/utils.sh

# Check if the vantage6-node user already exists
print_step "Checking if the vantage6-node user already exists"
NEW_USER="vantage6-node"
if id -u "vantage6-node" >/dev/null 2>&1; then
print_warning "The vantage6-node user already exists"
else
print_step "Creating new user: $NEW_USER"
sudo useradd $NEW_USER

# Set password for the new user
PASSWORD=$(openssl rand -base64 16)
echo "$NEW_USER:$PASSWORD" | sudo chpasswd
fi


print_step "Executing some steps as sudo user"
source $SCRIPT_DIR/create-ssh-keys.sh

# Tunnel settings
print_step "Setting tunnel settings"
export TUNNEL_HOSTNAME=$OMOP_HOST
export SSH_HOST=$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)
export SSH_PORT=22
print_step "SSH_HOST: $SSH_HOST, SSH_PORT: $SSH_PORT"


if [ -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
export SSH_HOST_FINGERPRINT=$(cat /etc/ssh/ssh_host_rsa_key.pub)
else
print_error "File /etc/ssh/ssh_host_rsa_key.pub does not exist."
print_error "Is openssh-server installed and running?"
fi

export SSH_USERNAME=$NEW_USER
export SSH_KEY=$PRIVATE_KEY_FILE
print_step "SSH_KEY: $SSH_KEY"

export TUNNEL_BIND_IP="0.0.0.0"
export TUNNEL_BIND_PORT=$OMOP_PORT

export TUNNEL_REMOTE_IP="127.0.0.1"
export TUNNEL_REMOTE_PORT=5432
print_step "TUNNEL_REMOTE_PORT: $TUNNEL_REMOTE_PORT"
2 changes: 2 additions & 0 deletions templates/docker-service.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker_services:
container_label: ${DOCKER_SERVICE_CONTAINER_LABEL}
Loading

0 comments on commit 83bb2a4

Please sign in to comment.