Skip to content

Commit

Permalink
Merge pull request #4 from ontoportal-lirmm/feature/create-a-script-t…
Browse files Browse the repository at this point in the history
…o-ontoportal-docker-api-ui

Feature: create a script to ontoportal docker api UI
  • Loading branch information
imadbourouche authored Jul 15, 2024
2 parents f395921 + 0a41f55 commit 6487d38
Show file tree
Hide file tree
Showing 21 changed files with 944 additions and 180 deletions.
57 changes: 35 additions & 22 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
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"
REDIS_HTTP_CACHE_HOST="redis"
REDIS_PERSISTENT_HOST="redis"
REPOSITORY_FOLDER="/srv/ontoportal/data/repository"
REPORT_PATH="/srv/ontoportal/data/reports/ontologies_report.json"
SOLR_TERM_SEARCH_URL="http://solr:8983/solr"
SOLR_PROP_SEARCH_URL="http://solr:8983/solr"
MGREP_HOST="mgrep"
MGREP_PORT="55556"
GOO_PORT=9000
GOO_HOST="4store"
##################### General 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
SERVICE=ontoportal

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

##################### UI configuration ####################
RAILS_ENV=development
SITE=Ontoportal
ORG_URL=http://www.lirmm.fr
UI_URL=http://localhost:3000
API_KEY=72c72cba-ad45-4785-b94e-483fa55cdddb
UI_THEME=ontoportal
FAIRNESS_DISABLED=false
NCBO_ANNOTATORPLUS_ENABLED=false
SUPPORT_EMAIL=sifrportal-support@lirmm.fr
RELEASE_VERSION="OntoPortal Appliance 3.0.1"
USE_RECAPTCHA=false
ANNOTATOR_URL=""

##################### CRON configuration #####################
OP_API_URL=https://data.bioontology.org
OP_APIKEY=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
STARTER_ONTOLOGY=STY
IMAGE_REPOSITORY=bioportal
IMAGE_TAG=latest
OP_APIKEY=<YOUR ONTOPORTAL API KEY>
OP_API_URL="https://data.bioontology.org"
STARTER_ONTOLOGY="STY"

##################### KAMAL configuration ####################
IMAGE_NAME=
SERVER_IP=
DOCKER_REGISTRY_NAME=
KAMAL_REGISTRY_PASSWORD=
SSH_USER=
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Run docker scripts tests CI"

on:
push:
pull_request:
types: [opened, reopened]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive" # Make sure submodules are fetched recursively

- name: Run OntoPortal Docker tests
run: test/run_tests.sh
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ dip.override.yml
/ontologies_linked_data/
/.idea/

ontologies_linked_data

.kamal/hooks/

docker-compose_api.yml

docker-compose_ui.yml

*.iml
/config/deploy.yml
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "test/bats"]
path = test/bats
url = https://github.com/bats-core/bats-core.git
[submodule "test/test_helper/bats-support"]
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "test/test_helper/bats-assert"]
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM alpine:latest

ENV TERM xterm-256color
RUN apk --update --no-cache add \
bash \
curl \
docker \
docker-compose \
git \
iproute2 \
busybox \
ncurses \
bind-tools

