Skip to content

Commit

Permalink
Update docs for docker production (#1090)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Swain <swainn@users.noreply.github.com>
  • Loading branch information
sdc50 and swainn authored Sep 23, 2024
1 parent 0c5ac17 commit f618b8c
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 52 deletions.
4 changes: 4 additions & 0 deletions docs/_static/css/tethys.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ section>section {
background-color: #cfef90;
}

pre {
padding-left: 1rem;
padding-right: 1rem;
}
2 changes: 1 addition & 1 deletion docs/installation/production.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ We currently have images for the following commercial cloud providers:
Docker Deployment
-----------------

This method involves using Docker to package and automate the deployment of a Tethys Portal with that has your apps pre-installed. The advantage of this approach is that the process of installing Tethys Platform and your apps is automated in the Docker image. The other major advantage is portability, the Docker image can be deployed to any Linux server with Docker installed. The disadvantage is that there is a learning curve to get started using Docker for the first time. However, the investment of learning Docker is very much worth your time as most modern web applications are deployed using Docker or a similar container technology.
This method involves using Docker to package and automate the deployment of a Tethys Portal that has your apps pre-installed. The advantage of this approach is that the process of installing Tethys Platform and your apps is automated in the Docker image. The other major advantage is portability, the Docker image can be deployed to any Linux server with Docker installed. The disadvantage is that there is a learning curve to get started using Docker for the first time. However, the investment of learning Docker is very much worth your time as most modern web applications are deployed using Docker or a similar container technology.

.. toctree::
:maxdepth: 1
Expand Down
15 changes: 3 additions & 12 deletions docs/installation/production/docker/docker_compose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Use the following instructions to create a Docker Compose file for the custom Te
Docker allows directories from the host machine to be mounted into the containers. This is most often used to provide easy access to container data, configuration files, and logs.

a. Create the following directories in :file:`tethys_portal_docker` directory:

.. code-block:: bash
mkdir -p data/db
Expand All @@ -84,7 +83,6 @@ a. Create the following directories in :file:`tethys_portal_docker` directory:
mkdir -p logs/thredds/tomcat
b. Download the default :file:`tomcat-users.xml` file from the `Unidata/thredds-docker GitHub repository <https://github.com/Unidata/thredds-docker>`_:

* :download:`tomcat-users.xml <https://raw.githubusercontent.com/Unidata/thredds-docker/master/files/tomcat-users.xml>`

.. note::
Expand Down Expand Up @@ -169,7 +167,6 @@ Add the following definition for the ``db`` service in the :file:`docker-compose
* `ports`_: Ports to expose on the container (``<host>:<container>``).
* `env_file`_: A file containing the environment variables to create for the container. Environment variables often contain sensitive information that should not be committed with the :file:`docker-compose.yml`. The :file:`db.env` file will be created in Step 7.
* `volumes`_: Mount directories from the host into the container or create Docker-managed named volumes. Volumes allow you to preserve data that would otherwise be lost when the container is removed. The syntax shown here is: ``<host_dir>:<container_dir>``.

* ``./data/db:/var/lib/postgresql/data``: The primary data directory for PostgreSQL database. This directory contains the data and configuration files for the database.

4. Define THREDDS Service
Expand All @@ -184,7 +181,7 @@ Add the following definition for the ``thredds`` service in the :file:`docker-co
.. code-block:: yaml
thredds:
image: unidata/thredds-docker:latest
image: unidata/thredds-docker:5.5
restart: always
networks:
- "internal"
Expand All @@ -207,7 +204,6 @@ Add the following definition for the ``thredds`` service in the :file:`docker-co
* `ports`_: Ports to expose on the container (``<host>:<container>``).
* `env_file`_: A file containing the environment variables to create for the container. Environment variables often contain sensitive information that should not be committed with the :file:`docker-compose.yml`. The :file:`thredds.env` file will be created in Step 7.
* `volumes`_: Mount directories from the host into the container or create Docker-managed named volumes. Volumes allow you to preserve data that would otherwise be lost when the container is removed. The syntax shown here is: ``<host_dir>:<container_dir>``.

* ``./data/thredds/:/usr/local/tomcat/content/thredds``: Main content directory for THREDDS. This directory will contain the data and XML configuration files for THREDDS.
* ``./logs/thredds/tomcat/:/usr/local/tomcat/logs/``: Logs for Tomcat, the server running THREDDS.
* ``./logs/thredds/thredds/:/usr/local/tomcat/content/thredds/logs/``: Logs for THREDDS.
Expand Down Expand Up @@ -278,7 +274,6 @@ Add the following definition for the ``web`` service in the :file:`docker-compos
* `ports`_: Ports to expose on the container (``<host>:<container>``).
* `env_file`_: A file containing the environment variables to create for the container. Environment variables often contain sensitive information that should not be committed with the :file:`docker-compose.yml`. The :file:`web.env` file will be created in Step 7.
* `volumes`_: Mount directories from the host into the container or create Docker-managed named volumes. Volumes allow you to preserve data that would otherwise be lost when the container is removed. The syntax shown here is: ``<host_dir>:<container_dir>``.

* ``./data/tethys:/var/lib/tethys_persist``: Main content directory for Tethys Platform. This directory contains the app workspaces, static files, and configuration files including the :file:`portal_config.yml`.
* ``./log/tethys:/var/log/tethys``: Logs for Tethys.

Expand All @@ -290,19 +285,16 @@ Each of the Docker containers can be configured through the environment variable
With that said, certain environment variables need to be defined for the custom Tethys Portal Compose recipe to work. This is often the case, so another pattern that is used is to provide default ``.env`` files that users can copy and modify. The default ``.env`` files are committed to the repository and the copies with sensitive information are not. In this step you will create the default ``.env`` files referenced in the `env_file`_ sections of the :file:`docker-compose.yml`.

a. Create a new :file:`env` directory in the :file:`tethys_portal_docker` directory for storing the ``.env`` files:

.. code-block:: bash
mkdir env
b. Create three new empty files in the :file:`env` directory with the same names as those referenced in the `env_file`_ sections of the :file:`docker-compose.yml`:

.. code-block:: bash
touch env/db.env env/thredds.env env/web.env
c. Add the following contents to each ``.env`` file:

**db.env**

.. code-block:: docker
Expand Down Expand Up @@ -357,6 +349,8 @@ c. Add the following contents to each ``.env`` file:

.. code-block:: docker
TERM=xterm
# Domain name of server should be first in the list if multiple entries added
ALLOWED_HOSTS="\"[localhost]\""
Expand Down Expand Up @@ -463,22 +457,19 @@ Update the contents of the README with instructions for using the repository and
The contents of the :file:`data`, :file:`logs`, and :file:`keys` directories should not be committed into the Git repository because they contain large amounts of instance-specific data and sensitive information.

a. Create a :file:`.gitignore` file:

.. code-block:: bash
touch .gitignore
b. Add the following contents to the :file:`.gitignore` file to omit the contents of these directories from being tracked:

.. code-block:: text
data/
keys/
logs/
c. Stage changes and commit the changes as follows:

.. code-block:: bash
git add .
Expand Down
4 changes: 2 additions & 2 deletions docs/installation/production/docker/dockerfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Please ensure you have the following prerequisites before continuing:
Project Setup
=============

Before you can start creating the :file:`Dockerfile` there is some setup that needs to be completed. This includes creating a folder to house all of the artifacts that you will use for the Docker build and acquiring the source code for the apps that will be installed in the Tethys Portal. It will also include setting up a Git repository. An important part of creating Docker projects is knowing how to properly version it version control software, so this tutorial will instruct you which files to commit. Follow these instructions to set up the Docker project.
Before you can start creating the :file:`Dockerfile` there is some setup that needs to be completed. This includes creating a folder to house all of the artifacts that you will use for the Docker build and acquiring the source code for the apps that will be installed in the Tethys Portal. It will also include setting up a Git repository. An important part of creating Docker projects is knowing how to properly version it with version control software, so this tutorial will instruct you which files to commit. Follow these instructions to set up the Docker project.

1. Create New Directory
-----------------------
Expand Down Expand Up @@ -224,7 +224,7 @@ d. Add the following lines to the Dockefile to add the images to the container i

The `RUN <https://docs.docker.com/engine/reference/builder/#run>`_ instruction can be used to run any command during the build. For long commands, the ``\`` (backslash) character can be used to continue a ``RUN`` instruction on the next line for easier readability.

For this image we need to run the ``tethys install`` command for each of our apps. The trickiest part about doing this in a Docker build is activating the ``tethys`` environment, which must be done for each ``RUN`` call. Add the following lines to the :file:`Dockerfile`:
For this image we need to run the ``tethys install`` command for each of our apps. The trickiest part about doing this in a Docker build is activating the ``tethys`` environment, which must be done before installing the apps. Add the following lines to the :file:`Dockerfile`:

.. code-block:: dockerfile
Expand Down
40 changes: 15 additions & 25 deletions docs/tutorials/bokeh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To leverage the Bokeh integration with Tethys you will need the ``bokeh`` and ``
- conda-forge
packages:
- bokeh
- bokeh_django
- bokeh-django
- bokeh_sampledata
pip:
Expand All @@ -79,9 +79,11 @@ Let's use Bokeh's sea temperature sample data to create a time series plot and l
from tethys_sdk.routing import handler
from .app import App
@handler(
template="bokeh_tutorial/home.html",
template=f"{App.package}/home.html",
)
def home(document):
df = sea_surface_temperature.copy()
Expand All @@ -101,7 +103,7 @@ This simple handler contains the logic for a time series plot of the sea surface

.. code-block:: html+django

{% extends "bokeh_tutorial/base.html" %}
{% extends tethys_app.package|add:"/base.html" %}

{% block app_content %}
<h1>Bokeh Integration Example</h1>
Expand All @@ -126,6 +128,9 @@ This is a simple Bokeh plot. We will now add the rest of the logic to make it an
...
@handler(
template=f"{App.package}/home.html",
)
def home(document):
df = sea_surface_temperature.copy()
source = ColumnDataSource(data=df)
Expand Down Expand Up @@ -172,27 +177,10 @@ In this example we will build on top of the ``bokeh_tutorial`` app to demonstrat

.. code-block:: yaml
# This file should be committed to your app code.
version: 1.0
# This should match the app - package name in your setup.py
name: bokeh_tutorial
requirements:
# Putting in a skip true param will skip the entire section. Ignoring the option will assume it be set to False
skip: false
conda:
channels:
- conda-forge
packages:
- bokeh
- bokeh_django
- bokeh_sampledata
- panel
- param
pip:
post:
packages:
...
- panel
- param
3. Add the following objects to a new file called ``param_model.py``.
Expand Down Expand Up @@ -287,12 +275,14 @@ The added classes depend on ``Bokeh``. The `Circle` and `NGon` classes depend o

.. code-block:: python
...
from .param_model import ShapeViewer
...
@handler(
app_package='bokeh_tutorial',
app_package=App.package,
)
def shapes(document):
viewer = ShapeViewer().panel()
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/thredds/plot_at_location.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ In this step you'll learn to use another Leaflet plugin: `Leaflet.Draw <http://l
2. Install Plotly
=================

In this step you will create a new controller that will query the dataset at the given location using the NCSS service and then build a plotly plot with the results.
In the next step you will create a new controller that will query the dataset at the given location using the NCSS service and then build a plotly plot with the results.

1. The Plotly View gizmo requires the `plotly` Python package. We'll also need `geojson` to handle the geometry data. Install `plotly` as follows running the following command in the terminal:

Expand All @@ -143,6 +143,7 @@ In this step you will create a new controller that will query the dataset at the
.. code-block:: yaml
dependencies:
...
- plotly
- goejson
Expand Down
Loading

0 comments on commit f618b8c

Please sign in to comment.