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

Update ontoportal docker to use docker compose of the ui and api #6

Closed
wants to merge 6 commits into from
Closed
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
53 changes: 31 additions & 22 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
BUNDLE_PATH="/srv/ontoportal/bundle"
# default bundle config resolves to /usr/local/bundle/config inside of the container
# we are setting it to local app directory if we need to use 'bundle config local'
BUNDLE_APP_CONFIG="/srv/ontoportal/.bundle"
# API/NCBO configs
REDIS_GOO_CACHE_HOST="redis-goo-cache"
REDIS_HTTP_CACHE_HOST="redis-http-cache"
REDIS_PERSISTENT_HOST="redis-persistent"
REPOSITORY_FOLDER="/srv/ontoportal/data/repository"
REPORT_PATH="/srv/ontoportal/data/reports/ontologies_report.json"
SOLR_TERM_SEARCH_URL="http://solr-term:8983/solr/term_search_core1"
SOLR_PROP_SEARCH_URL="http://solr-prop:8983/solr/prop_search_core1"
MGREP_HOST="mgrep"
MGREP_PORT="55556"
GOO_PORT=9000
GOO_HOST="4store"
##################### PERSONEL configuration ####################
ORGANIZATION_NAME=ontoportal-lirmm
COMPOSE_API_FILE_PATH=/ontologies_api/master/docker-compose.yml
COMPOSE_UI_FILE_PATH=/bioportal_web_ui/master/docker-compose.yml
ONTOLOGIES_LINKED_DATA_LINK=https://github.com/ontoportal-lirmm/ontologies_linked_data.git
SERVICE=ontoportal

# AllegroGraph related settings
AGRAPH_SUPER_USER="test"
AGRAPH_SUPER_PASSWORD="xyzzy"
##################### API configuration ####################
API_URL=http://api-service:9393
REDIS_GOO_CACHE_HOST=redis-ut
REDIS_HTTP_CACHE_HOST=redis-ut
REDIS_PERSISTENT_HOST=redis-ut

OP_APIKEY=<YOUR ONTOPORTAL API KEY>
OP_API_URL="https://data.bioontology.org"
STARTER_ONTOLOGY="STY"
##################### UI configuration ####################
RAILS_ENV=development
SITE=Ontoportal
ORG_URL=http://www.lirmm.fr
UI_URL=http://localhost:3000
API_URL=http://api-service:9393
API_KEY=72c72cba-ad45-4785-b94e-483fa55cdddb
UI_THEME=ontoportal
FAIRNESS_DISABLED=false
NCBO_ANNOTATORPLUS_ENABLED=false
[email protected]
RELEASE_VERSION="OntoPortal Appliance 3.0.1"
USE_RECAPTCHA=false

##################### KAMAL configuration ####################
IMAGE_NAME=
SERVER_IP=
DOCKER_REGISTRY_NAME=
KAMAL_REGISTRY_PASSWORD=
SSH_USER=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.env
dip.override.yml


.kamal/hooks/
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:latest

RUN apk --update --no-cache add \
bash \
curl \
docker \
docker-compose \
git

COPY ontoportal /app/ontoportal
COPY .env /app/.env
RUN chmod +x /app/ontoportal
WORKDIR /app
VOLUME /var/run/docker.sock
CMD ["/bin/sh", "-c", "/app/ontoportal start && tail -f /dev/null"]
17 changes: 17 additions & 0 deletions config/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
service: ontoportal_docker
image: ENV["IMAGE_NAME"]
servers:
- ENV["SERVER_IP"]
registry:
username:
- ENV["DOCKER_REGISTRY_NAME"]
password:
- ENV["KAMAL_REGISTRY_PASSWORD"]
ssh:
user: ENV["SSH_USER"]
run_directory: /root/app
volumes: /var/run/docker.sock:/var/run/docker.sock
traefik:
host_port: 4000
healthcheck:
cmd: /bin/true
217 changes: 217 additions & 0 deletions ontoportal
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#!/usr/bin/env bash

