Skip to content

Commit

Permalink
Make docker compose setup work with new Dockerfile
Browse files Browse the repository at this point in the history
And document how to connect to tom docker-compose ecosystem
  • Loading branch information
mtauraso committed Nov 6, 2024
1 parent 3da0faf commit 7c56dc6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ _html/
.initialize_new_project.sh
auxiliary_files/cosmo
auxiliary_files/cosmo.hpp

# Location for secrets used to log into TOM in a dev envornoment
secrets/
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM ubuntu

ENV RESSPECT_DIR=/resspect

# Note that this is where we copy resspect source at build time
# and also where docker-compose mounts the curent source directory in this container.
ENV RESSPECT_SRC=${RESSPECT_DIR}/resspect-src
ENV RESSPECT_VENV=${RESSPECT_DIR}/resspect-venv
ENV RESSPECT_VENV_BIN=${RESSPECT_VENV}/bin
ENV RESSPECT_WORK=${RESSPECT_DIR}/resspect-work

WORKDIR ${RESSPECT_DIR}

#ENV HOME=/

RUN echo "entering resspect Dockerfile"
RUN echo "Entering resspect Dockerfile"

RUN apt-get update && \
apt-get -y upgrade && \
Expand All @@ -20,7 +21,10 @@ RUN apt-get update && \

RUN ln -s /usr/bin/python3 /usr/bin/python

# Copy over resspect source from local checkout
# Copy over resspect source from local checkout so we can install dependencies
# and so the container will have a version of RESSPECT packaged when run standalone.
#
# If this line is changed, pleas refer to the bind mount in the compose file to ensure consistency.
COPY . ${RESSPECT_SRC}

# Create a venv for resspect
Expand Down
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,54 @@ You can now install this package with:

(RESSPECT) >>> pip install -e .

> You may choose to create your virtual environment within the folder of the repository. If you choose to do this, you must remember to exclude the virtual environment directory from version control using e.g., ``.gitignore``.
> You may choose to create your virtual environment within the folder of the repository. If you choose to do this, you must remember to exclude the virtual environment directory from version control using e.g., ``.gitignore``.
# Starting the docker environment

The docker file in this repository can be run as a standalone environment for testing or developing RESSPECT, or in connection with tom. You will need to start by installing Docker Desktop for your chosen platform before you start.

Note: These workflows have only been tested on macs; however the standalone docker image is built on Linux in in Github Actions CI.

## Using standalone

To use the container standalone first go into the root of the source directory, and build the container with:
```
docker build .
```

You can run the container two ways. The first way will use the version of resspect from your local checkout, which is probably what you want for development. After the
container is built run:
```
docker run -it --rm --mount type=bind,source=.,target=/resspect/resspect-src resspect
```

This will put you into a bash shell in the container with the venv for resspect already activated, and the current version of resspect in your source checkout installed.

If you wish to use the version of resspect packaged at build time, simply omit `--mount type=bind,source=.,target=/resspect/resspect-src` from the command above.

## Using with tom docker-compose setup

First checkout tom and follow [TOM's docker compose setup instructions](https://github.com/LSSTDESC/tom_desc?tab=readme-ov-file#deploying-a-dev-environment-with-docker). You will need to load [ELAsTiCC2 data](https://github.com/LSSTDESC/tom_desc?tab=readme-ov-file#for-elasticc2) into your tom environment in order to work with RESSPECT.

When you have finished that setup, go into the top level source directory and run these two commands:
```
docker compose build
docker compose up -d
```

You will now have a docker container called `resspect` which you can run resspect from. The version of resspect in use will be that of your local git checkout. That same docker container will be on the network with your tom setup, so you can access
the tom docker container on port 8080.

You can enter the `resspect` docker container to run commands with
```
docker compose run resspect
```

From the resspect container you should be able to log into the tom server with:
```
(resspect-venv) root@cd647ac7eca5:/resspect# python3
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from resspect import tom_client as tc
>>> tc = tc.TomClient(url="http://tom:8080", username='admin', password='<your tom password>')
```
20 changes: 13 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
resspect:
tty: true
Expand All @@ -11,11 +9,13 @@ services:
- "db"
volumes:
- type: bind
source: ./resspect
target: /resspect
source: ./
target: /resspect/resspect-src
- type: bind
source: ./secrets
target: /secrets
bind:
create_host_path: true
environment:
- DB_USER=admin
- DB_PASS=verysecurepassword
Expand All @@ -35,11 +35,17 @@ services:
- POSTGRES_DB=resspectdb
- POSTGRES_DATA_DIR=/docker-entrypoint-initdb.d
volumes:
- ./resspectdb.sql:/docker-entrypoint-initdb.d/resspectdb.sql
- type: bind
source: ./resspect
source: ./resspectdb.sql
target: /docker-entrypoint-initdb.d/resspectdb.sql
- type: bind
source: ./src/resspect
target: /resspect

healthcheck:
test: ["CMD-SHELL", "pg_isready -U admin -d resspectdb"]
interval: 1s
timeout: 5s
retries: 10

networks:
tom_desc_default:
Expand Down

0 comments on commit 7c56dc6

Please sign in to comment.