github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/dashboard/scripts/tmux.sh (about)

     1  #!/bin/bash
     2  set -euo pipefail
     3  IFS=$'\n\t'
     4  SESSION=bacalhau-dashboard
     5  export APP=${APP:=""}
     6  export PREDICTABLE_API_PORT=1
     7  export BACALHAU_API_HOST=localhost
     8  export BACALHAU_API_PORT=20000
     9  export BACALHAU_DASHBOARD_POSTGRES_HOST=127.0.0.1
    10  export BACALHAU_DASHBOARD_POSTGRES_DATABASE=postgres
    11  export BACALHAU_DASHBOARD_POSTGRES_USER=postgres
    12  export BACALHAU_DASHBOARD_POSTGRES_PASSWORD=postgres
    13  export BACALHAU_DASHBOARD_JWT_SECRET=apples
    14  export LOG_LEVEL=DEBUG
    15  
    16  function start() {
    17    if tmux has-session -t "$SESSION" 2>/dev/null; then
    18      echo "Session $SESSION already exists. Attaching..."
    19      sleep 1
    20      tmux -2 attach -t $SESSION
    21      exit 0;
    22    fi
    23  
    24    echo "Creating tmux session $SESSION..."
    25  
    26    rm -f /tmp/bacalhau-devstack.{port,pid}
    27  
    28    # get the size of the window and create a session at that size
    29    local screensize=$(stty size)
    30    local width=$(echo -n "$screensize" | awk '{print $2}')
    31    local height=$(echo -n "$screensize" | awk '{print $1}')
    32    tmux -2 new-session -d -s $SESSION -x "$width" -y "$(($height - 1))"
    33  
    34    # the right hand col with a 50% vertical split
    35    tmux split-window -h -d
    36    tmux select-pane -t 1
    37    tmux split-window -v -d
    38    tmux select-pane -t 0
    39    tmux split-window -v -d
    40    tmux split-window -v -d
    41    tmux select-pane -t 4
    42    tmux split-window -v -d
    43  
    44    tmux send-keys -t 0 'make devstack' C-m
    45    tmux send-keys -t 1 'cd dashboard/frontend' C-m
    46    tmux send-keys -t 1 'yarn dev'
    47    tmux send-keys -t 2 'cd dashboard/api' C-m
    48    tmux send-keys -t 2 'go run . serve --port 8081'
    49    tmux send-keys -t 3 "bacalhau docker run ubuntu echo hello"
    50    tmux send-keys -t 4 "docker exec -ti postgres psql --user postgres"
    51    tmux send-keys -t 5 "docker run -ti --rm --name postgres -p 5432:5432 -e POSTGRES_DB=$BACALHAU_DASHBOARD_POSTGRES_DATABASE -e POSTGRES_USER=$BACALHAU_DASHBOARD_POSTGRES_USER -e POSTGRES_PASSWORD=$BACALHAU_DASHBOARD_POSTGRES_PASSWORD postgres" C-m
    52  
    53    tmux -2 attach-session -t $SESSION
    54  }
    55  
    56  function stop() {
    57    echo "Stopping tmux session $SESSION..."
    58    docker rm -f postgres || true
    59    tmux kill-session -t $SESSION
    60  }
    61  
    62  command="$@"
    63  
    64  if [ -z "$command" ]; then
    65    command="start"
    66  fi
    67  
    68  eval "$command"