Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify setting up dev environment #993

Merged
merged 11 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe
* Increase the security of the session cookie using HTTPONLY and SECURE ([#972](https://github.com/ScilifelabDataCentre/dds_web/pull/972))
* Add role when listing project users ([#974](https://github.com/ScilifelabDataCentre/dds_web/pull/974))
* Add custom error messages to registration form ([#975](https://github.com/ScilifelabDataCentre/dds_web/pull/975))
* Fix format of self deletion email ([#984](https://github.com/ScilifelabDataCentre/dds_web/pull/984))
* Fix format of self deletion email ([#984](https://github.com/ScilifelabDataCentre/dds_web/pull/984))
* Add a full zero-conf development environment ([#993](https://github.com/ScilifelabDataCentre/dds_web/pull/993))
13 changes: 13 additions & 0 deletions Dockerfiles/cli.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:latest as base

RUN apt-get update && apt-get upgrade -y && apt-get install git
RUN git clone https://github.com/ScilifelabDataCentre/dds_cli /code
WORKDIR /code

# Install all dependencies
RUN pip3 install -r /code/requirements.txt

# Add code directory in pythonpath
ENV PYTHONPATH /code

CMD ["tail", "-f", "/dev/null"] # to keep container running
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,51 @@ You can download Docker here: <https://docs.docker.com/get-docker/>
Then, fork this repository and clone to your local system.
In the root folder of the repo, run the server as follows:

There are multiple profiles prepared depending on your needs:

```bash
docker-compose up
```
This command will orchestrate the building and running of two containers: one for the SQL database (`mariadb`) and one for the application.

```bash
docker-compose --profile dev up
```

This will give you the above two containers, but also `mailcatcher` that will allow you to read
any sent emails by going to `localhost:1080` in a web browser.

```bash
docker-compose --profile full-dev up
```

This command will orchestrate the building and running of two containers:
one for the SQL database (`mariadb`) and one for the application.
Will also activate minio for s3 storage (clearly not functional with cli) and redis to enable a persistent limiter for the API.
You also need to uncomment `RATELIMIT_STORAGE_URI` in `docker-compose.yml` to enable redis.

If you prefer, you can run the web servers in 'detached' mode with the `-d` flag, which does not block your terminal.
If using this method, you can stop the web server with the command `docker-compose down`.
<br><br>

#### CLI development against local environment

```bash
docker-compose --profile cli up
```
Will start database, backend, minio, and mailcatcher. Will also start an extra container prepared for working with the CLI.

Requires that dds_cli is checked out in `../dds_cli` (otherwise adapt the volume path in `docker-compose.yml`).

1. Start docker-compose with the `cli` profile
2. Inject into the `dds_cli` container:

```bash
docker exec -it dds_cli /bin/bash
```

3. pip install -e .

Then you can freely use the dds cli component against the local development setup in the active CLI.

### Python debugger inside docker
It's possible to use the interactive debugging tool `pdb` inside Docker with this method:
1. Edit the `docker-compose.yml` and for the `backend` service, add:
Expand Down
16 changes: 8 additions & 8 deletions dds_web/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class Config(object):
# Expected paths - these are the bind paths *inside* the container
USE_LOCAL_DB = True
LOGS_DIR = "/dds_web/logs"
SAFESPRING_URL = os.environ.get("DDS_SAFESPRING_URL", "https://example.endpoint.net")
SAFESPRING_URL = os.environ.get("DDS_SAFESPRING_URL", "http://minio:9000")
DDS_SAFESPRING_PROJECT = os.environ.get("DDS_SAFESPRING_PROJECT", "project-name.example.se")
DDS_SAFESPRING_ACCESS = os.environ.get("DDS_SAFESPRING_ACCESS", "SAFESPRINGACCESSKEY")
DDS_SAFESPRING_SECRET = os.environ.get("DDS_SAFESPRING_SECRET", "SAFESPRINGSECRETKEY")
DDS_SAFESPRING_ACCESS = os.environ.get("DDS_SAFESPRING_ACCESS", "minio")
DDS_SAFESPRING_SECRET = os.environ.get("DDS_SAFESPRING_SECRET", "minioPassword")

# Use short-lived session cookies:
PERMANENT_SESSION_LIFETIME = datetime.timedelta(hours=1)
Expand All @@ -49,11 +49,11 @@ class Config(object):
OIDC_CLIENT_SECRET = ""
OIDC_ACCESS_TOKEN_URL = ""

MAIL_SERVER = "smtp.mailtrap.io"
MAIL_PORT = 2525
MAIL_USERNAME = os.environ.get("MAIL_USERNAME", "mailtrap_username")
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD", "mailtrap_password")
MAIL_USE_TLS = True
MAIL_SERVER = "mailcatcher"
MAIL_PORT = 1025
MAIL_USERNAME = os.environ.get("MAIL_USERNAME", "")
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD", "")
MAIL_USE_TLS = False
MAIL_USE_SSL = False
MAIL_DEFAULT_SENDER = "[email protected]"

Expand Down
63 changes: 56 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: "3.8"
# for persistent endpoint limiter, uncomment RATELIMIT_STORAGE_URI and the redis entry
version: "3.9"
# Use --profile full-dev and uncomment RATELIMIT_STORAGE_URI to use redis

services:

db:
container_name: dds_database
image: mariadb:latest
Expand Down Expand Up @@ -53,7 +52,6 @@ services:
ports:
- 127.0.0.1:5000:5000
volumes:

# Migrations
- type: bind
source: ./migrations
Expand All @@ -79,6 +77,57 @@ services:
source: $DDS_LOG_DIR
target: /dds_web/logs

# redis:
# container_name: dds_redis
# image: redis:latest
minio:
container_name: dds_minio
image: minio/minio:RELEASE.2022-02-24T22-12-01Z
profiles:
- s3
- full-dev
- cli
command: server /data --console-address ":9001"
ports:
- 127.0.0.1:9000:9000
- 127.0.0.1:9001:9001
environment:
MINIO_ROOT_USER: minio # access key
MINIO_ROOT_PASSWORD: minioPassword # secret key
# NOTE: Uncomment if you want to keep your data.
# Mounts a folder into the container to make uploaded data persistent.
# volumes:
talavis marked this conversation as resolved.
Show resolved Hide resolved
# - type: bind
# source: ./minio-data
# target: /data
talavis marked this conversation as resolved.
Show resolved Hide resolved

mailcatcher:
container_name: dds_mailcatcher
image: sj26/mailcatcher:latest
profiles:
- dev
- mail
- full-dev
- cli
ports:
- 127.0.0.1:1080:1080

redis:
container_name: dds_redis
image: redis:latest
profiles:
- full-dev
- redis

cli:
container_name: dds_cli
build:
dockerfile: Dockerfiles/cli.Dockerfile
context: ./
target: base
profiles:
- cli
- full-dev
environment:
- DDS_CLI_ENV=docker-dev
volumes:
- type: bind
source: ../dds_cli
target: /code