forked from ncbo/ontoportal_docker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use native bash script instead of dip for people that do not have ruby
- Loading branch information
1 parent
c141c7f
commit 2de8736
Showing
3 changed files
with
105 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ GEM | |
|
||
PLATFORMS | ||
x86_64-darwin-23 | ||
x86_64-linux-musl | ||
|
||
DEPENDENCIES | ||
dip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
name: ontoportal | ||
|
||
x-app: &api | ||
stdin_open: true | ||
tty: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,129 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'optparse' | ||
#!/usr/bin/env bash | ||
|
||
# Default values | ||
options = { | ||
api_key: nil, | ||
api_url: 'https://data.bioontology.org', | ||
starter_ontology: 'STY' | ||
} | ||
|
||
# OptionParser configuration | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: #{$PROGRAM_NAME} -k API_KEY -u API_URL -s STARTER_ONTOLOGY" | ||
|
||
opts.on("-k", "--api-key API_KEY", "Your Ontoportal API key") do |api_key| | ||
options[:api_key] = api_key | ||
end | ||
|
||
opts.on("-u", "--api-url API_URL", "Ontoportal API URL (default: https://data.bioontology.org)") do |api_url| | ||
options[:api_url] = api_url | ||
end | ||
|
||
opts.on("-r", "--docker-hub-repository DOCKER_HUB_REPOSITORY", "Ontoportal API image repository (default: bioportal)") do |image_repository| | ||
options[:image_repository] = image_repository || 'bioportal' | ||
end | ||
|
||
opts.on("-t", "--image-tag DOCKER_IMAGE_TAG", "Ontoportal API image version (default: latest)") do |image_tag| | ||
options[:image_tag] = image_tag || 'latest' | ||
end | ||
|
||
|
||
opts.on("-s", "--starter-ontology [STARTER_ONTOLOGY]", "Starter ontology code (default: STY)") do |starter_ontology| | ||
options[:starter_ontology] = starter_ontology || 'STY' | ||
end | ||
|
||
opts.on_tail("-h", "--help", "Show this message") do | ||
puts opts | ||
exit | ||
end | ||
end.parse! | ||
API_URL="https://data.bioontology.org" | ||
STARTER_ONTOLOGY="STY" | ||
IMAGE_REPOSITORY="bioportal" | ||
IMAGE_TAG="latest" | ||
|
||
# Parse command line options | ||
while getopts ":k:u:r:t:s:" opt; do | ||
case $opt in | ||
k) API_KEY="$OPTARG";; | ||
u) API_URL="$OPTARG";; | ||
r) IMAGE_REPOSITORY="$OPTARG";; | ||
t) IMAGE_TAG="$OPTARG";; | ||
s) STARTER_ONTOLOGY="$OPTARG";; | ||
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;; | ||
:) echo "Option -$OPTARG requires an argument." >&2; exit 1;; | ||
esac | ||
done | ||
|
||
# Check if required arguments are provided | ||
unless options[:api_key] | ||
puts "Error: Missing required arguments. Please provide API_KEY." | ||
puts "See help using -h, --help" | ||
exit 1 | ||
end | ||
if [ -z "$API_KEY" ]; then | ||
echo "Error: Missing required argument. Please provide API_KEY." | ||
echo "See help using -h, --help" | ||
exit 1 | ||
fi | ||
|
||
echo "Running the Ontoportal API and CRON Setup..." | ||
|
||
puts "Running the Ontoportal API and CRON Setup..." | ||
|
||
# Step 1: Clone ontologies_linked_data repo | ||
puts "Cloning ontologies_linked_data repo..." | ||
system("git clone --depth=1 https://github.com/ontoportal-lirmm/ontologies_linked_data.git") | ||
echo "Cloning ontologies_linked_data repo..." | ||
git clone --depth=1 https://github.com/ontoportal-lirmm/ontologies_linked_data.git | ||
|
||
# Step 2: Generate configsets | ||
puts "Generating Solr configsets..." | ||
Dir.chdir("ontologies_linked_data") do | ||
unless system("./test/solr/generate_ncbo_configsets.sh") | ||
puts "Error: Failed to generate Solr configsets." | ||
exit 1 | ||
end | ||
end | ||
echo "Generating Solr configsets..." | ||
cd ontologies_linked_data || exit 1 | ||
if ! ./test/solr/generate_ncbo_configsets.sh; then | ||
echo "Error: Failed to generate Solr configsets." | ||
exit 1 | ||
fi | ||
|
||
puts "Navigating to ontoportal_docker directory..." | ||
Dir.chdir("../ontoportal_docker") || exit(1) | ||
echo "Navigating to ontoportal_docker directory..." | ||
cd .. || exit 1 | ||
|
||
# Step 4: Install DIP | ||
puts "Installing DIP (Docker in Production) dependencies..." | ||
unless system("bundle install") | ||
puts "Error: Failed to install DIP dependencies." | ||
exit 1 | ||
end | ||
echo "Installing DIP (Docker in Production) dependencies..." | ||
if ! bundle install; then | ||
echo "Error: Failed to install DIP dependencies." | ||
exit 1 | ||
fi | ||
|
||
# Copy .env.sample to .env | ||
unless system("cp .env.sample .env") | ||
puts "Error: Failed to copy .env.sample to .env." | ||
exit 1 | ||
end | ||
# Copy .env.sample to .env | ||
if ! cp .env.sample .env; then | ||
echo "Error: Failed to copy .env.sample to .env." | ||
exit 1 | ||
fi | ||
|
||
env_file_path = './.env' | ||
# Read the content of .env file | ||
begin | ||
env_content = File.read(env_file_path) | ||
rescue StandardError => e | ||
puts "Error: Failed to read .env file. #{e.message}" | ||
exit 1 | ||
end | ||
env_file_path="./.env" | ||
|
||
# Step 5: Export bioportal APIKEY, update OP_APIKEY and OP_API_URL in .env file | ||
puts "Exporting bioportal APIKEY..." | ||
env_content.gsub!(/OP_APIKEY=<YOUR ONTOPORTAL API KEY>/, "OP_APIKEY=#{options[:api_key]}") | ||
# Read the content of .env file | ||
env_content=$(<"$env_file_path") | ||
|
||
# Step 6: Update OP_API_URL in .env file with provided API_URL argument | ||
puts "Updating OP_API_URL in .env file..." | ||
env_content.gsub!(/OP_API_URL="https:\/\/data.bioontology.org"/, "OP_API_URL=#{options[:api_url]}") | ||
# Export bioportal APIKEY, update OP_APIKEY and OP_API_URL in .env file | ||
echo "Exporting bioportal APIKEY..." | ||
env_content="${env_content//OP_APIKEY=<YOUR ONTOPORTAL API KEY>/OP_APIKEY=$API_KEY}" | ||
|
||
# Step 7: Update STARTER_ONTOLOGY in .env file with provided STARTER_ONTOLOGY argument | ||
puts "Updating STARTER_ONTOLOGY in .env file..." | ||
env_content.gsub!(/STARTER_ONTOLOGY="STY"/, "STARTER_ONTOLOGY=#{options[:starter_ontology]}") | ||
# Update OP_API_URL in .env file with provided API_URL argument | ||
echo "Updating OP_API_URL in .env file..." | ||
env_content="${env_content//OP_API_URL=\"https:\/\/data.bioontology.org\"/OP_API_URL=$API_URL}" | ||
|
||
# Step 7: Update IMAGE_REPOSITORY in .env file with provided IMAGE_REPOSITORY argument | ||
puts "Updating IMAGE_REPOSITORY in .env file..." | ||
env_content.gsub!(/IMAGE_REPOSITORY=bioportal/, "IMAGE_REPOSITORY=#{options[:image_repository]}") | ||
# Update STARTER_ONTOLOGY in .env file with provided STARTER_ONTOLOGY argument | ||
echo "Updating STARTER_ONTOLOGY in .env file..." | ||
env_content="${env_content//STARTER_ONTOLOGY=\"STY\"/STARTER_ONTOLOGY=$STARTER_ONTOLOGY}" | ||
|
||
# Update IMAGE_REPOSITORY in .env file with provided IMAGE_REPOSITORY argument | ||
echo "Updating IMAGE_REPOSITORY in .env file..." | ||
env_content="${env_content//IMAGE_REPOSITORY=bioportal/IMAGE_REPOSITORY=$IMAGE_REPOSITORY}" | ||
|
||
# Step 7: Update IMAGE_TAG in .env file with provided IMAGE_TAG argument | ||
puts "Updating IMAGE_TAG in .env file..." | ||
env_content.gsub!(/IMAGE_TAG=latest/, "IMAGE_TAG=#{options[:image_tag]}") | ||
# Update IMAGE_TAG in .env file with provided IMAGE_TAG argument | ||
echo "Updating IMAGE_TAG in .env file..." | ||
env_content="${env_content//IMAGE_TAG=latest/IMAGE_TAG=$IMAGE_TAG}" | ||
|
||
# Write the modified content back to the .env file | ||
begin | ||
File.write(env_file_path, env_content) | ||
rescue StandardError => e | ||
puts "Error: Failed to write to .env file. #{e.message}" | ||
exit 1 | ||
end | ||
echo "$env_content" > "$env_file_path" | ||
|
||
# Step 8: Run provisioning via dip | ||
puts "Running provisioning via DIP..." | ||
unless system("dip provision") | ||
puts "Error: Failed to run provisioning via DIP." | ||
exit 1 | ||
end | ||
|
||
puts "Setup completed successfully!" | ||
echo "Running provisioning via DIP..." | ||
commands=( | ||
'docker compose down --volumes > /dev/null 2>&1' | ||
'docker compose run --rm 4store bash -c "4s-backend-setup ontoportal_kb" > /dev/null 2>&1 ' | ||
'docker compose run --rm ncbo_cron bundle exec rake user:create[admin,[email protected]] > /dev/null 2>&1' | ||
"docker compose run --rm ncbo_cron bundle exec 'bin/ncbo_ontology_import --admin-user admin --ontologies $STARTER_ONTOLOGY --from-apikey $API_KEY --from $API_URL' > /dev/null 2>&1 " | ||
"docker compose run --rm ncbo_cron bundle exec 'bin/ncbo_ontology_pull -o $STARTER_ONTOLOGY' > /dev/null 2>&1 " | ||
"docker compose run --rm ncbo_cron bundle exec 'bin/ncbo_ontology_process -o ${STARTER_ONTOLOGY}' > /dev/null 2>&1" | ||
) | ||
|
||
for cmd in "${commands[@]}"; do | ||
echo "Run: $cmd" | ||
if ! eval "$cmd"; then | ||
echo "Error: Failed to run provisioning via DIP. $cmd" | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "Setup completed successfully!" | ||
|
||
|
||
|
||
|
||
|
||
echo "Running api via DIP..." | ||
docker compose run --service-ports -it --rm -d api | ||
|
||
# Wait for API to be ready (adjust the sleep time accordingly) | ||
timeout=30 | ||
elapsed=0 | ||
until [ $elapsed -ge $timeout ] || curl -sSf http://localhost:9393 > /dev/null 2>&1; do | ||
echo "Waiting for the server to be up..." | ||
sleep 1 | ||
elapsed=$((elapsed + 1)) | ||
done | ||
if [ $elapsed -ge $timeout ]; then | ||
echo "Timed out waiting for the server to be up." | ||
exit 1 | ||
fi | ||
|
||
puts "Running api via DIP..." | ||
system("dip api rackup") | ||
echo "Server is up and running!" |