Skip to content

Commit

Permalink
Merge pull request #79 from guzman-raphael/adjust-docker-envs
Browse files Browse the repository at this point in the history
Add dev environment and update docs
  • Loading branch information
Synicix committed Feb 19, 2021
2 parents 8fa44a0 + d1cddc3 commit e6ae1bf
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 41 deletions.
1 change: 0 additions & 1 deletion .github/workflows/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
IMAGE: ${{matrix.image}}
DOCKER_CLIENT_TIMEOUT: "120"
COMPOSE_HTTP_TIMEOUT: "120"
AS_SCRIPT: "TRUE"
steps:
- uses: actions/checkout@v2
- name: Compile image
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [Unreleased]
### Added
- Docker `dev` environment that supports hot reloading.
- Documentation on setting up environments within `docker-compose` header.

### Removed
- Docker `base` environment to simplify dependencies.

## [0.1.0a5] - 2021-02-18
### Added
- List schemas method.
Expand All @@ -11,3 +19,6 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
- Read table definition method.
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
- Check dependency utility to determine child table references.

[Unreleased]: https://github.com/datajoint/pharus/compare/0.1.0a5...HEAD
[0.1.0a5]: https://github.com/datajoint/pharus/releases/tag/0.1.0a5
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ Usage and API documentation currently available within method docstrings. See Py

## Run Locally w/ Docker

- Copy a `*-docker-compose.yaml` file corresponding to your usage to `docker-compose.yaml`. This file is untracked so feel free to modify as necessary.
- Check the first comment which will provide best instruction on how to start the service.
- Copy a `*-docker-compose.yaml` file corresponding to your usage to `docker-compose.yaml`. This file is untracked so feel free to modify as necessary. Idea is to commit anything generic but system/setup dependent should go on 'your' version i.e. local UID/GID, etc.
- Check the first comment which will provide the best instruction on how to start the service; yes, it is a bit long. Note: Any of the keyword arguments prepended to the `docker-compose` command can be safely moved into a dedicated `.env` and read automatically if they are not evaluated i.e. `$(...)`. Below is a brief description of the non-evaluated environment variables:

```shell
PY_VER=3.8 # Python version: 3.6|3.7|3.8
IMAGE=djtest # Image type: djbase|djtest|djlab|djlabhub
DISTRO=alpine # Distribution: alpine|debian
AS_SCRIPT= # If 'TRUE', will not keep container alive but run tests and exit
```

