Skip to content

Commit efebfbe

Browse files
committed
Add instructions for Docker deployment
Changes to be committed: modified: Dockerfile modified: docker-compose.yml modified: docs/deployment/dockerDeployment.md new file: entrypoint.sh
1 parent f54925b commit efebfbe

File tree

4 files changed

+115
-25
lines changed

4 files changed

+115
-25
lines changed

Dockerfile

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,22 @@ LABEL org.opencontainers.image.source=https://github.com/octocat/my-repo
66
LABEL org.opencontainers.image.description="My container image"
77
LABEL org.opencontainers.image.licenses=MIT
88

9-
# Note that this is just for debug / test purposes; should not be set via the setup for production
10-
# ENV DJANGO_SUPERUSER_PASSWORD="BioCompute123"
11-
# ENV DJANGO_SUPERUSER_USERNAME="BioComputeSuperUser"
12-
# ENV DJANGO_SUPERUSER_EMAIL="[email protected]"
139

1410
RUN apt-get -qq update && apt-get install -y python3.9 python3-dev python3-pip
1511

1612
RUN python3 -m pip install --upgrade pip
1713

1814
WORKDIR /biocompute_api
1915

20-
COPY requirements.txt .
21-
16+
COPY requirements.txt /biocompute_api/
2217
RUN python3 -m pip install -r requirements.txt
2318

24-
COPY . ./
25-
26-
WORKDIR /biocompute_api/
19+
COPY . /biocompute_api/
2720

28-
# RUN python3 manage.py migrate
29-
# RUN python3 manage.py createsuperuser --no-input
21+
WORKDIR /biocompute_api
3022

3123
EXPOSE 8000
32-
#CMD ["bash"]
33-
ENTRYPOINT ["python3", "manage.py", "runserver"]
34-
CMD ["0.0.0.0:8000"]
24+
25+
ENTRYPOINT ["./entrypoint.sh"]
26+
27+
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]

docker-compose.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
#cat docker-compose.yml
2-
3-
version: '3.4'
41

52
services:
63
bco-api:
74
platform: linux/amd64
85
build: .
9-
image: ghcr.io/biocompute-objects/bco_api:23.07
106
container_name: bco-api
11-
volumes:
12-
- ./data/db.sqlite3:/biocompute_api/db.sqlite3
13-
- ./data/server.conf:/biocompute_api/server.conf
7+
# volumes:
8+
# - ./db.sqlite3:/biocompute_api/db.sqlite3
9+
# - ./.secrets:/biocompute_api/.secrets
1410
environment:
1511
TZ: 'America/New_York'
16-
ENV DJANGO_SUPERUSER_PASSWORD: "BioCompute123"
17-
ENV DJANGO_SUPERUSER_USERNAME: "BioComputeSuperUser"
18-
ENV DJANGO_SUPERUSER_EMAIL: "[email protected]"
12+
1913
ports:
2014
- "8000:8000"
21-
read_only: true
15+
2216
tmpfs:
2317
- /tmp
2418
restart: unless-stopped
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.

entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# entrypoint.sh
3+
4+
# Check if the SQLite database file exists and run migrations if it doesn't
5+
if [ ! -f "db.sqlite3" ]; then
6+
echo "Database not found. Running migrations..."
7+
python3 manage.py migrate
8+
python3 manage.py loaddata config/fixtures/local_data.json
9+
else
10+
echo "Database exists. Running migrations."
11+
python3 manage.py migrate
12+
fi
13+
14+
# Start the Django server
15+
exec "$@"

0 commit comments

Comments
 (0)