|
| 1 | +# BCODB Docker Deployment |
| 2 | + |
| 3 | + |
| 4 | +### Requirements |
| 5 | +- Python 3: [3.10.6 reccomended](https://www.python.org/downloads/release/python-3106/) |
| 6 | +- [PyEnv](https://github.com/pyenv/pyenv) (optional but recommended for Mac/Linux) |
| 7 | +- Docker: |
| 8 | + - [Docker Desktop for Linux](https://docs.docker.com/desktop/install/linux-install/) |
| 9 | + - [Docker Desktop for Mac (macOS)](https://docs.docker.com/desktop/install/mac-install/) |
| 10 | + - [Docker Desktop for Windows](https://docs.docker.com/desktop/install/windows-install/) |
| 11 | + |
| 12 | + |
| 13 | +## Clone the repository |
| 14 | +``` |
| 15 | +git clone https://github.com/biocompute-objects/bco_api |
| 16 | +``` |
| 17 | + |
| 18 | +**Make sure you are on the desired branch (Check for latest branch):** |
| 19 | + |
| 20 | +``` |
| 21 | +git switch [DESIRED BRANCH TAG] |
| 22 | +``` |
| 23 | + |
| 24 | +## Enter the repository |
| 25 | +``` |
| 26 | +cd bco_api |
| 27 | +``` |
| 28 | +## Configure the DB settings using the `.secrets` file: |
| 29 | + |
| 30 | +### OPTION 1: Generate the secrets file |
| 31 | + |
| 32 | +In the project root copy the `.secrets.example` to `.secrets` |
| 33 | + |
| 34 | +``` |
| 35 | +cp .secrets.example .secrets |
| 36 | +``` |
| 37 | +#### Generate the DJANGO_KEY |
| 38 | +Generate a 32-bytes long PSK key using the `openssl` command or `PowerShell` command. |
| 39 | + |
| 40 | +##### Mac/Linux: |
| 41 | +``` |
| 42 | +openssl rand -base64 32 |
| 43 | +``` |
| 44 | +##### Windows: |
| 45 | +``` |
| 46 | +[Convert]::ToBase64String((1..32 | ForEach-Object { Get-Random -Minimum 0 -Maximum 256 }) -as [byte[]]) |
| 47 | +``` |
| 48 | + |
| 49 | +Use a text editor to open the `.secrets` file and update the rest of the variables. For details on each of the variables see the [configuration](/docs/config.md) documentation. |
| 50 | + |
| 51 | +### OPTION 2: Use the `local_deployment.secrets` file |
| 52 | +Fromt the project root: |
| 53 | +``` |
| 54 | +cp admin_only/local_deployment.secrets .secrets |
| 55 | +``` |
| 56 | + |
| 57 | +### Building the BCO API via Docker |
| 58 | + |
| 59 | +A docker file is provided to allow easy building of the BCO API. This can be done from the root directory (the directory with Dockerfile in it) by running: |
| 60 | + |
| 61 | +`docker build -t bco_api:latest .` |
| 62 | + |
| 63 | +This will build a container named `bco_api` with the tag `latest`. |
| 64 | + |
| 65 | +The build process (via the `entrypoint.sh` script) will check for an existing database in the repository and run migrations. If no database is present one will be created and the test data will be loaded (taken from `config/fixtures/local_data.json`). |
| 66 | + |
| 67 | +### Running the container via Docker |
| 68 | + |
| 69 | +The BCO Api container can be run via docker on the command line in Linux/Windows by running: |
| 70 | + |
| 71 | +`docker run --rm --network host -it bco_api:latest` |
| 72 | + |
| 73 | +The BCO Api container can be run via docker on the command line in MacOS by running: |
| 74 | + |
| 75 | +`docker run --rm -p 8000:8000 -it bco_api:latest` |
| 76 | + |
| 77 | +This will expose the server at `http://127.0.0.1:8000`, whitch is where all of the default settings will expect to find the BCODB. |
| 78 | + |
| 79 | +#### Overriding the port |
| 80 | + |
| 81 | +It is possible to override the port 8000 to whatever port is desired. This is done by running the container with 8080 representing the desired port. |
| 82 | + |
| 83 | +`docker run --rm --network host -it bco_api:latest 0.0.0.0:8080` |
| 84 | + |
| 85 | + |
| 86 | +NOTE: The ip address of 0.0.0.0 is to allow the web serer to properly associate with 127.0.0.1 - if given 127.0.0.1 it will not allow communications outside of the container! |
| 87 | + |
| 88 | +You can also give it a specific network created with `docker network create` if you wanted to give assigned IP addresses. |
0 commit comments