tethysplatform / tethys

The Tethys Platform main Django website project repository.
http://tethysplatform.org/
BSD 2-Clause "Simplified" License
92 stars 50 forks source link

[FEATURE] Make Docker Build More Flexible #1027

Open sdc50 opened 6 months ago

sdc50 commented 6 months ago

I'd like to add several build args to the Dockerfile that will enable the Tethys Docker Image to be built in several ways. I've crated a new repository that copied the docker stuff from the Tethys repo, to explore some other options. I'd like to integrate those changes back into this repository.

Base Image

Currently the FROM image is mambaorg/micromamba:bullseye. I'd like to make this into an build arg and provide a RHEL option, like this one (https://github.com/sdc50/ubi-micromamba-docker).

ARG BASE_IMAGE=mambaorg/micromamba:bullseye

FROM ${BASE_IMAGE}

Proxy Server

Currently the proxy server is set to NGINX. Tethys supports generating configurations for Apache and Nginx. I'd like to generalize some Environment Variables that are NGINX specific and make them be PROXY_SERVER variables.

# Proxy Server Config
ENV PROXY_SERVER_SSL_CERT_FILE="${TETHYS_PERSIST}/keys/server.crt"
ENV PROXY_SERVER_SSL_KEY_FILE="${TETHYS_PERSIST}/keys/server.key"
ENV PROXY_SERVER_PORT=""
ENV USE_SSL=false
ENV RUN_PROXY_SERVER_AS_USER="root"
ENV PROXY_SERVER_PORT=""
ENV PROXY_SERVER_ADDITIONAL_DIRECTIVES=""

I would need to combine the following two versions of the tethyscore.sls:

```yaml Generate_NGINX_Settings_TethysCore: cmd.run: - name: > tethys gen nginx --tethys-port {{ TETHYS_PORT }} --web-server-port {{ NGINX_PORT }} --client-max-body-size {{ CLIENT_MAX_BODY_SIZE }} --overwrite - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/setup_complete" ];" Generate_NGINX_Service_TethysCore: cmd.run: - name: tethys gen nginx_service --overwrite - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/setup_complete" ];" ``` ```yaml Generate_Apache_Settings_TethysCore: cmd.run: - name: > tethys gen apache {%- if USE_SSL %} --ssl --ssl-cert-path {{ APACHE_SSL_CERT_FILE }} --ssl-key-path {{ APACHE_SSL_KEY_FILE }} {%- endif %} --tethys-port {{ TETHYS_PORT }} {%- if PROXY_SERVER_PORT %} --web-server-port {{ PROXY_SERVER_PORT }} {%- endif %} --ip-address $(hostname -I | awk '{print $1}') --overwrite {{ PROXY_SERVER_ADDITIONAL_DIRECTIVES }} Generate_SSL_Certificate_Key_Pair_TethysCore: cmd.run: - name: > openssl req -newkey rsa:2048 -keyout {{ APACHE_SSL_KEY_FILE }} -x509 -days 365 -out {{ APACHE_SSL_CERT_FILE }} -nodes -subj "/C=US/ST=UT/L=Provo/O=Tethys Foundation/CN=localhost" && chown {{ APACHE_USER }}: {{ APACHE_SSL_KEY_FILE }} {{ APACHE_SSL_CERT_FILE }} - unless: /bin/bash -c "[ {{ USE_SSL }} == false ] || ([ -f {{ APACHE_SSL_CERT_FILE }} ] && [ -f {{ APACHE_SSL_KEY_FILE }} ]);" Generate_Apache_Service_TethysCore: cmd.run: - name: tethys gen apache_service --overwrite --run-as-user {{ RUN_PROXY_SERVER_AS_USER }} - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/setup_complete" ];" Generate_ASGI_Service_TethysCore: cmd.run: - name: > tethys gen asgi_service --asgi-processes {{ ASGI_PROCESSES }} --conda-prefix {{ CONDA_HOME }}/envs/{{ CONDA_ENV_NAME }} --micromamba --overwrite - unless: /bin/bash -c "[ -f "{{ TETHYS_PERSIST }}/setup_complete" ];" ```

Tethys Environment

1013 Implements a build arg that supports building the environment with either the full Tethys environment or the Micro-Tethys environment.

Tethys Code

The current version of the image copies the source code files from the repo. I'd also like to add a version where the conda package is used.

RUN micromamba create -n "${CONDA_ENV_NAME}" --yes -c conda-forge -c ${TETHYS_CHANNEL} \
    $(if [ "$MICRO_TETHYS" = false ]; then echo tethys-platform; else echo micro-tethys-platform; fi)=${TETHYS_VERSION} \
     python=${PYTHON_VERSION} \
 && micromamba clean --all --yes
sdc50 commented 6 months ago

With a total of 4 build args that each have 2 options:

Base Image (Debian, REHL) Proxy Server (Apache, NGINX) Tethys Environment (Full, Micro) Tethys Code (Source, Conda)

This allows for 16 unique versions of the docker to be built. I don't think our CI should build all of them, but maybe a couple of them. We can then add docs with instructions for building with other options.

swainn commented 5 months ago

The current version of the image copies the source code files from the repo. I'd also like to add a version where the conda package is used.

I'd add to this:

Python (3.9, 3.10, 3.11, 3.12) Django (4.2,5.X)