Skip to content

Commit

Permalink
add bash scripts to run and stop an ontoportal api using docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Nov 16, 2023
1 parent 42734cf commit 5140fe5
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 127 deletions.
158 changes: 31 additions & 127 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,137 +1,41 @@
# Default values are optimized for production to avoid having to configure
# much in production.
#
# However it should be easy to get going in development too. If you see an
# uncommented option that means it's either mandatory to set or it's being
# overwritten in development to make your life easier.
##################### UI configuration ####################
SITE=Testportal
ORG=LIRMM
ORG_URL=http://www.lirmm.fr

# Enable BuildKit by default:
# https://docs.docker.com/develop/develop-images/build_enhancements
export DOCKER_BUILDKIT=1
UI_URL=http://localhost:3000
API_URL=http://localhost:9393
API_KEY=

# Rather than use the directory name, let's control the name of the project.
export COMPOSE_PROJECT_NAME=ontoportal-docker
BIOMIXER_URL=
BIOMIXER_APIKEY=

# In development we want all services to start but in production you don't
# need the asset watchers to run since assets get built into the image.
#
# You can even choose not to run postgres and redis in prod if you plan to use
# managed cloud services. Everything "just works", even optional depends_on!
#export COMPOSE_PROFILES=postgres,redis,web,worker,cable
export COMPOSE_PROFILES=db,cache,assets,web
ANNOTATOR_URL=

# If you're running native Linux and your uid:gid isn't 1000:1000 you can set
# these to match your values before you build your image. You can check what
# your uid:gid is by running `id` from your terminal.
#export UID=1000
#export GID=1000
FAIRNESS_DISABLED=false
FAIRNESS_URL=

# You can generate a more secure secret by running: ./run rails secret
export SECRET_KEY_BASE=insecure_key_for_dev
NCBO_ANNOTATORPLUS_ENABLED=false
NCBO_ANNOTATOR_URL=
NCBO_API_KEY=

# Which environment is running? These should be "development" or "production".
#export RAILS_ENV=production
#export NODE_ENV=production
export RAILS_ENV=development
export NODE_ENV=development
SUPPORT_EMAIL=[email protected]
UI_THEME=stageportal
RELEASE_VERSION="OntoPortal Appliance 3.0.1"

# The bind port for puma.
#
# Be warned that if you change this value you'll need to change 8000 in both
# your Dockerfile and in a few spots in docker-compose.yml due to the nature of
# how this value can be set (Docker Compose doesn't support nested ENV vars).
#export PORT=8000
ANALYTICS_ID=
USE_RECAPTCHA=false
#################### Buidling the API for running tests ####################
## An ontology that will be imported in the starting of the API server
STARTER_ONTOLOGY=STY
## API key of a remote API used to download the starter ontology
OP_API_KEY=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
## API url of the remote API used to download the starter ontology
OP_API_URL="https://data.bioontology.org"

# How many workers and threads should your app use? WEB_CONCURRENCY defaults
# to the server's CPU count * 2. That is a good starting point. In development
# it's a good idea to use 1 to avoid race conditions when debugging.
#export WEB_CONCURRENCY=
#export RAILS_MAX_THREADS=5
#export WEB_CONCURRENCY=1
#export RAILS_MAX_THREADS=1
## Image repositroy from which the ontoportal api will be built
API_IMAGE_REPOSITORY=agroportal
## Image tag/version from which the ontoportal api will be built
API_IMAGE_TAG=stage

# You'll always want to set POSTGRES_USER and POSTGRES_PASSWORD since the
# postgres Docker image uses them for its default database user and password.
export POSTGRES_USER=hello
export POSTGRES_PASSWORD=password
#export POSTGRES_DB=hello
#export POSTGRES_HOST=postgres
#export POSTGRES_PORT=5432

# What's your full Redis connection URL? This will be used for caching, Sidekiq,
# and Action Cable. You can always split them up later.
#export REDIS_URL=redis://redis:6379/1

# The bind port for puma but for Action Cable.
#
# Be warned that if you change this value you'll need to change 28080 in a few
# spots in docker-compose.yml due to the nature of how this value can be set
# (Docker Compose doesn't support nested ENV vars).
#export CABLE_PORT=28080

# The Action Cable address that will be accessible over HTTP. In production
# you would typically have this reverse proxied to a sub-domain with nginx, in
# which case you would set something like: ws://cable.example.com
#
# This is one case where it defaults to a development value because it's not
# possible for me to know what domain name you'll be using.
#export ACTION_CABLE_FRONTEND_URL=ws://localhost:28080

# Comma separated list of RegExp origins to allow connections from for Action
# Cable. The values will be converted into a proper RegExp, so omit the / /.
#
# Examples:
# http:\/\/localhost*
# http:\/\/example.*,https:\/\/example.*
#export ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=http:\/\/localhost*

# If this is set then Rails will serve files from public/ in production. You
# probably don't want this behavior unless you're testing prod mode locally,
# because nginx would typically serve static files.
#export RAILS_SERVE_STATIC_FILES=