COPY . /app
RUN chmod +x /app/ontoportal
RUN chmod +x /app/bin/*
RUN chmod +x /app/utils/*
WORKDIR /app

CMD ["/bin/sh", "-c", "/app/ontoportal start --no-provision"]
99 changes: 88 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,93 @@
# OntoPortal docker environment
See help
# OntoPortal docker
OntoPortal Docker is a comprehensive collection of scripts designed to facilitate the running, testing, and deployment of ontoPortal using Docker.

With this project, you can quickly spin up a fully functional ontoPortal instance with minimal setup by leveraging docker's containerization technology. This allows you to test its features and deploy the instance using Kamal.

## Features
- Start ontoportal instance (with or without parsing ontology)
- Start specific services (API/UI)
- Build docker image for this project and push it to your repository
- Deploy the instance to server

## Project architecture
- **bin**: directory contains essential scripts for deploying and running various components of the ontoPortal system
- **config**: contains deploy.yml file which contains settings and parameters required for deployment using kamal deployment tool
- **test**: testing-related files and scripts using bats testing framework
- **utils**: utility and additional scripts for various purposes
- **.env.sample**: sample file contains configuration of the ontoportal instance (will be copied to .env when running)
- **Dockerfile**: defines configurations to build the docker image for the project
- **ontoportal**: the main script to run the ontoportal, it includes the entry point and main execution logic for the ontoPortal services
- **run**: This file is used to set up environment for tests (it will be deleted).
## Prerequisites
- [git](https://git-scm.com/downloads)
- [Docker](https://docs.docker.com/engine/install/)
- [Docker Compose](https://docs.docker.com/compose/install/)
- [Kamal deploy tool](https://kamal-deploy.org/docs/installation/) (if you plan to use the deploy feature)

## Installation
```
./run -h
~> git clone https://github.com/ontoportal-lirmm/ontoportal_docker.git
~> cd ontoportal-docker
```
## Usage
### General Command Structure
```
./ontoportal <command> [arguments]
```
### Commands
- **Start**
- start ontoportal instance
```
./ontoportal start [--no-provision]
```
- start specific services (API or UI)
```
./ontoportal start [api|ui] [--no-provision]
```
- `--no-provision`: Start the appliance without any data (an empty appliance).

to know how to run an ontoportal API docker instance
- **Deploy**
- build and push image to repository (by default docker hub)
```
./ontoportal deploy push
```
- Deploy ontoportal instance to server (or just specific services mentioned in the arguments)
```
./ontoportal deploy [api|ui]
```
- **Stop**: stop the OntoPortal API and UI services.
```
./ontoportal stop [api|ui]
```
- **Clean**: clean up the server. This removes all data, Docker Compose files, and containers
```
./ontoportal clean [-f]
```
- `-f` : for force clean

```
Usage: ./run [-k API_KEY] [-u API_URL] [-r IMAGE_REPOSITORY] [-t IMAGE_TAG] [-s STARTER_ONTOLOGY] [--no-provision]
```
- **Help**: display the help message.
```
./ontoportal help
```

Example
```bash
./run -k <apikey>-r agroportal -t master -s STY -u "https://data.bioontology.org"
```
### Additional Notes
- You can provide your own `.env` file to customize parameters. Place the .env file in the project directory.
- `.env` file contains 5 parts:
- **General configuration**: where you can specify:
```yml
ORGANIZATION_NAME: github organization from where script will fetch docker compose files
COMPOSE_API_FILE_PATH: docker compose file of the UI
COMPOSE_UI_FILE_PATH: docker compose file of the UI
SERVICE: specify the service you want to run (script will handle this)
```
- **API Configurations:** contains settings for api service
- **UI Configurations:** contains settings for ui service
- **Cron Configurations:** contains settings for cron service
- **Kamal configurations**: for build and deployment of the ontoportal instance:
```yml
IMAGE_NAME: the name of the image to build and push to docker hub
SERVER_IP: the ip server where you want to deploy the instance
DOCKER_REGISTRY_NAME: the name of account in docker hub of another repository
KAMAL_REGISTRY_PASSWORD: password of token to access the repository
SSH_USER: the user that will be used when deploying into the server
```
54 changes: 54 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
deploy() {
local env_path='.env'

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

if [ -z "$1" ]; then
SERVICE="ontoportal"
else
SERVICE="$1"
fi

# Update SERVICE variable in .env file without using sed
awk -v SERVICE="$SERVICE" '/^SERVICE=/{sub(/=.*/, "=" SERVICE)} 1' .env >temp && mv temp .env

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 -e "volumes:\n - /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
if [ -z "$1" ]; then
echo "[+] Starting the deployment"
kamal setup -vv
elif [ "$1" == "push" ]; then
echo "[+] Pushing image to Docker Hub without deploying to server"
kamal build push -vv
fi

}

deploy "$1"
Loading

0 comments on commit 6487d38

Please sign in to comment.