Skip to content
Open
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
19 changes: 1 addition & 18 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CLUSTERED_MODE=false
VERSION=v0.0.1

# Log

DEBUG=1
BASHLOG_FILE=1
BASHLOG_FILE_PATH=platform.log
Expand All @@ -12,20 +11,4 @@ BASHLOG_FILE_PATH=platform.log
OPENHIM_CORE_INSTANCES=1
OPENHIM_CONSOLE_INSTANCES=1
OPENHIM_MEDIATOR_API_PORT=443
MONGO_SET_COUNT=1
OPENHIM_MONGO_URL=mongodb://mongo-1:27017/openhim
OPENHIM_MONGO_ATNAURL=mongodb://mongo-1:27017/openhim

# iSantePlus and MySQL
MYSQL_ROOT_PASSWORD=change_for_prod!
MYSQL_USE_LOCAL=false
OMRS_CONFIG_CONNECTION_USERNAME_1=openmrs
OMRS_CONFIG_CONNECTION_PASSWORD_1=change_for_prod!
OMRS_CONFIG_CONNECTION_URL_1=jdbc:mysql://mysql:3306/openmrs?autoReconnect=true

# Reverse Proxy
DOMAIN_NAME=localhost
SUBDOMAINS=
STAGING=true
INSECURE=true
INSECURE_PORTS=5001:5001-80:80-8080:8080-5601:5601-5488:5488-3000:3000-9200:9200-8089:8089-9001:9001-3033:3033-50000:50000
MONGO_SET_COUNT=1
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ isante-backup

dist

.tmp
.tmp

*-bkp*
38 changes: 33 additions & 5 deletions build-custom-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if [ ! -d "/var/lib/openmrs-volume/openmrs-data" ]; then
chmod +w /var/lib/openmrs-volume/openmrs-data
fi

if [ ! -d "/var/lib/certs/letscencrypt" ]; then
mkdir -p /var/lib/certs/letscencrypt
chmod +w /var/lib/certs/letscencrypt
fi

##
# iSantePlus DB
##
Expand All @@ -27,12 +32,19 @@ while IFS= read -r line; do
done <<< "$envs"

# Build the Docker image
docker build -t isanteplus-mysql:5.7.44 ./projects/isanteplus-db
docker build -t isanteplus-mysql:local ./projects/isanteplus-db
docker build -t isanteplus-mysql:legacy ./projects/isanteplus-db -f ./projects/isanteplus-db/legacy.Dockerfile
docker build -t isanteplus-mysql:2.8.4 ./projects/isanteplus-db -f ./projects/isanteplus-db/legacy.Dockerfile

##
# iSantePlus Application
##

## Modules

# Lab Integration Module


# Load Env vars from json file environmentVariables field
filepath="./packages/emr-isanteplus/package-metadata.json"
envs=$(jq -r '.environmentVariables | to_entries | .[] | "\(.key)=\(.value)"' $filepath)
Expand All @@ -42,13 +54,29 @@ while IFS= read -r line; do
export "$line"
done <<< "$envs"

docker compose \
-f packages/emr-isanteplus/docker-compose.yml \
build
docker build -t itechuw/docker-isanteplus-server:local ./projects/emr-isanteplus -f ./projects/emr-isanteplus/Dockerfile
# docker build -t itechuw/docker-isanteplus-server:legacy ./projects/emr-isanteplus -f ./projects/emr-isanteplus/legacy.Dockerfile
# docker build -t itechuw/docker-isanteplus-server:2.8.4 ./projects/emr-isanteplus -f ./projects/emr-isanteplus/2_8_4.Dockerfile

##
# Cert Maintenance
##
# Load Env vars from json file environmentVariables field
filepath="./packages/reverse-proxy-nginx/package-metadata.json"

envs=$(jq -r '.environmentVariables | to_entries | .[] | "\(.key)=\(.value)"' $filepath)

# Export each environment variable
while IFS= read -r line; do
export "$line"
done <<< "$envs"

# Build the Docker image
docker build -t cert-maintenance:local ./projects/cert-maintenance

## Build the Platform to contain the above custom builds
##
# Build the Platform to contain the above custom builds
##
./build-image.sh

