Skip to content

Commit

Permalink
Merge pull request #380 from tethysplatform/release-candidate21
Browse files Browse the repository at this point in the history
Release Candidate for 2.1.0
  • Loading branch information
swainn authored Jan 3, 2019
2 parents 2311f47 + 7b28b88 commit 813fa1b
Show file tree
Hide file tree
Showing 431 changed files with 27,195 additions and 4,943 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ docs/_build
tethys_gizmos/static/tethys_gizmos/less/bower_components/*
.coverage
tests/coverage_html_report
.*.swp
.DS_Store
29 changes: 29 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
image: docker:git

stages:
- build

before_script:
# Set up ssh-agent for use when checking out other repos
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" > key
- chmod 600 key
- ssh-add key
- ssh-add -l
# Add known host keys
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'

build:
stage: build
script:
# Docker Stuff
- docker build --squash -t $CI_REGISTRY_IMAGE/tethyscore:$CI_COMMIT_TAG -t $CI_REGISTRY_IMAGE/tethyscore:latest .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE/tethyscore:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE/tethyscore:latest
tags:
- docker
only:
- tags
5 changes: 5 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters:
flake8:
max-line-length: 120
fixer: true
exclude: .git,build,dist,__pycache__,.eggs,*.egg-info
57 changes: 57 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
language: c

env:
- PYTHON_VERSION="2"
- PYTHON_VERSION="3"

# Setting sudo to false opts in to Travis-CI container-based builds.
sudo: false

# Turn off email notifications
notifications:
email: false

os:
- linux
- osx

install:
- cd ..
- mv tethys src
- bash ./src/scripts/install_tethys.sh -h
- bash ./src/scripts/install_tethys.sh --partial-tethys-install mesdiat -t $PWD --python-version $PYTHON_VERSION

# activate conda environment
- export PATH="$PWD/miniconda/bin:$PATH"
- source activate tethys
- conda list

# start database server
- pg_ctl -U postgres -D "${TETHYS_DB_DIR}/data" -l "${TETHYS_DB_DIR}/logfile" start -o "-p ${TETHYS_DB_PORT}"

# generate new settings.py file with tethys_super user for tests
- rm ./src/tethys_portal/settings.py
- tethys gen settings --db-username tethys_super --db-password pass --db-port ${TETHYS_DB_PORT}

# install test dependencies
- pip install python-coveralls
- pip install -e $TETHYS_HOME/src/[tests]

# install test apps and extensions
- pushd ./src/tests/extensions/tethysext-test_extension
- python setup.py develop
- popd

- pushd ./src/tests/apps/tethysapp-test_app
- python setup.py develop
- popd

# command to run tests
script:
- tethys test -c -u

# generate test coverage information
after_success:
- ls -al
- coveralls
124 changes: 124 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Use an official Python runtime as a parent image
FROM python:2-slim-stretch

###############
# ENVIRONMENT #
###############
ENV TETHYS_HOME="/usr/lib/tethys" \
TETHYS_PORT=80 \
TETHYS_PUBLIC_HOST="127.0.0.1" \
TETHYS_DB_USERNAME="tethys_default" \
TETHYS_DB_PASSWORD="pass" \
TETHYS_DB_HOST="172.17.0.1" \
TETHYS_DB_PORT=5432 \
TETHYS_SUPER_USER="" \
TETHYS_SUPER_USER_EMAIL="" \
TETHYS_SUPER_USER_PASS=""

# Misc
ENV ALLOWED_HOSTS="['127.0.0.1', 'localhost']" \
BASH_PROFILE=".bashrc" \
CONDA_HOME="${TETHYS_HOME}/miniconda" \
CONDA_ENV_NAME=tethys \
MINICONDA_URL="https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" \
PYTHON_VERSION=2 \
UWSGI_PROCESSES=10 \
CLIENT_MAX_BODY_SIZE="75M"

#########
# SETUP #
#########
RUN mkdir -p "${TETHYS_HOME}/src"
WORKDIR ${TETHYS_HOME}

# Speed up APT installs
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup \
; echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache

# Install APT packages
RUN apt-get update && apt-get -y install wget gnupg2 \
&& wget -O - https://repo.saltstack.com/apt/debian/9/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add - \
&& echo "deb http://repo.saltstack.com/apt/debian/9/amd64/latest stretch main" > /etc/apt/sources.list.d/saltstack.list
RUN apt-get update && apt-get -y install bzip2 git nginx gcc salt-minion procps pv
RUN rm -f /etc/nginx/sites-enabled/default

# Install Miniconda
RUN wget ${MINICONDA_URL} -O "${TETHYS_HOME}/miniconda.sh" \
&& bash ${TETHYS_HOME}/miniconda.sh -b -p "${CONDA_HOME}"

# Setup Conda Environment
ADD environment_py2.yml ${TETHYS_HOME}/src/
WORKDIR ${TETHYS_HOME}/src
RUN ${CONDA_HOME}/bin/conda env create -n "${CONDA_ENV_NAME}" -f "environment_py${PYTHON_VERSION}.yml"

###########
# INSTALL #
###########
# ADD files from repo
ADD resources ${TETHYS_HOME}/src/resources/
ADD templates ${TETHYS_HOME}/src/templates/
ADD tethys_apps ${TETHYS_HOME}/src/tethys_apps/
ADD tethys_compute ${TETHYS_HOME}/src/tethys_compute/
ADD tethys_config ${TETHYS_HOME}/src/tethys_config/
ADD tethys_gizmos ${TETHYS_HOME}/src/tethys_gizmos/
ADD tethys_portal ${TETHYS_HOME}/src/tethys_portal/
ADD tethys_sdk ${TETHYS_HOME}/src/tethys_sdk/
ADD tethys_services ${TETHYS_HOME}/src/tethys_services/
ADD README.rst ${TETHYS_HOME}/src/
ADD *.py ${TETHYS_HOME}/src/

# Remove any apps that may have been installed in tethysapp
RUN rm -rf ${TETHYS_HOME}/src/tethys_apps/tethysapp \
; mkdir -p ${TETHYS_HOME}/src/tethys_apps/tethysapp
ADD tethys_apps/tethysapp/__init__.py ${TETHYS_HOME}/src/tethys_apps/tethysapp/

# Run Installer
RUN /bin/bash -c '. ${CONDA_HOME}/bin/activate ${CONDA_ENV_NAME} \
; python setup.py develop \
; conda install -c conda-forge uwsgi -y'
RUN mkdir ${TETHYS_HOME}/workspaces ${TETHYS_HOME}/apps ${TETHYS_HOME}/static

# Add static files
ADD static ${TETHYS_HOME}/src/static/

# Generate Inital Settings Files
RUN /bin/bash -c '. ${CONDA_HOME}/bin/activate ${CONDA_ENV_NAME} \
; tethys gen settings --production --allowed-host "${ALLOWED_HOST}" --db-username ${TETHYS_DB_USERNAME} --db-password ${TETHYS_DB_PASSWORD} --db-port ${TETHYS_DB_PORT} --overwrite \
; sed -i -e "s:#TETHYS_WORKSPACES_ROOT = .*$:TETHYS_WORKSPACES_ROOT = \"/usr/lib/tethys/workspaces\":" ${TETHYS_HOME}/src/tethys_portal/settings.py \
; tethys gen nginx --overwrite \
; tethys gen uwsgi_settings --overwrite \
; tethys gen uwsgi_service --overwrite \
; tethys manage collectstatic'

# Give NGINX Permission
RUN export NGINX_USER=$(grep 'user .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}') \
; find ${TETHYS_HOME} ! -user ${NGINX_USER} -print0 | pv | xargs -0 -I{} chown ${NGINX_USER}: {}

############
# CLEAN UP #
############
RUN apt-get -y remove wget gcc gnupg2 \
; apt-get -y autoremove \
; apt-get -y clean

#########################
# CONFIGURE ENVIRONMENT#
#########################
ENV PATH ${CONDA_HOME}/miniconda/envs/tethys/bin:$PATH
VOLUME ["${TETHYS_HOME}/workspaces", "${TETHYS_HOME}/keys"]
EXPOSE 80

###############*
# COPY IN SALT #
###############*
ADD docker/salt/ /srv/salt/
ADD docker/run.sh ${TETHYS_HOME}/

########
# RUN! #
########
WORKDIR ${TETHYS_HOME}
# Create Salt configuration based on ENVs
CMD bash run.sh
HEALTHCHECK --start-period=240s \
CMD ps $(cat $(grep 'pid .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}')) > /dev/null && ps $(cat $(grep 'pidfile2: .*' src/tethys_portal/tethys_uwsgi.yml | awk '{print $2}')) > /dev/null;
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Tethys Platform
===============
.. image:: https://travis-ci.org/tethysplatform/tethys.svg?branch=master
:target: https://travis-ci.org/tethysplatform/tethys

.. image:: https://coveralls.io/repos/github/tethysplatform/tethys/badge.svg
:target: https://coveralls.io/github/tethysplatform/tethys


.. image:: https://readthedocs.org/projects/tethys-platform/badge/?version=stable
:target: http://docs.tethysplatform.org/en/stable/?badge=stable
:alt: Documentation Status

Tethys Platform provides both a development environment and a hosting environment for water resources web apps.

Expand Down
87 changes: 87 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Docker Support Files

This project houses the docker file and scripts needed to make usable docker image.

### Environment

| Argument | Description |Phase| Default |
|-----------------------|-----------------------------|-----|-------------------------|
|ALLOWED_HOSTS | Django Setting |Run |['127.0.0.1', 'localhost']|
|BASH_PROFILE | Where to create aliases |Run |.bashrc |
|CONDA_HOME | Path to Conda Home Dir |Build|${TETHYS_HOME}/miniconda”|
|CONDA_ENV_NAME | Name of Conda environ |Build|tethys |
|MINICONDA_URL | URL of conda install script |Build|https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh”|
|PYTHON_VERSION | Version of Python to use |Build|2 |
|TETHYS_HOME | Path to Tethys Home Dir |Build|/usr/lib/tethys |
|TETHYS_PORT | Port for external web access|Run |80 |
|TETHYS_PUBLIC_HOST | Public host and port |Run |127.0.0.1 |
|TETHYS_DB_USERNAME | Postgres connection username|Run |tethys_default |
|TETHYS_DB_PASSWORD | Postgres connection password|Run |pass |
|TETHYS_DB_HOST | Postgres connection address |Run |172.17.0.1 |
|TETHYS_DB_PORT | Postgres connection Port |Run |5432 |
|TETHYS_SUPER_USER | Default superuser username |Run |"" |
|TETHYS_SUPER_USER_EMAIL| Default superuser email |Run |“” |
|TETHYS_SUPER_USER_PASS | Default superuser password |Run |"" |
|UWSGI_PROCESSES | Number of uwsgi processes |Run |10 |
|CLIENT_MAX_BODY_SIZE | Maximum size of file uploads|Run |75M |

### Building the Docker
To build the docker use the following commands in the terminal after
pulling the latest source code:

1. Make sure that there isn't already a docker container or docker
images with the desired name
```
> docker rm tethyscore
> docker rmi tethyscore
```

2. Build a new docker with the desired name and tag
```
> docker build -t tethyscore:latest
```
You can also use build arguments in this to change certain features
that you may find useful, such as the branch, and the configuration

Use the following syntax with arguments listed in the table

```
> docker build [--build-arg ARG=VAL] -t tethyscore:latest
```

| Argument | Description | Default |
|--------------------------|---------------------------|------------------------|
|TETHYSBUILD_BRANCH | Tethys branch to be used | release |
|TETHYSBUILD_PY_VERSION | Version of python | 2 |
|TETHYSBUILD_TETHYS_HOME | Path to Tethys home dir | /usr/lib/tethys |
|TETHYSBUILD_CONDA_HOME | Path to Conda home dir | /usr/lib/tethys/conda/ |
|TETHYSBUILD_CONDA_ENV_NAME| Tethys environment name | tethys |

### Running the docker
To run the docker you can use the following flags

use the following flag with the arguments listed in the table. (NOTE:
args in the build arg table can be used here as well)

```
-e TETHYSBUILD_CONDA_ENV='tethys'
```

| Argument | Description | Default |
|--------------------------|----------------------------|---------------|
|TETHYSBUILD_ALLOWED_HOST | Django Allowed Hosts | 127.0.0.1 |
|TETHYSBUILD_DB_USERNAME | Database Username | tethys_default|
|TETHYSBUILD_DB_PASSWORD | Password for Database | pass |
|TETHYSBUILD_DB_HOST | IPAddress for Database host| 127.0.0.1 |
|TETHYSBUILD_DB_PORT | Port on Database host | 5432 |
|TETHYSBUILD_SUPERUSER | Tethys Superuser | tethys_super |
|TETHYSBUILD_SUPERUSER_PASS| Tethys Superuser Password | admin |

Example of Command:
```
> docker run -p 127.0.0.1:8000:8000 --name tethyscore \
-e TETHYSBUILD_CONDA_ENV='tethys' -e TETHYSBUILD_CONFIG='develop' \
-e TETHYSBUILD_DB_USERNAME='tethys_super' -e TETHYSBUILD_DB_PASSWORD='3x@m9139@$$' \
-e TETHYSBUILD_DB_PORT='5432' TETHYSBUILD_SUPERUSER='admin' \
-e TETHYSBUILD_SUPERUSER_PASS='admin' tethyscore
```
35 changes: 35 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

echo_status() {
local args="${@}"
tput setaf 4
tput bold
echo -e "- $args"
tput sgr0
}

echo_status "Starting up..."

# Set extra ENVs
export NGINX_USER=$(grep 'user .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}')
export NGINX_PIDFILE=$(grep 'pid .*;' /etc/nginx/nginx.conf | awk '{print $2}' | awk -F';' '{print $1}')
export UWSGI_PIDFILE=$(grep 'pidfile2: .*' src/tethys_portal/tethys_uwsgi.yml | awk '{print $2}')

# Create Salt Config
echo "file_client: local" > /etc/salt/minion
echo "postgres.host: '${TETHYS_DB_HOST}'" >> /etc/salt/minion
echo "postgres.port: '${TETHYS_DB_PORT}'" >> /etc/salt/minion
echo "postgres.user: '${TETHYS_DB_USERNAME}'" >> /etc/salt/minion
echo "postgres.pass: '${TETHYS_DB_PASSWORD}'" >> /etc/salt/minion
echo "postgres.bins_dir: '${CONDA_HOME}/envs/${CONDA_ENV_NAME}/bin'" >> /etc/salt/minion

# Apply States
echo_status "Enforcing start state... (This might take a bit)"
salt-call --local state.apply
echo_status "Fixing permissions"
find ${TETHYS_HOME} ! -user ${NGINX_USER} -print0 | xargs -0 -I{} chown ${NGINX_USER}: {}
echo_status "Done!"

# Watch Logs
echo_status "Watching logs"
tail -qF /var/log/nginx/* /var/log/uwsgi/*
14 changes: 14 additions & 0 deletions docker/salt/run.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% set TETHYS_HOME = salt['environ.get']('TETHYS_HOME') %}
{% set NGINX_USER = salt['environ.get']('NGINX_USER') %}

uwsgi:
cmd.run:
- name: {{ TETHYS_HOME }}/miniconda/envs/tethys/bin/uwsgi --yaml {{ TETHYS_HOME}}/src/tethys_portal/tethys_uwsgi.yml --uid {{ NGINX_USER }} --gid {{ NGINX_USER }} --enable-threads
- bg: True
- ignore_timeout: True

nginx:
cmd.run:
- name: nginx -g 'daemon off;'
- bg: True
- ignore_timeout: True
Loading

0 comments on commit 813fa1b

Please sign in to comment.