run_api(){

clone_ongologies_linked_data(){

if [ -d "ontologies_linked_data" ]; then
echo "[+] Directory $repo_dir already exists. Skipping cloning."
else
echo "[+] Cloning ontologies_linked_data repo... from $ONTOLOGIES_LINKED_DATA_LINK"
git clone -q --depth=1 "$ONTOLOGIES_LINKED_DATA_LINK"
fi

echo "[+] Generating Solr configsets ..."
if [ -d "ontologies_linked_data" ]; then
cd ontologies_linked_data || exit 1
if ! ./test/solr/generate_ncbo_configsets.sh; then
echo "[-] Error: Failed to generate Solr configsets."
exit 1
else
echo "[+] Success: Generating Solr configsets."
fi
cd ..
else
echo "[-] Error: directory ontologies_linked_data does not exists"
fi
}
source .env
ontologies_linked_data_link="$ONTOLOGIES_LINKED_DATA_LINK"
api_url="$API_URL"
if [ -z "$api_url" ] || [ -z "$ontologies_linked_data_link" ]; then
echo "[-] Error: Missing required configurations. Please provide both API_URL and ONTOLOGIES_LINKED_DATA_LINK in your .env file"
exit 1
fi
clone_ongologies_linked_data
bash_cmd="bundle exec rackup --host 0.0.0.0 --env=development --port 9393"
docker_run_cmd="docker compose -f docker-compose_api.yml -p ontoportal_docker run --rm -d --name api-service --service-ports api bash -c \"$bash_cmd\""
echo "[+] Starting the API"
eval "$docker_run_cmd"
}

run_ui(){
source .env
api_url="$API_URL"
api_key="$API_KEY"
if [ -z "$api_url" ] || [ -z "$api_key" ]; then
echo "[-] Error: Missing required arguments. Please provide both --api-url and --api-key or update them in your .env"
exit 1
fi
echo "[+] Starting the UI"
bash_cmd="cp /app/config/bioportal_config_env.rb.sample /app/config/bioportal_config_development.rb && cp /app/config/database.yml.sample /app/config/database.yml && (bundle check || bundle install) && bin/rails db:prepare && bundle exec rails s -b 0.0.0.0 -p 3000"
imadbourouche marked this conversation as resolved.
Show resolved Hide resolved
eval "docker compose -f docker-compose_ui.yml -p ontoportal_docker run --rm -d --name ui-service --service-ports rails bash -c \"$bash_cmd\""

}

start() {

start_api(){
echo "[+] Getting compose file for API"
echo "[+] Getting compose file from: $ORGANIZATION_NAME$COMPOSE_API_FILE_PATH"
eval "curl -sS -L https://raw.githubusercontent.com/$ORGANIZATION_NAME$COMPOSE_API_FILE_PATH -o docker-compose_api.yml"
echo "[+] Changing lines in docker-compose_api.yml"
file_path="./docker-compose_api.yml"
sed -i 's#- .:/srv/ontoportal/ontologies_api#- app_api:/srv/ontoportal/ontologies_api#' "$file_path"
sed -i 's#- bundle:/srv/ontoportal/bundle#- bundle_api:/srv/ontoportal/bundle#' "$file_path"
sed -i 's#./test/solr/configsets:/configsets:ro#./ontologies_linked_data/test/solr/configsets/:/configsets:ro#' "$file_path"
sed -i '/volumes:/,/^$/ s/bundle:/bundle_api:/' "$file_path"
sed -i '/^volumes:/a \ \ app_api:' "$file_path"

echo "[+] Running api script"
run_api
if [ $? -ne 0 ]; then
echo "[-] Error in run_api function. Exiting..."
exit 1
fi
echo "[+] The API is running successfully."
}

start_ui(){
echo "[+] Getting compose file from: $ORGANIZATION_NAME$COMPOSE_UI_FILE_PATH"
eval "curl -sS -L https://raw.githubusercontent.com/$ORGANIZATION_NAME$COMPOSE_UI_FILE_PATH -o docker-compose_ui.yml"

echo "[+] Changing lines in docker-compose_ui.yml"
file_path="./docker-compose_ui.yml"
sed -i 's/- .:\/app/- app_web:\/app/' "$file_path"
sed -i 's/retries: 3/retries: 100/' "$file_path"
sed -i '/^volumes:/a \ \ app_web:' "$file_path"

echo "[+] Running ui script"
run_ui
if [ $? -ne 0 ]; then
echo "[-] Error in run_ui function. Exiting..."
exit 1
fi

echo "[+] The UI is running successfully."
}

clean
if [ -f ".env" ]; then
echo "[+] Env file exist"
else
echo "[+] Env file does not exist"
cp .env.sample .env
fi

if [ -z "$1" ]; then
sed -i "s/^SERVICE=.*/SERVICE=ontoportal/" .env
else
sed -i "s/^SERVICE=.*/SERVICE=$1/" .env
fi

source .env
if [ "$SERVICE" == "api" ]; then
start_api
elif [ "$SERVICE" == "ui" ]; then
start_ui
else
start_api
start_ui
fi

}