echo "You can run the the Platform commands: E.g: ./instant-linux package init -p dev"
220 changes: 220 additions & 0 deletions initial-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#!/usr/bin/env bash
#
# init_config.sh
#

# This script will:
# 1. Prompt for secrets (always asks user) and store them securely in the Linux keychain.
# 2. Prompt for non-sensitive env vars (always asks user) with hardcoded defaults in the script.
# 3. Copy ".env.local" to ".env" and append environment variables from user input.
#
# Usage: ./init_config.sh
#

##
# Update / Install Required Packages
##
sudo apt-get update
sudo apt-get install git secret-tool

##
# Install / Update Docker
##
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

# Create keychain secrets for:
# - MySQL user password
# - MySQL root password
# - OpenHIM root passwor



# ---- Helper Functions ----

# Prompt for secret with an optional label for storing in keychain.
# No default is used here (or you can define one if you like).
ask_secret() {
local var_name="$1"
local prompt_msg="$2"
local label="$3" # For keychain (secret-tool)
local service="$4" # For keychain (secret-tool)
local user="$5" # For keychain (secret-tool)

echo
echo "=== $prompt_msg ==="
# '-s' makes read silent (no echo back). Remove -s if you want to show typed characters.
read -s -p "Enter $prompt_msg: " secret_val
echo

# Store in keychain if user entered something
if [ -n "$secret_val" ]; then
echo "Storing $prompt_msg in keychain..."
secret-tool store --label="$label" service="$service" user="$user" <<< "$secret_val"
echo "$prompt_msg stored in keychain."
else
echo "No input for $prompt_msg. Nothing was stored."
fi

# Export to a shell variable if needed for immediate usage (optional)
eval "$var_name=\"$secret_val\""
}

# Prompt for an env var with a hardcoded default.
ask_env_with_default() {
local var_name="$1"
local prompt_msg="$2"
local default_val="$3"

echo
echo "=== $prompt_msg ==="
read -p "Enter value (default: $default_val): " user_input
# If user presses Enter (no input), use the default
if [ -z "$user_input" ]; then
user_input="$default_val"
fi

# Export the final chosen value into a shell variable
eval "$var_name=\"$user_input\""
}

# ---- 1) Collect Secrets Securely ----

echo "=== Step 1: Gather secrets for storage in the Linux keychain ==="
echo "You will be prompted for each secret (no defaults). Press Enter to skip a secret if not needed."

# Example secret #1: OpenHIM admin password
ask_secret OPENHIM_ADMIN_PASSWORD \
"OpenHIM Admin Password" \
"OpenHIM Admin Password" \
"openhim" \
"admin"

# Example secret #2: MySQL root password
ask_secret MYSQL_ROOT_PASSWORD \
"MySQL Root Password" \
"MySQL Root Password" \
"mysql" \
"root"

# Add more secrets if needed...

# ---- 2) Gather Non-Sensitive ENV Variables (Hardcoded Defaults) ----

echo
echo "=== Step 2: Configure non-sensitive environment variables ==="
echo "You will be prompted for each variable with a default. Press Enter to accept the default."

ask_env_with_default OPENHIM_CORE_MEDIATOR_HOSTNAME \
"OPENHIM_CORE_MEDIATOR_HOSTNAME" \
"openhimcomms.isanteplus.uwdigi.org"

ask_env_with_default OPENHIM_MEDIATOR_API_PORT \
"OPENHIM_MEDIATOR_API_PORT" \
"8899"

ask_env_with_default OPENHIM_CORE_MEDIATOR_HOSTNAME_2 \
"OPENHIM_CORE_MEDIATOR_HOSTNAME_2 (2nd var, if needed)" \
"isanteplus.uwdigi.org"

ask_env_with_default OPENHIM_MONGO_URL \
"OPENHIM_MONGO_URL" \
"mongodb://mongo-1:27017/openhim"

ask_env_with_default OPENHIM_MONGO_ATNAURL \
"OPENHIM_MONGO_ATNAURL" \
"mongodb://mongo-1:27017/openhim"

