Skip to content

Commit 1178cd3

Browse files
ntoufoudisastrosnatpwdel
authored
Install Procedures (#589)
Co-authored-by: Osnat Katz Moon <137817983+astrosnat@users.noreply.github.com> Co-authored-by: Patrick Delaney <patrick.del@gmail.com>
1 parent 799120e commit 1178cd3

File tree

11 files changed

+570
-666
lines changed

11 files changed

+570
-666
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ DB_PORT=5432
2222
POSTGRES_USER='user'
2323
POSTGRES_PASSWORD='password'
2424
POSTGRES_DATABASE='socialpredict_db'
25+
POSTGRES_VOLUME='pgdata'
2526

2627
FRONTEND_CONTAINER_NAME=socialpredict-frontend-container
2728
FRONTEND_IMAGE_NAME=ghcr.io/openpredictionmarkets/socialpredict-frontend
@@ -37,6 +38,5 @@ NGINX_PORT=80
3738
DOMAIN='domain.com'
3839
DOMAIN_URL='domain.com'
3940
API_URL='domain.com'
40-
EMAIL='john@doe.com'
4141

4242
TRAEFIK_CONTAINER_NAME=socialpredict-traefik-container

SocialPredict

Lines changed: 103 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -e # Stop script on error
4-
set -a # Automatically export all variables
3+
set -euo pipefail
54

5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
# Function to print colored output
12+
print_status() {
13+
echo -e "${GREEN}[INFO]${NC} $1"
14+
}
15+
16+
print_warning() {
17+
echo -e "${YELLOW}[WARNING]${NC} $1"
18+
}
19+
20+
print_error() {
21+
echo -e "${RED}[ERROR]${NC} $1"
22+
}
623

724
# Determine script's directory
825
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -15,144 +32,100 @@ fi
1532

1633
# --- Main SocialPredict Functionality ---
1734

18-
# Ensure .env file exists before resolving path
19-
if [ ! -f "$SCRIPT_DIR/.env" ]; then
20-
echo ".env file not found."
21-
22-
if [ -f "$SCRIPT_DIR/scripts/dev/env_writer_dev.sh" ]; then
23-
echo "Initializing .env file using env_writer_dev.sh (first-run only)..."
24-
export CALLED_FROM_SOCIALPREDICT=yes
25-
SCRIPT_INTERACTIVE=true source "$SCRIPT_DIR/scripts/dev/env_writer_dev.sh"
26-
unset CALLED_FROM_SOCIALPREDICT
27-
else
28-
echo "Cannot continue. .env file is missing and env_writer_dev.sh was not found."
29-
exit 1
30-
fi
31-
fi
32-
33-
# Calculate the absolute path to the .env file
34-
ENV_PATH="$( readlink -f "$SCRIPT_DIR/.env" )"
35-
ENV_FILE="--env-file $ENV_PATH"
36-
3735
# Function to check if a command exists
3836
command_exists() {
39-
command -v "$1" &> /dev/null 2>&1
37+
command -v "$1" &> /dev/null 2>&1
4038
}
4139

42-
# Function to check if Docker && Docker Compose are installed
43-
docker_check() {
44-
if command_exists docker && docker compose version &> /dev/null; then
45-
echo "Found docker compose."
46-
COMPOSE='docker compose'
47-
elif command_exists docker-compose; then
48-
echo "Error: Found docker-compose V1. Please update to V2."
49-
echo "https://docs.docker.com/compose/migrate/"
50-
exit 1
51-
52-
else
53-
echo "Error: Docker Compose is not installed."
54-
exit 1
55-
fi
40+
# Initial Checks
41+
# Check if docker compose is installed. Fails if not found.
42+
# Check if .env file exists. Fails if not found.
43+
check_docker() {
44+
print_status "Checking that docker compose is installed..."
45+
if command_exists docker && docker compose version &> /dev/null; then
46+
print_status "Found docker compose."
47+
elif command_exists docker-compose; then
48+
print_warning "Found docker-compose V1. Please update to V2."
49+
print_warning "https://docs.docker.com/compose/migrate/"
50+
exit 1
51+
else
52+
print_error "Docker Compose is not installed."
53+
exit 1
54+
fi
5655
}
5756

58-
# Function to Source the .env file
59-
source_env() {
60-
if [ -f "${SCRIPT_DIR}/.env" ]; then
61-
source "${SCRIPT_DIR}/.env"
62-
else
63-
echo "Error: .env file not found."
57+
init() {
58+
check_docker
59+
if [ ! -f "$SCRIPT_DIR/.env" ]; then
60+
print_status "Looks like this is the first time running SocialPredict."
61+
print_warning "Please run './SocialPredict install' to initialize the application."
6462
exit 1
63+
else
64+
print_status "Loading configuration from .env file"
65+
source "$SCRIPT_DIR/.env"
6566
fi
6667
}
6768

68-
if [ "$1" = "install" ]; then
69-
# Echo initial message
70-
echo "### Building and Deploying SocialPredict ..."
71-
echo
72-
sleep 1;
73-
74-
# Check that docker is installed
75-
echo "### Checking that docker compose is installed ..."
76-
docker_check
77-
echo
78-
sleep 1;
79-
80-
# Ask user input for Application Environment
81-
echo "### Select Application Environment: "
82-
PS3='Please enter your choice: '
83-
options=("Development" "Localhost" "Production" "Quit")
84-
select opt in "${options[@]}"
85-
do
86-
case $opt in
87-
"Development")
88-
echo
89-
echo "Building for Development"
90-
echo
91-
export CALLED_FROM_SOCIALPREDICT=yes
92-
source "$SCRIPT_DIR/scripts/dev.sh"
93-
unset CALLED_FROM_SOCIALPREDICT
94-
break
95-
;;
96-
"Localhost")
97-
echo
98-
echo "Building for Localhost"
99-
echo
100-
export CALLED_FROM_SOCIALPREDICT=yes
101-
source "$SCRIPT_DIR/scripts/localhost.sh"
102-
unset CALLED_FROM_SOCIALPREDICT
103-
break
104-
;;
105-
"Production")
106-
echo
107-
echo "Building for Production"
108-
echo
109-
export CALLED_FROM_SOCIALPREDICT=yes
110-
source "$SCRIPT_DIR/scripts/prod.sh"
111-
unset CALLED_FROM_SOCIALPREDICT
112-
break
113-
;;
114-
"Quit")
115-
break
116-
;;
117-
*) echo "Invalid option $REPLY";;
118-
esac
119-
done
120-
fi
69+
print_help() {
70+
cat <<EOF
71+
Usage: ./SocialPredict COMMAND
12172
122-
# Run Docker Exec
123-
if [ "$1" = "exec" ]; then
124-
source_env
125-
export CALLED_FROM_SOCIALPREDICT=yes
126-
if [ -z "$3" ]; then
127-
source "$SCRIPT_DIR/scripts/docker-commands.sh" exec "$2"
128-
else
129-
source "$SCRIPT_DIR/scripts/docker-commands.sh" exec "$2" "$3"
130-
fi
131-
unset CALLED_FROM_SOCIALPREDICT
132-
fi
73+
Commands:
74+
install Initialize SocialPredict
75+
up Start SocialPredict containers
76+
down Stop SocialPredict containers
77+
exec Execute command on SocialPredict containers
78+
backup Backup operations on SocialPredict
13379
134-
# Run docker compose up
135-
if [ "$1" = "up" ]; then
136-
source_env
137-
export CALLED_FROM_SOCIALPREDICT=yes
138-
source "$SCRIPT_DIR/scripts/docker-commands.sh" up
139-
unset CALLED_FROM_SOCIALPREDICT
140-
fi
80+
Run './SocialPredict COMMAND --help' for more information on a command.
14181
142-
# Run docker compose down
143-
if [ "$1" = "down" ]; then
144-
source_env
145-
export CALLED_FROM_SOCIALPREDICT=yes
146-
source "$SCRIPT_DIR/scripts/docker-commands.sh" down
147-
unset CALLED_FROM_SOCIALPREDICT
148-
fi
82+
For more help on how to use SocialPredict, head to https://github.com/openpredictionmarkets/socialpredict/
83+
EOF
84+
}
14985