stop() {
echo "[+] Stoping services"
docker container stop api-service
docker container stop ui-service
docker ps -a --format "{{.Names}}" | grep "ontoportal_docker" | awk '{print "docker stop " $1}' | sh
}

deploy(){
if [ -f ".env" ]; then
echo "[+] Env file exist"
else
echo "[+] Env file does not exist"
cp .env.sample .env
fi

if [ -z "$1" ]; then
sed -i "s/^SERVICE=.*/SERVICE=ontoportal/" .env
else
sed -i "s/^SERVICE=.*/SERVICE=$1/" .env
fi

echo "[+] Checking for env variables"
source .env
variables=("IMAGE_NAME" "SERVER_IP" "DOCKER_REGISTRY_NAME" "KAMAL_REGISTRY_PASSWORD" "SSH_USER")

for variable in "${variables[@]}"; do
if [ -z "${!variable}" ]; then
echo "[-] Error: $variable is not set."
exit
fi
done

echo "[+] Changing kamal deploy.yml file"
echo "" > config/deploy.yml
echo "service: ontoportal_docker" > config/deploy.yml
echo "image: ${IMAGE_NAME}" >> config/deploy.yml
echo -e "servers:\n - ${SERVER_IP}" >> config/deploy.yml
echo "run_directory: /root/app" >> config/deploy.yml
echo -e "registry:\n username:\n - DOCKER_REGISTRY_NAME\n password:\n - KAMAL_REGISTRY_PASSWORD" >> config/deploy.yml
echo -e "ssh:\n user: ${SSH_USER}" >> config/deploy.yml
echo "volumes: /var/run/docker.sock:/var/run/docker.sock" >> config/deploy.yml
echo -e "traefik:\n host_port: 4000" >> config/deploy.yml
echo -e "healthcheck:\n cmd: /bin/true" >> config/deploy.yml
echo "[+] Starting the deployment"
kamal setup -vv

}

clean(){
echo "[+] Cleanning the server"
rm -rf ontologies_linked_data
rm -f docker-compose*
docker container rm -f api-service ui-service 2>/dev/null
docker ps -a --format "{{.Names}}" | grep "ontoportal_docker" | awk '{print "docker rm -f " $1}' | sh
docker volume rm ontoportal_docker_rails_cache > /dev/null 2>&1
}

show_help() {
echo "Usage: $0 <command>"
echo
echo "Commands:"
echo " start : Start the ontologies API and UI (Default Mode / Personilized Mode)"
echo " deploy : Deploy the application using Kamal to the server"
echo " stop : Stop the API and UI services"
echo " clean : Clean up the server (remove ontologies_linked_data, docker-compose files, and remove all containers)"
echo " help : Show this help message"
echo
echo "Additional notes:"
echo "- You can provide your own .env file to customize parameters:"
echo " Just put the .env file in this directory and run $0 start"
}

case "$1" in
"start")
start "$2"
;;
"deploy")
deploy "$2"
;;
"stop")
stop
;;
"clean")
clean
;;
"help")
show_help
;;
*)
show_help
exit 1
;;
esac