Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced the multi-setup scripts #761

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions scripts/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
###########################################################################
## GENERAL ##

# Running through Docker: NODE_ENV=production
NODE_ENV=production

###########################################################################
## DATABASE ##

# Running through Docker: MONGO_HOST=mongodb
# Running outside Docker: MONGO_HOST=localhost
MONGO_HOST=mongodb
MONGO_DB=praise_db
MONGO_PORT=27017
MONGO_INITDB_ROOT_USERNAME=praiseDbRootUsername
MONGO_INITDB_ROOT_PASSWORD=
MONGO_USERNAME=praiseDbUsername
MONGO_PASSWORD=


###########################################################################
## HOST ##

# The fully qualified domain name for the host where you are running Praise
# For development: HOST=localhost
HOST=localhost

###########################################################################
## API ##

# Full URL to the host where the API is running.
# When running in development, the URL should also include API_PORT
API_URL=

# The API is accessed on this port. In production this port is not exposed
# externally but API is accessed on {$API_URL}/api
API_PORT=8088

# Comma separated list of ethereum addresses with admnin access to the API
ADMINS=

# API authentication
JWT_SECRET=
# expires after 1 hour of inactivity, or 3 days
JWT_ACCESS_EXP=3600
JWT_REFRESH_EXP=25920000

###########################################################################
## FRONTEND ##

# Full URL to the host (and optionally port) where frontend is being served
FRONTEND_URL=

## FRONTEND - DEVELOPMENT ONLY ##

# Full URL to host where API is running. This variable is not currently used in production.
# Why? The frontend is built as a static website and cannot easily accept
# env variables. There are workarounds but we haven't prioritised to implement them yet.
#
# ℹ️ https://jakobzanker.de/blog/inject-environment-variables-into-a-react-app-docker-on-runtime/
REACT_APP_SERVER_URL=

# Port number used when running frontend for development, outside of Docker
FRONTEND_PORT=3000

###########################################################################
## DISCORD_BOT ##

DISCORD_TOKEN=
DISCORD_CLIENT_ID=
DISCORD_GUILD_ID=

###########################################################################
## LOGGING ##

