## Prerequisites

* This image needs access to the files generated by autosubmit

## Build

To build the image you can execute `./build.sh`, or:

```bash
docker build -t autosubmit-api .
```

You can build with a different version of the API by running:

```bash
docker build --build-arg API_VERSION=4.0.0b5 -t autosubmit-api .
```

## Run

### Default run

If you followed the normal installation path of autosubmit (creating the autosubmit directory `~/autosubmit`). You can run `./run.sh`.

Else, you can set which are the directories that holds your DDBB files and experiment directories like this:

```bash
docker run --name autosubmit-api-container \
    --rm -d -p 8099:8000 \
    -v ${YOUR_DB_PATH}:/app/autosubmit/database \
    -v ${YOUR_EXPERIMENTS_PATH}:/app/autosubmit/experiments \
    autosubmit-api
```

This will expose a default API instance on port `8099`.

### Custom run (Recommended)

Alternatively, you can run the command `autosubmit_api` with custom parameters by adding additional arguments like this:

```bash
# Run with 6 workers, log level DEBUG, and map from port 9000
docker run --name autosubmit-api-container \
    --rm -p 8099:9000 \
    -v ${YOUR_DB_PATH}:/app/autosubmit/database \
    -v ${YOUR_EXPERIMENTS_PATH}:/app/autosubmit/experiments \
    autosubmit-api start -w=6 --log-level=DEBUG -b=0.0.0.0:9000
```

> **IMPORTANT** Always use the `-b` flag with `0.0.0.0` as the host to properly map the container API port


## Environment Variables Configuration

The `autosubmit_api` use env variables to configure some features like auth.

Here is an example:

```bash
docker run --name autosubmit-api-container \
    --rm -p 8099:9000 \
    -v ${YOUR_DB_PATH}:/app/autosubmit/database \
    -v ${YOUR_EXPERIMENTS_PATH}:/app/autosubmit/experiments \
    -e "PROTECTION_LEVEL=NONE" \  # This will disable protection
    autosubmit-api start -w=6 --log-level=DEBUG -b=0.0.0.0:9000
```


## Configuring the `.autosubmitrc`

The default `.autosubmitrc` of this image is configured to use SQLite and uses some predefined paths like `/app/autosubmit/database` for the main DB files and `/app/autosubmit/experiments` for the experiments root directory.

To modify it you have to make a new `.autosubmitrc` available in the container and mount its directory into the `/app/configs/` directory.

```bash
docker run --name autosubmit-api-container \
    --rm -d -p 8099:8000 \
    -v ${YOUR_DB_PATH}:/app/autosubmit/database \
    -v ${YOUR_EXPERIMENTS_PATH}:/app/autosubmit/experiments \
    -e "PROTECTION_LEVEL=NONE" \
    -v ${YOUR_AUTOSUBMIT_CONFIGURATION_PATH}:/app/configs \ # Mount the directory with your .autosubmitrc file in the configs directory
    autosubmit-api
```