150-
# Database backup/restore
151-
if [ "$1" = "backup" ]; then
152-
source_env
153-
export CALLED_FROM_SOCIALPREDICT=yes
154-
shift
155-
# Pass remaining args to the backup script, e.g. --save / --list / --restore <file> / --restore-latest
156-
source "$SCRIPT_DIR/scripts/backup/db_backup.sh" "$@"
157-
unset CALLED_FROM_SOCIALPREDICT
158-
fi
86+
COMMAND="${1:-"--help"}"
87+
case "$COMMAND" in
88+
install)
89+
check_docker
90+
shift
91+
export CALLED_FROM_SOCIALPREDICT=yes
92+
source "${SCRIPT_DIR}/scripts/install.sh"
93+
unset CALLED_FROM_SOCIALPREDICT
94+
;;
95+
up)
96+
init
97+
export CALLED_FROM_SOCIALPREDICT=yes
98+
source "${SCRIPT_DIR}/scripts/docker-commands.sh" up
99+
unset CALLED_FROM_SOCIALPREDICT
100+
;;
101+
down)
102+
init
103+
export CALLED_FROM_SOCIALPREDICT=yes
104+
source "${SCRIPT_DIR}/scripts/docker-commands.sh" down
105+
unset CALLED_FROM_SOCIALPREDICT
106+
;;
107+
exec)
108+
init
109+
export CALLED_FROM_SOCIALPREDICT=yes
110+
shift
111+
source "${SCRIPT_DIR}/scripts/docker-commands.sh" exec "$@"
112+
unset CALLED_FROM_SOCIALPREDICT
113+
;;
114+
backup)
115+
init
116+
export CALLED_FROM_SOCIALPREDICT=yes
117+
shift
118+
# Pass remaining args to the backup script, e.g. --save / --list / --restore <file>
119+
source "${SCRIPT_DIR}/scripts/backup/db_backup.sh" "$@"
120+
unset CALLED_FROM_SOCIALPREDICT
121+
;;
122+
--help|-h|help)
123+
print_help
124+
;;
125+
*)
126+
echo "Unknown command: $COMMAND"
127+
echo
128+
print_help
129+
exit 1
130+
;;
131+
esac

scripts/dev.sh

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)