# options: error, warn, info, http, debug
LOGGER_LEVEL=warn
59 changes: 42 additions & 17 deletions scripts/multi-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ installQuestions() {
echo "Welcome to the Praise Setup!"
echo "I need to ask you a few questions before starting the setup."

# Detect public IPv4 or IPv6 address and pre-fill for the user
PUBLIC_IP=$(curl ifconfig.me)
read -rp "IPv4 or IPv6 public address: " -e -i "${PUBLIC_IP}" PUBLIC_IP

# Ask User for the Desirted Domain Name for the Praise Bot Server
HOST=""
read -rp "What would you like the Praise Bot Domain Name to be? " -e -i "${HOST}" HOST
Expand Down Expand Up @@ -50,7 +46,7 @@ configure_praise () {
## GENERAL ##

# Running through Docker: NODE_ENV=production
NODE_ENV=$PRAISE_ENV
NODE_ENV=$NODE_ENV

###########################################################################
## DATABASE ##
Expand Down Expand Up @@ -78,7 +74,7 @@ HOST=$HOST

# Full URL to the host where the API is running.
# When running in development, the URL should also include API_PORT
API_URL=https://$HOST
API_URL=http://$HOST

# The API is accessed on this port. In production this port is not exposed
# externally but API is accessed on {$API_URL}/api
Expand All @@ -97,7 +93,7 @@ JWT_REFRESH_EXP=25920000
## FRONTEND ##

# Full URL to the host (and optionally port) where frontend is being served
FRONTEND_URL=https://$HOST
FRONTEND_URL=http://$HOST

## FRONTEND - DEVELOPMENT ONLY ##

Expand All @@ -106,7 +102,7 @@ FRONTEND_URL=https://$HOST
# env variables. There are workarounds but we haven't prioritised to implement them yet.
#
# https://jakobzanker.de/blog/inject-environment-variables-into-a-react-app-docker-on-runtime/
REACT_APP_SERVER_URL=https://$HOST
REACT_APP_SERVER_URL=http://$HOST

# Port number used when running frontend for development, outside of Docker
FRONTEND_PORT=$FRONTEND_PORT
Expand Down Expand Up @@ -135,12 +131,12 @@ praise_env () {
read -rp "Confirm Praise env? [1/2]: " -e -i "1" env
done
if [[ "$env" =~ ^[1]$ ]]; then
export PRAISE_ENV=production
echo $PRAISE_ENV
export NODE_ENV=production
echo $NODE_ENV
sleep 1
elif [[ "$env" =~ ^[2]$ ]]; then
export PRAISE_ENV=development
echo $PRAISE_ENV
export NODE_ENV=development
echo $NODE_ENV
sleep 1
else
echo "Invalid Option, Praise Setup Aborted"
Expand All @@ -161,11 +157,40 @@ configure_compose () {
sed -i "s/container_name: .*frontend-praise/container_name: ${HOST}-frontend-praise/" $PRAISE_HOME/docker-compose.multi.yml
}

extract_conf () {
export $(grep -v '^#' $PRAISE_HOME/.env | xargs)
echo
# Ask User for the Desirted Domain Name for the Praise Bot Server
HOST=$HOST
read -rp "What would you like the Praise Bot Domain Name to be? " -e -i "${HOST}" HOST
# Ask the user for the DISCORD TOKEN
DISCORD_TOKEN=$DISCORD_TOKEN
read -rp "What is your Discord Token? " -e -i "${DISCORD_TOKEN}" DISCORD_TOKEN
# Ask the user for the DISCORD CLIENT ID
DISCORD_CLIENT_ID=$DISCORD_CLIENT_ID
read -rp "What is your Discord Client ID? " -e -i "${DISCORD_CLIENT_ID}" DISCORD_CLIENT_ID
# Ask the user for the DISCORD GUILD ID
DISCORD_GUILD_ID=$DISCORD_GUILD_ID
read -rp "What is your Discord Guild ID? " -e -i "${DISCORD_GUILD_ID}" DISCORD_GUILD_ID
# Ask the user for the ADMINS wallet Address
ADMINS=$ADMINS
read -rp "What will your praise bot server admin wallet address be (Please insert the addresses separated by comma)? " -e -i "${ADMINS}" ADMINS
echo
echo "Okay, that was all I needed. Praise will be configured using the inputted values"
read -n1 -r -p "Press any key to continue..."
}

main () {
praise_env
installQuestions
configure_compose
configure_praise
if [ -f "$PRAISE_HOME/.env" ]; then
echo "ENV Exists"
extract_conf
configure_praise
else
praise_env
installQuestions
configure_compose
configure_praise
fi
}

main
main
17 changes: 6 additions & 11 deletions scripts/setup-new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ installQuestions() {

echo "Welcome to the Praise Setup!"
echo "I need to ask you a few questions before starting the setup."

# Detect public IPv4 or IPv6 address and pre-fill for the user
PUBLIC_IP=$(curl ifconfig.me)
read -rp "IPv4 or IPv6 public address: " -e -i "${PUBLIC_IP}" PUBLIC_IP

# Ask User for the Desirted Domain Name for the Praise Bot Server
HOST=""
read -rp "What would you like the Praise Bot Domain Name to be? " -e -i "${HOST}" HOST
Expand Down Expand Up @@ -50,7 +45,7 @@ configure_praise () {
## GENERAL ##

# Running through Docker: NODE_ENV=production
NODE_ENV=$PRAISE_ENV
NODE_ENV=$NODE_ENV

###########################################################################
## DATABASE ##
Expand Down Expand Up @@ -135,12 +130,12 @@ praise_env () {
read -rp "Confirm Praise env? [1/2]: " -e -i "1" env
done
if [[ "$env" =~ ^[1]$ ]]; then
export PRAISE_ENV=production
echo $PRAISE_ENV
export NODE_ENV=production
echo $NODE_ENV
sleep 1
elif [[ "$env" =~ ^[2]$ ]]; then
export PRAISE_ENV=development
echo $PRAISE_ENV
export NODE_ENV=development
echo $NODE_ENV
sleep 1
else
echo "Invalid Option, Praise Setup Aborted"
Expand All @@ -155,4 +150,4 @@ main () {
configure_praise
}

main
main
9 changes: 0 additions & 9 deletions scripts/setup.sh

This file was deleted.