# Deployment

# Server deployment

* The AgtroPortal VM is deployed in INRAE servers
* The global architecture

  ![](https://wiki.agroportal.eu/api/files.get?sig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1cGxvYWRzL2MyODRmYzA0LTA4ZmUtNGE1Yi05ODM4LWM5MjhmYTFlNjhjNi85ZDI5MjY3Zi05OGQyLTRmZjItYTdlNS05OGFlNTMwZDhiNjkvaW1hZ2UucG5nIiwidHlwZSI6ImF0dGFjaG1lbnQiLCJpYXQiOjE3OTM4OTQ0MDAsImV4cCI6MTc5Mzk4MDgwMH0.EioMSPuylaQXJKJtWjrxRNbB58soHv1JnLu5bCTC9DY " =2506x1028")

# Code deployment

* AgroPortal new deployment process: <https://github.com/ontoportal-lirmm/agroportal_deployment>
  * This repository contains the **Capistrano-based deployment system** for the three AgroPortal components:
    * **BioPortal Web UI** (`bioportal_web_ui`)
    * **Ontologies API** (`ontologies_api`)
    * **NCBO Cron** (`ncbo_cron`)
  * It supports deployment to **production** (master branch) and **pre-production** (development branch) environments with a simple command-line script.

## Quick Start: Deploy in One Command

From the root of this repository, run:

```bash
./deploy.sh <application> <stage>
```

### Examples

```bash
# Deploy with full name of apps in production and pre_production servers
./deploy.sh bioportal_web_ui production
./deploy.sh ontologies_api pre_production
./deploy.sh ncbo_cron production

# Use short aliases (UI, API, CRON)
./deploy.sh UI production
./deploy.sh API pre_production
./deploy.sh CRON production
```

## How to use it inside the server

This repo is private so we have to add PAT token so that we can clone it in the server (copy the PAT token in settings => Secrets and variables => Actions => Variables => Repository variables) or generate new one.

Inside the server do:

```bash
# with user ontoportal
git clone https://<PAT_TOKEN>@github.com/agroportal/agroportal_deployment.git
cd agroportal_deployment
./deploy.sh <application> <stage>
```

## Project Structure

```
.
├── deployment/                 # Capistrano project (Ruby-based)
│   ├── Capfile                # Capistrano entry point
│   ├── Gemfile                # Ruby dependencies
│   └── config/
│       ├── deploy.rb          # Main deployment logic
│       ├── apps/              # App-specific settings (repo, etc.)
│       │   ├── bioportal_web_ui.rb
│       │   ├── ontologies_api.rb
│       │   └── ncbo_cron.rb
│       └── deploy/            # Environment definitions
│           ├── production.rb
│           └── pre_production.rb
├── projects_configs/          # Environment-specific config files
│   ├── bioportal_web_ui/
│   │   ├── production/config/
│   │   └── pre_production/config/
│   ├── ontologies_api/
│   │   ├── production/config/
│   │   └── pre_production/config/
│   └── ncbo_cron/
│       ├── production/config/
│       └── pre_production/config/
├── deploy.sh                  # Main deployment script (use this!)
└── README.md
```

### Key Directories

| Directory | Purpose |
|-----------|---------|
| `deployment/` | Contains the Capistrano automation code (Ruby) |
| `projects_configs/` | Holds **environment-specific configuration files** that get uploaded during deploy (e.g., `database.yml`, `settings.rb`) |
| `deployment/config/apps/` | Defines Git repo, app name, and other per-project settings |
| `deployment/config/deploy/` | Defines servers, branches, and environment settings (`production` vs `pre_production`) |

## How It Works


1. You run `./deploy.sh UI production`
2. The script:
   * Validates inputs
   * Normalizes `UI` → `bioportal_web_ui` (if you use short aliases)
   * Installs Ruby gems (into `vendor/bundle`)
   * Runs: `APP=bioportal_web_ui bundle exec cap production deploy`
3. Capistrano:
   * Clones the correct Git repo
   * Uploads configs from `projects_configs/bioportal_web_ui/production/config/`
   * Symlinks shared files
   * Restarts the service (`systemctl restart bioportal_web_ui.service`)

## Requirements on the server

* **Ruby 3.1+** (managed via `rbenv` on target servers)
* **SSH access** to target servers as the `ontoportal` user
* **Internet access** (to clone Git repos and install gems)

## Notes

* To add a **new application**, create:
  * `deployment/config/apps/<app_name>.rb`
  * `projects_configs/<app_name>/production/config/`
  * `projects_configs/<app_name>/pre_production/config/`
* To add a **new environment**, create:
  * `deployment/config/deploy/<env_name>.rb`
  * Update `VALID_STAGES` in `deploy.sh`
* Config files in `projects_configs/` are **copied as-is** to the app’s `release_path` during deploy.

---

**Documents**

- [💁‍♂️ Acknowledgments](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/acknowledgments-15GdRXLQdm)
- [📚Publications and references](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/publications-and-references-87tEoeoGKy)
- [🗽Terms & Conditions](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/terms-conditions-naDsDo2Zxq)
- [🧞‍♂️Metadata guidelines and recommendations](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/metadata-guidelines-and-recommendations-pOFbK9sIfp)
- [📜 AgroPortal Release Notes](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-release-notes-btKjZk5tU2)
- [ 👩‍🚀 User Guide](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/user-guide-ZszoBwfjGF)
- [📎 API Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/api-documentation-kMCurGKD97)
- [🤖 Developer Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/developer-documentation-LhsrucqGTa)
- [🗃External Documentation](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/external-documentation-vNPQCdArrr)
- [AgroPortal infrastructure](https://wiki.agroportal.eu/s/e6158eda-c109-4385-852c-51a42de9a412/doc/agroportal-infrastructure-ietsAU4kPs)