diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..2b94298a04a15d16e3d67c778f48e33c9c4771fe --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,44 @@ +FROM python:3.9-slim-bullseye + +# Set the environment +ARG AUTOSUBMIT_ROOT_DIR=/app/autosubmit/ + +WORKDIR "${AUTOSUBMIT_ROOT_DIR}" + +RUN apt-get update && apt-get install -y git graphviz gcc lsof && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install Autosubmit API +# If GIT_REF is set, it will install from the specified branch/tag/commit. +# Otherwise, if AUTOSUBMIT_VERSION is set, it will install the specified version from pypi. +# Otherwise, it will install the latest version from pypi. +ARG GIT_REF +ARG AUTOSUBMIT_VERSION +RUN if [ -n "${GIT_REF}" ] ; then \ + pip3 install git+https://earth.bsc.es/gitlab/es/autosubmit-api.git@${GIT_REF}; \ + elif [ -n "${AUTOSUBMIT_VERSION}" ] ; then \ + pip3 install autosubmit-api==${AUTOSUBMIT_VERSION}; \ + else \ + pip3 install autosubmit-api; \ + fi + +COPY autosubmitrc /app/configs/autosubmitrc + +# Setup API env vars +ENV PROTECTION_LEVEL=ALL +ENV JWT_SECRET="k87;Zg,o5?MSC(/@#-LbzgE3PH-5ki.ZvS}N.s09v>I#v8I'00THrA-:ykh3HX?" + +ENV CAS_LOGIN_URL="" +ENV CAS_VERIFY_URL="" + +ENV GITHUB_OAUTH_CLIENT_ID="" +ENV GITHUB_OAUTH_CLIENT_SECRET="" +ENV GITHUB_OAUTH_WHITELIST_ORGANIZATION="" +ENV GITHUB_OAUTH_WHITELIST_TEAM="" + +ENV AUTOSUBMIT_CONFIGURATION="/app/configs/autosubmitrc" + +# Entrypoint +ENTRYPOINT ["autosubmit_api"] +CMD ["start", "-b=0.0.0.0:8000", "--log-file=api.log"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ff5576d9981138d343835b2296f6c2df3daa2a97 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,83 @@ +## 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 +``` \ No newline at end of file diff --git a/docker/autosubmitrc b/docker/autosubmitrc new file mode 100644 index 0000000000000000000000000000000000000000..aaa413e2d5b05b21d5a3d70ef1197d3683e6383e --- /dev/null +++ b/docker/autosubmitrc @@ -0,0 +1,10 @@ +[database] +path = /app/autosubmit/database +backend = sqlite +filename = autosubmit.db + +[local] +path = /app/autosubmit/experiments + +[globallogs] +path = /app/autosubmit/logs diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..2cc723e9e5c931cd8a0ee57a65f14f97ffc2f8ae --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t autosubmit-api --progress=plain . &> build.log diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..44da60e46d6ddb08850beca09255a43da5d7a306 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --name autosubmit-api-container \ + --rm -d -p 8099:8000 \ + -v ~/autosubmit:/app/autosubmit/database \ + -v ~/autosubmit:/app/autosubmit/experiments \ + autosubmit-api \ No newline at end of file diff --git a/docker/stop.sh b/docker/stop.sh new file mode 100755 index 0000000000000000000000000000000000000000..7936c91e46fe94724f23d1f9e0163958575e84cd --- /dev/null +++ b/docker/stop.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker stop autosubmit-api-container \ No newline at end of file