about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2025-05-09 12:36:59 +0300
committerMunyoki Kilyungi2025-05-09 12:36:59 +0300
commit4ca9bbe29781913f046b22e12e738a5317310dc1 (patch)
treee14bbae01de5fbcb50701bdef734fbdc0ffdd6f3
parent0ff2f957fe64e2fe5c898525a290314abdc2d5a2 (diff)
downloadgn-machines-4ca9bbe29781913f046b22e12e738a5317310dc1.tar.gz
Add cli tutorial for genenetwork set-up.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--genenetwork-local-container.scm1
-rwxr-xr-xgenenetwork-local-container.sh220
2 files changed, 212 insertions, 9 deletions
diff --git a/genenetwork-local-container.scm b/genenetwork-local-container.scm
index 8dc02c7..4399796 100644
--- a/genenetwork-local-container.scm
+++ b/genenetwork-local-container.scm
@@ -21,7 +21,6 @@
 ;;; tux04.
 
 (use-modules (gnu)
-             (genenetwork services genenetwork)
              (gnu build linux-container)
              ((gn packages genenetwork) #:select (genenetwork2 genenetwork3 gn-auth gn-libs gn-uploader))
              ((gnu packages admin) #:select (shepherd shadow))
diff --git a/genenetwork-local-container.sh b/genenetwork-local-container.sh
index 1db01dd..16492c6 100755
--- a/genenetwork-local-container.sh
+++ b/genenetwork-local-container.sh
@@ -26,6 +26,7 @@ set -euo pipefail
 
 BASE_DIR="${HOME:-/home/$USER}/genenetwork"
 SYSTEM_DIRECTORIES=(
+    "$BASE_DIR"
     "$BASE_DIR/var/log"
     "$BASE_DIR/var/genenetwork"
     "$BASE_DIR/etc/genenetwork/conf"
@@ -43,8 +44,8 @@ SYSTEM_DIRECTORIES=(
 )
 
 GN_PROJECTS=(
-    "genenetwork2:git@github.com:genenetwork/genenetwork2"
-    "genenetwork3:git@github.com:genenetwork/genenetwork3"
+    "genenetwork2:https://github.com/genenetwork/genenetwork2.git"
+    "genenetwork3:https://github.com/genenetwork/genenetwork3.git"
     "gn-transform-databases:https://git.genenetwork.org/gn-transform-databases/"
     "gn-auth:https://git.genenetwork.org/gn-auth"
     "gn-docs:https://git.genenetwork.org/gn-docs"
@@ -96,8 +97,8 @@ if [ -z "${HOME:-}" ]; then
     exit 1
 fi
 
-if [ "$1" = "--init-container" ]; then
-    log "INFO" "Creating system directories..."
+init_container() {
+        log "INFO" "Creating system directories..."
     for dir in "${SYSTEM_DIRECTORIES[@]}"; do
 	# Check if directory exists and is accessible
 	if [ -d "$dir" ]; then
@@ -125,7 +126,7 @@ if [ "$1" = "--init-container" ]; then
 		exit 1
             fi
             # Set ownership to current user if created with sudo
-            if ! sudo chown "$USER:$USER" "$dir"; then
+            if ! sudo chown -R "$USER" "$dir"; then
 		log "WARNING" "Failed to set ownership for: $dir"
             fi
 	fi
@@ -282,9 +283,13 @@ if [ "$1" = "--init-container" ]; then
     log "INFO" "Run with: $CONTAINER_BIN"
     log "INFO" "Email: test@development.user"
     log "INFO" "Password: testpasswd"
+}
+if [ "$1" = "--init-container" ]; then
+    init_container
+    exit 0
 fi
 
-if [ "$1" = "--init-sql" ]; then
+init_sql() {
     # Configuration
     URL="https://files.genenetwork.org/database/db_webqtl_s-2025-02-18.sql.xz"
     DOWNLOAD_DIR="/tmp"
@@ -370,10 +375,14 @@ if [ "$1" = "--init-sql" ]; then
     rm -f "$DOWNLOAD_DIR/$EXTRACTED_FILE"
 
     log INFO "Database import completed successfully"
+}
+
+if [ "$1" = "--init-sql" ]; then
+    init_sql
     exit 0
 fi
 
-if [ "$1" = "--init-rdf" ]; then
+init_rdf() {
     # Check for required tools
     for cmd in guix; do
 	if ! command -v "$cmd" &> /dev/null; then
@@ -401,10 +410,14 @@ if [ "$1" = "--init-rdf" ]; then
     guix shell guile-dbi -m "manifest.scm" -- guile load-rdf.scm \
 	 "$curr_dir/etc/conn.scm"
     cd $curr_dir
+}
+
+if [ "$1" = "--init-rdf" ]; then
+    init_rdf
     exit 0
 fi
 
-if [ "$1" = "--init-xapian" ]; then
+init_xapian() {
     # Check for required tools
     log INFO "Please make sure your container is running for this to work"
     log INFO "This takes some time to run"
@@ -432,5 +445,196 @@ if [ "$1" = "--init-xapian" ]; then
     mv "$BASE_DIR/var/lib/xapian/build/*" "$BASE_DIR/var/lib/xapian/" \
 	&& rmdir "$BASE_DIR/var/lib/xapian/build/"
     log INFO "Please restart the container to set the correct permissions"
+}
+
+if [ "$1" = "--init-xapian" ]; then
+    init_xapian
+    exit 0
+fi
+
+
+# Function to handle yes/no prompts
+prompt_yes_no() {
+    local prompt="$1"
+    while true; do
+        read -p "$prompt (yes/no): " response
+        case "$response" in
+            [Yy][Ee][Ss]|[Yy] ) return 0 ;;
+            [Nn][Oo]|[Nn] ) return 1 ;;
+            * ) echo "Please answer 'yes' or 'no'." ;;
+        esac
+    done
+}
+
+# Main tutorial function
+run_beginner_setup_tutorial() {
+    clear
+    # Step 1: Initialize Container
+    echo "Step 1: Setting Up the Container"
+    echo "--------------------------------"
+    echo "Before we begin, make sure you are using the correct guix-profile that has:"
+    echo ""
+    echo "     guix-bioinformatics"
+    echo ""
+    echo "Otherwise, I will terminate early.  If you don't know how to do that, read:"
+    echo ""
+    echo "     https://issues.genenetwork.org/topics/guix/guix-profiles"
+    echo ""
+    echo "This step prepares the container environment where GeneNetwork runs."
+    echo "It ensures all necessary files, folders, and configurations are in place."
+    echo ""
+    echo "This step is similar to running:"
+    echo ""
+    echo "./genenetwork-local-container.sh --init-container"
+    echo ""
+    echo "NOTE: If you have any of the following projects:"
+    echo "           genenetwork2"
+    echo "           genenetwork3"
+    echo "           gn-uploader"
+    echo ""
+    echo "Move/copy them to $BASE_DIR.  This is where'll you'll be hacking"
+    echo "on them from.  Because of how we mount things inside the container,"
+    echo "make sure the names appear as above."
+    echo ""
+    echo "Now, some things to note.  AI search won't work.  To get this working, if you want so,"
+    echo "Get into the container, and modify FAHAMU_AUTH_TOKEN in:"
+    echo "     /etc/genenetwork/conf/gn3/secrets.py"
+    echo ""
+    echo "Similarly, e-mail functionality ala resetting passwords or confirming a new user"
+    echo "won't work unless you modify:"
+    echo "  SMTP_HOST = 'XXXX'"
+    echo "  SMTP_USER = 'XXXX'"
+    echo "  SMTP_PASSWORD = 'XXXX'"
+    echo "  SMTP_PORT = 'XXXX'"
+    echo "  EMAIL_ADDRESS = 'XXXX'"
+    echo "  EMAIL_DISPLAY_NAME = 'XXXX'"
+    echo "inside:"
+    echo "     /etc/genenetwork/conf/gn-auth/secrets.py"
+    echo ""
+    if prompt_yes_no "Would you like to set up the container now?"; then
+        init_container
+	clear
+        echo "Container setup complete!"
+	echo ""
+	echo "Right now you have a working container.  You need to set-up sql, upload rdf data"
+	echo "and build a xapian index to have a fully functioning system akin to production and"
+	echo "our test environment."
+	echo ""
+    else
+	clear
+        echo "Skipping container setup. Moving to the next step."
+    fi
+    echo ""
+
+    # Step 2: Initialize SQL Database
+    echo "Step 2: Setting Up the SQL Database"
+    echo "-----------------------------------"
+    echo "Please make sure you have a working MariaDB installation on your Linux system."
+    echo ""
+    echo "This step creates and configures the database for storing GeneNetwork data."
+    echo ""
+    echo "It sets up tables and initial data needed for Genenetwork to run"
+    echo ""
+    echo "This step is similar to running:"
+    echo "./genenetwork-local-container.sh --init-sql"
+    echo ""
+    echo "Make sure your container, if not, is running for this to work:"
+    echo ""
+    echo "sudo /usr/local/bin/genenetwork-local-container"
+    if prompt_yes_no "Would you like to set up the database now?"; then
+        init_sql
+	clear
+        echo "Database setup complete!"
+    else
+	clear
+        echo "Skipping database setup. Moving to the next step: Importing RDF"
+    fi
+    echo ""
+
+    # Step 3: Initialize RDF
+    echo ""
+    echo "Step 3: Importing RDF into your local set-up"
+    echo "---------------------------------------------"
+    echo "This step adds RDF (Resource Description Framework) data."
+    echo ""
+    echo "RDF helps organize and link data for GeneNetwork."
+    echo ""
+    echo "IMPORTANT. This step requires you to have a running container instance."
+    echo "           Otherwise, it will fail."
+    echo "To run your container, in a different shell, run:"
+    echo "sudo /usr/local/bin/genenetwork-local-container"
+    echo ""
+    echo "This step is similar to running:"
+    echo "./genenetwork-local-container.sh --init-rdf"
+    echo ""
+    echo "Make sure your container, if not, is running for this to work:"
+    echo ""
+    echo "sudo /usr/local/bin/genenetwork-local-container"
+    if prompt_yes_no "Would you like to set up RDF now?"; then
+        init_rdf
+	clear
+        echo "RDF setup complete!"
+    else
+	clear
+        echo "Skipping RDF setup."
+    fi
+    echo ""
+
+    # Step 4: Initialize XAPIAN
+    clear
+    echo "Step 3: Setting up XAPIAN search locally"
+    echo "---------------------------------------------"
+    echo "This indexes all your data from GeneNetwork and indexes it using XAPIAN"
+    echo ""
+    echo "Read more here:"
+    echo "https://issues.genenetwork.org/topics/xapian/xapian-search"
+    echo ""
+    echo "IMPORTANT. This step requires you to have a running container instance."
+    echo "           Otherwise, it will fail."
+    echo "           To run your container, in a different shell, run:"
+    echo "           sudo /usr/local/bin/genenetwork-local-container"
+    echo ""
+    echo "This step is similar to running:"
+    echo "./genenetwork-local-container.sh --init-xapian"
+    echo ""
+    echo "Make sure your container, if not, is running for this to work:"
+    echo ""
+    echo "sudo /usr/local/bin/genenetwork-local-container"
+    if prompt_yes_no "Would you like to build the xapian index now?"; then
+        init_xapian
+	clear
+        echo "XAPIAN setup complete!"
+    else
+	clear
+        echo "Skipping RDF setup."
+    fi
+    echo ""
+
+    # Completion Message
+    echo "============================================================="
+    echo "Congratulations! You've completed the GeneNetwork Beginner Setup Tutorial!"
+    echo "============================================================="
+    echo "You may have skipped some steps. To complete them, run the tutorial again."
+    echo "Your environment is ready to the extent you chose to set it up."
+    echo "If you run your container, you can access the different web-services at:"
+    echo "gn-guile     : localhost:8091"
+    echo "genenetwork2 : localhost:8082"
+    echo "genenetwork3 : localhost:8083"
+    echo "gn-uploader  : localhost:8085"
+    echo "sparql web ui: localhost:7082/sparql"
+    echo ""
+    echo "To access virtuoso back-end service, run:"
+    echo "guix shell virtuoso-ose isql -- 7081"
+    echo ""
+    echo "To login in gn-uploader/genenetwork2, use the following credentials:"
+    echo "  Email: test@development.user"
+    echo "  Password: testpasswd"
+    exit 0
+}
+
+# Check for --beginner-set-up flag or run tutorial interactively
+if [ "$1" = "--beginner-set-up" ]; then
+# Interactive mode: run the tutorial
+    run_beginner_setup_tutorial
     exit 0
 fi