ask_env_with_default OPENHIM_CONSOLE_BASE_URL \
"OPENHIM_CONSOLE_BASE_URL" \
"https://openhimconsole.isanteplus.uwdigi.org"

ask_env_with_default OPENHIM_CONSOLE_SHOW_LOGIN \
"OPENHIM_CONSOLE_SHOW_LOGIN" \
"true"

ask_env_with_default MYSQL_USE_LOCAL \
"MYSQL_USE_LOCAL" \
"false"

ask_env_with_default OMRS_CONFIG_CONNECTION_USERNAME_1 \
"OMRS_CONFIG_CONNECTION_USERNAME_1" \
"openmrs"

ask_env_with_default OMRS_CONFIG_CONNECTION_URL_1 \
"OMRS_CONFIG_CONNECTION_URL_1" \
"jdbc:mysql://mysql:3306/openmrs?autoReconnect=true"

ask_env_with_default OMRS_CONFIG_CONNECTION_USERNAME_2 \
"OMRS_CONFIG_CONNECTION_USERNAME_2" \
"openmrs2"

ask_env_with_default OMRS_CONFIG_CONNECTION_URL_2 \
"OMRS_CONFIG_CONNECTION_URL_2" \
"jdbc:mysql://mysql:3306/openmrs2?autoReconnect=true"

ask_env_with_default DOMAIN_NAME \
"DOMAIN_NAME" \
"isanteplus.uwdigi.org"

ask_env_with_default SUBDOMAINS \
"SUBDOMAINS" \
"pestel.isanteplus.uwdigi.org,charess.isanteplus.uwdigi.org,openhim.isanteplus.uwdigi.org,openhimcomms.isanteplus.uwdigi.org,openhimcore.isanteplus.uwdigi.org,legacy.isanteplus.uwdigi.org"

ask_env_with_default STAGING \
"STAGING" \
"false"

ask_env_with_default INSECURE \
"INSECURE" \
"false"

# ---- 3) Generate the .env File ----

echo
echo "=== Step 3: Create .env from .env.local and append environment variables ==="

if [ ! -f .env.local ]; then
echo "ERROR: .env.local does not exist in the current directory!"
exit 1
fi

cp .env.local .env

# Append the user-provided environment variables
{
echo "OPENHIM_CORE_MEDIATOR_HOSTNAME=$OPENHIM_CORE_MEDIATOR_HOSTNAME"
echo "OPENHIM_MEDIATOR_API_PORT=$OPENHIM_MEDIATOR_API_PORT"
echo "OPENHIM_CORE_MEDIATOR_HOSTNAME_2=$OPENHIM_CORE_MEDIATOR_HOSTNAME_2"
echo "OPENHIM_MONGO_URL=$OPENHIM_MONGO_URL"
echo "OPENHIM_MONGO_ATNAURL=$OPENHIM_MONGO_ATNAURL"
echo "OPENHIM_CONSOLE_BASE_URL=$OPENHIM_CONSOLE_BASE_URL"
echo "OPENHIM_CONSOLE_SHOW_LOGIN=$OPENHIM_CONSOLE_SHOW_LOGIN"
echo "MYSQL_USE_LOCAL=$MYSQL_USE_LOCAL"
echo "OMRS_CONFIG_CONNECTION_USERNAME_1=$OMRS_CONFIG_CONNECTION_USERNAME_1"
echo "OMRS_CONFIG_CONNECTION_URL_1=$OMRS_CONFIG_CONNECTION_URL_1"
echo "OMRS_CONFIG_CONNECTION_USERNAME_2=$OMRS_CONFIG_CONNECTION_USERNAME_2"
echo "OMRS_CONFIG_CONNECTION_URL_2=$OMRS_CONFIG_CONNECTION_URL_2"
echo "DOMAIN_NAME=$DOMAIN_NAME"
echo "SUBDOMAINS=$SUBDOMAINS"
echo "STAGING=$STAGING"
echo "INSECURE=$INSECURE"
} >> .env

echo
echo "=== Initialization Complete! ==="
echo "Secrets have been stored in your keychain (if you provided any)."
echo "A new .env file has been created with your chosen values."
Loading