Skip to content

Commit

Permalink
Add mongosh to the tom_server Dockerfile. Some (not enough) doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rknop committed Oct 30, 2024
1 parent e1ac27c commit eecb1e8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Based on the [Tom Toolkit](https://lco.global/tomtoolkit/)
* [For ELAsTiCC](#for-elasticc)
* [For ELAsTiCC2](#for-elasticc2)
* [Development and database migrations](#development-and-database-migrations)
* [MongoDB installation and users]
* [Running Tests](#running-tests)
* [Starting the test environment](#starting-the-test-environemnt)
* [Deployment at NERSC](#deployment-at-nersc)
Expand All @@ -36,6 +37,7 @@ Based on the [Tom Toolkit](https://lco.global/tomtoolkit/)
* [Updating the running code](#updating-the-running code)
* [Additional YAML files](#additional-yaml-files)
* [Removing it all from Spin](#removing-it-all-from-spin)

* [Notes for ELAsTiCC](#notes-for-elasticc)
* [ELAsTiCC](#noteselasticc)
* [Streaming to ZADS](#elasticcstream)
Expand Down Expand Up @@ -533,6 +535,32 @@ If you change any database schema, you have to get a shell on the server's conta

BE CAREFUL ABOUT DATABASE MIGRATIONS. For throw-away development environments, it's fine. But, the nature of database migrations is such that forks in database schema history are potentially a lot more painful to deal with than forks in source code (where git and text merge can usually handle it without _too_ much pain). If you're going to make migrations that you want to have pulled into the main branch, coordinate with the other people working on the DESC Tom. (As of this writing, that's me, Rob Knop.)

### MongoDB installation and users

The `fastdb_dev` application uses Mongo for storing broker alerts. In `docker_server/Dockerfile`, it tries to install `mongosh`, so that should be available on both the running `tom` server and a shell server (if you start one, as the dev docker-compose environment can). The URL for downloading the `.deb` was discovered from this web page (in case at some point in the future we want to update the version): https://www.mongodb.com/try/download/shell

The connection string is something like:

```
mongodb://mongodb_admin:password@mongodb/
```

Where `password` is whatever you set it to when configuring the server, and replace the `mongodb` after the `@` with the right host address. (`mongodb` is the right thing to use in the test docker compose environment, and in Spin deployments that Rob did, assuming you're connecting from a server elsewhere within the same spin deployment.)

#### Creating the database

Just as you may have to do a `python manage.py migrate` and `python manage.py createsuperuser` to update the postgres databases*, when you first install you probably need to create the mongodb `alerts` database and a couple of users. Use `mongosh` to connect to the database and run:

```
use alerts
db.createUser( {user: 'mongodb_alert_reader', pwd: '<password>', 'roles': [ { role: 'read', db: 'alerts' } ] } )
db.createUser( {user: 'mongodb_alert_writer', pwd: '<password>', 'roles': [ { role: 'readWrite', db: 'alerts' } ] } )
```

where the usernames should match what you set in the `MONGO_ALERT_READER_USERNAME` and `MONGO_ALERT_WRITER_USERNAME` environment variables passed to the container, and the passwords likewise match the `*_PASSWORD` env vars.

* Note: for postgres, but _not_ (as of this writing) mongo, in the test environment defined in `tests/docker-compose.yaml` the database migrations and user creation are performed automatically when you bring up the docker compose environment.

<!--
#### Cassandra Migrations
Expand Down Expand Up @@ -625,6 +653,8 @@ where you cut and paste the full ugly pod name from the output of `get all` or `

#### <a name="prodscratch"></a> The steps necessary to create the production TOM from scratch:

NOTE, THIS IS OUT OF DATE, NEEDS TO BE UDPATED FOR THE ADDITION OF MONGODB

If you're making a new deployment somewhere (rather than just recreating
desc_tom on the Spin production server), you *will* need to edit the YAML files before applying them
(so that things like "namespace" and "workloadselector" are consistent
Expand Down
14 changes: 12 additions & 2 deletions docker_server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ SHELL ["/bin/bash", "-c"]
ENV TZ="UTC"

RUN mkdir /tom_desc
WORKDIR /tom_desc
ENV HOME="/"

RUN DEBIAN_FRONTEND="noninteractive" \
apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y gdal-bin python3 postgresql-client \
tmux dumb-init netcat-openbsd bind9-dnsutils \
tmux dumb-init netcat-openbsd bind9-dnsutils curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -41,6 +40,13 @@ RUN chmod -R 777 /.astropy
# Sanity
ENV LESS=-XLRi

WORKDIR /usr/src

# Try to install mongosh
RUN curl -L https://downloads.mongodb.com/compass/mongodb-mongosh-shared-openssl3_2.3.3_amd64.deb -O \
&& dpkg --install mongodb-mongosh-shared-openssl3_2.3.3_amd64.deb \
&& rm -f mongodb-mongosh-shared-openssl3_2.3.3_amd64.deb

# ======================================================================
FROM base AS build

Expand Down Expand Up @@ -70,6 +76,8 @@ FROM base AS tom-server-bindmount
COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH

WORKDIR /tom_desc

# Run the TOM server
EXPOSE 8080
ENTRYPOINT [ "/venv/bin/gunicorn", "tom_desc.wsgi", "-b", "0.0.0.0:8080", "--access-logfile", "-", "--error-logfile", "-", "-k", "gevent", "--timeout", "300", "--workers", "2"]
Expand All @@ -93,5 +101,7 @@ FROM build AS tom-server-bindmount-dev

ENV PATH=/venv/bin:$PATH

WORKDIR /tom_desc

EXPOSE 8080
ENTRYPOINT [ "/venv/bin/gunicorn", "tom_desc.wsgi", "-b", "0.0.0.0:8080", "--access-logfile", "-", "--error-logfile", "-", "-k", "gevent", "--timeout", "300", "--workers", "2"]

0 comments on commit eecb1e8

Please sign in to comment.