# Should Docker restart your containers if they go down in unexpected ways?
#export DOCKER_RESTART_POLICY=unless-stopped
export DOCKER_RESTART_POLICY=no

# What health check test command do you want to run? In development, having it
# curl your web server will result in a lot of log spam, so setting it to
# /bin/true is an easy way to make the health check do basically nothing.
#export DOCKER_WEB_HEALTHCHECK_TEST=curl localhost:8000/up
export DOCKER_WEB_HEALTHCHECK_TEST=/bin/true

# What ip:port should be published back to the Docker host for the app server?
# If you're using Docker Toolbox or a custom VM you can't use 127.0.0.1. This
# is being overwritten in dev to be compatible with more dev environments.
#
# If you have a port conflict because something else is using 8000 then you
# can either stop that process or change 8000 to be something else.
#
# Use the default in production to avoid having puma directly accessible to
# the internet since it'll very likely be behind nginx or a load balancer.
#export DOCKER_WEB_PORT_FORWARD=127.0.0.1:8000
export DOCKER_WEB_PORT_FORWARD=127.0.0.1:3000

# This is the same as above except for Action Cable.
#export DOCKER_CABLE_PORT_FORWARD=127.0.0.1:28080
export DOCKER_CABLE_PORT_FORWARD=28080

# What volume path should be used? In dev we want to volume mount everything
# so that we can develop our code without rebuilding our Docker images.
#export DOCKER_WEB_VOLUME=./public:/app/public


export DOCKER_WEB_VOLUME=.:/app

# What CPU and memory constraints will be added to your services? When left at
# 0 they will happily use as much as needed.
# export DOCKER_POSTGRES_CPUS=0
# export DOCKER_POSTGRES_MEMORY=0
# export DOCKER_REDIS_CPUS=0
# export DOCKER_REDIS_MEMORY=0
# export DOCKER_WEB_CPUS=0
# export DOCKER_WEB_MEMORY=0
# export DOCKER_WORKER_CPUS=0
# export DOCKER_WORKER_MEMORY=0
# export DOCKER_CABLE_CPUS=0
# export DOCKER_CABLE_MEMORY=0
69 changes: 69 additions & 0 deletions bin/run_api
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
display_help() {
echo "Usage: $0 [options]"
echo "Options:"
echo " -f Remove tmp/ontoportal_docker"
echo " -k API_KEY API key"
echo " -r REPOSITORY Image repository"
echo " -t TAG Image tag"
echo " -s ONTOLOGY Starter ontology"
echo " -u URL Remote API URL"
echo " -h Display this help message"
exit 0
}


env_file_path="$(realpath "$(dirname "$0")")/../.env"

# Read and parse the .env file
if [ -f "$env_file_path" ]; then
while IFS='=' read -r key value; do
[[ "$key" =~ ^\s*# ]] && continue # Skip commented lines
[[ "$value" ]] || continue # Skip lines without values
export "$key"="$value"
done < "$env_file_path"
fi


while getopts ":k:r:t:s:u:fh" opt; do
case $opt in
k) api_key="$OPTARG" ;;
r) image_repository="$OPTARG" ;;
t) image_tag="$OPTARG" ;;
s) starter_ontology="$OPTARG" ;;
u) remote_api_url="$OPTARG" ;;
f) rm -fr tmp/ontoportal_docker ;;
h) display_help ;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
esac
done



if [ ! -d "tmp/ontoportal_docker" ]; then
git clone --depth=1 https://github.com/syphax-bouazzouni/ontoportal_docker.git tmp/ontoportal_docker
fi

# If an option is not provided, check and use the corresponding value from the environment variables
api_key="${api_key:-$OP_API_KEY}"
image_repository="${image_repository:-$API_IMAGE_REPOSITORY}"
image_tag="${image_tag:-$API_IMAGE_TAG}"
starter_ontology="${starter_ontology:-$STARTER_ONTOLOGY}"
remote_api_url="${remote_api_url:-$OP_API_URL}"

if curl -sSf http://localhost:9393 > /dev/null 2>&1; then
echo "API is already running in http://localhost:9393"
exit 0
fi

# Check if the Docker Compose service exists
docker compose ls -a --filter "name=ontoportal_docker" | grep -q "ontoportal_docker" && no_provision=true || no_provision=false
(
cd tmp/ontoportal_docker || exit 1
command="./run -k $api_key -r $image_repository -t $image_tag -s $starter_ontology -u $remote_api_url"
[ "$no_provision" = true ] && command="$command --no-provision"
echo "Run: $command"
eval "$command"
)

13 changes: 13 additions & 0 deletions bin/stop_api
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Check if the directory exists
if [ -d "tmp/ontoportal_docker" ]; then
# Check if the container is running
if docker ps --filter "name=ontoportal_docker-api" --format "{{.Names}}" | grep -q "ontoportal_docker-api"; then
container_names=$(docker ps --filter "name=ontoportal_docker-api" --format "{{.Names}}")
docker stop "$container_names"
fi

cd "tmp/ontoportal_docker" && docker compose stop
fi

0 comments on commit 5140fe5

Please sign in to comment.