> ⚠️ Deployment options currently being considered are [Docker Compose](https://docs.docker.com/compose/install/) and [Kubernetes](https://kubernetes.io/docs/tutorials/kubernetes-basics/).
Expand All @@ -31,17 +38,6 @@ Usage and API documentation currently available within method docstrings. See Py
- For development, use CLI command `pharus`. This method supports hot-reloading so probably best coupled with `pip install -e ...`.
- For production, use `gunicorn --bind 0.0.0.0:${PHARUS_PORT} pharus.server:app`.

## Run Tests for Development w/ Docker

- Create a `.env` as appropriate for your setup:
```shell
PY_VER=3.8 # Python version: 3.6|3.7|3.8
IMAGE=djtest # Image type: djbase|djtest|djlab|djlabhub
DISTRO=alpine # Distribution: alpine|debian
AS_SCRIPT= # If 'TRUE', will not keep container alive but run tests and exit
```
- Navigate to `test-docker-compose.yaml` and check first comment which will provide best instruction on how to start the service. Yes, the command is a bit long...

## Run Tests for Development w/ Pytest and Flake8

- Set `pharus` testing environment variables:
Expand Down
9 changes: 0 additions & 9 deletions docker-compose-base.yaml

This file was deleted.

13 changes: 9 additions & 4 deletions docker-compose-build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-build.yaml up --exit-code-from pharus --build
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-build.yaml up --exit-code-from pharus --build
#
# Intended for updating dependencies and docker image.
# Used to build release artifacts.
version: "2.4"
services:
pharus:
extends:
file: ./docker-compose-base.yaml
service: pharus
build:
context: .
args:
- PY_VER
- DISTRO
- IMAGE
image: datajoint/pharus:${PHARUS_VERSION}
environment:
- PHARUS_PRIVATE_KEY
- PHARUS_PUBLIC_KEY
user: ${HOST_UID}:anaconda
volumes:
- .:/main
command:
Expand Down
40 changes: 31 additions & 9 deletions docker-compose-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') docker-compose -f docker-compose-deploy.yaml up -d
# Note: You must run both commands above
# PHARUS_VERSION=0.1.0a5 docker-compose -f docker-compose-deploy.yaml pull
# PHARUS_VERSION=0.1.0a5 docker-compose -f docker-compose-deploy.yaml up -d
#
# Intended for production deployment.
# Note: You must run both commands above for minimal outage
# Make sure to add an entry into your /etc/hosts file as `127.0.0.1 fakeservices.datajoint.io`
# This serves as an alias for the domain to resolve locally.
# With this config and the configuration below in NGINX, you should be able to verify it is
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
version: "2.4"
x-net: &net
networks:
- main
services:
pharus:
extends:
file: ./docker-compose-base.yaml
service: pharus
<<: *net
image: datajoint/pharus:${PHARUS_VERSION}
# environment: # configurable values with defaults
# - PHARUS_PORT=5000
# - PHARUS_PREFIX=/
fakeservices.datajoint.io:
<<: *net
image: raphaelguzman/nginx:v0.0.15
environment:
- PHARUS_PORT=5000
- PHARUS_PREFIX=/now
- ADD_pharus_TYPE=REST
- ADD_pharus_ENDPOINT=pharus:5000
- ADD_pharus_PREFIX=/api
- HTTPS_PASSTHRU=TRUE
ports:
- "5000:5000"
- "443:443"
- "80:80"
depends_on:
pharus:
condition: service_healthy
networks:
main:
39 changes: 39 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# PY_VER=3.8 IMAGE=djbase DISTRO=alpine PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-dev.yaml up
#
# Intended for normal development. Supports hot/live reloading.
# Note: If requirements or Dockerfile change, will need to add --build flag to docker-compose.
# Make sure to add an entry into your /etc/hosts file as `127.0.0.1 fakeservices.datajoint.io`
# This serves as an alias for the domain to resolve locally.
# With this config and the configuration below in NGINX, you should be able to verify it is
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
version: "2.4"
x-net: &net
networks:
- main
services:
pharus:
<<: *net
extends:
file: ./docker-compose-build.yaml
service: pharus
environment:
- FLASK_ENV=development # enables logging to console from Flask
volumes:
- ./pharus:/opt/conda/lib/python3.8/site-packages/pharus
command: pharus
fakeservices.datajoint.io:
<<: *net
image: raphaelguzman/nginx:v0.0.15
environment:
- ADD_pharus_TYPE=REST
- ADD_pharus_ENDPOINT=pharus:5000
- ADD_pharus_PREFIX=/api
- HTTPS_PASSTHRU=TRUE
ports:
- "443:443"
- "80:80"
depends_on:
pharus:
condition: service_healthy
networks:
main:
12 changes: 7 additions & 5 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-test.yaml up --exit-code-from pharus
# Note: If requirements or Dockerfile change, will need to add --build flag
# PY_VER=3.8 IMAGE=djtest DISTRO=alpine AS_SCRIPT=FALSE PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') HOST_UID=$(id -u) docker-compose -f docker-compose-test.yaml up --exit-code-from pharus
#
# Intended for running test suite locally.
# Note: If requirements or Dockerfile change, will need to add --build flag.
version: "2.4"
x-net: &net
networks:
Expand Down Expand Up @@ -28,8 +30,8 @@ services:
- sh
- -c
- |
if [ ! -z "$${AS_SCRIPT}" ]; then
set -e
set -e
if echo "${AS_SCRIPT}" | grep -i true &>/dev/null; then
echo "------ SYNTAX TESTS ------"
PKG_DIR=/opt/conda/lib/python3.8/site-packages/pharus
flake8 $${PKG_DIR} --count --select=E9,F63,F7,F82 --show-source --statistics
Expand All @@ -39,7 +41,7 @@ services:
flake8 $${PKG_DIR} --count --max-complexity=20 --max-line-length=95 --statistics
else
echo "=== Running ==="
echo "Please see 'LNX-docker-compose.yaml' for detail on running tests."
echo "Please see 'docker-compose-test.yaml' for detail on running tests."
tail -f /dev/null
fi
depends_on:
Expand Down

0 comments on commit e6ae1bf

Please sign in to comment.