Skip to content

Commit e6ae1bf

Browse files
authored
Merge pull request #79 from guzman-raphael/adjust-docker-envs
Add dev environment and update docs
2 parents 8fa44a0 + d1cddc3 commit e6ae1bf

File tree

8 files changed

+106
-41
lines changed

8 files changed

+106
-41
lines changed

.github/workflows/development.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jobs:
4242
IMAGE: ${{matrix.image}}
4343
DOCKER_CLIENT_TIMEOUT: "120"
4444
COMPOSE_HTTP_TIMEOUT: "120"
45-
AS_SCRIPT: "TRUE"
4645
steps:
4746
- uses: actions/checkout@v2
4847
- name: Compile image

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

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

5+
## [Unreleased]
6+
### Added
7+
- Docker `dev` environment that supports hot reloading.
8+
- Documentation on setting up environments within `docker-compose` header.
9+
10+
### Removed
11+
- Docker `base` environment to simplify dependencies.
12+
513
## [0.1.0a5] - 2021-02-18
614
### Added
715
- List schemas method.
@@ -11,3 +19,6 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
1119
- Read table definition method.
1220
- Support for DataJoint attribute types: `varchar`, `int`, `float`, `datetime`, `date`, `time`, `decimal`, `uuid`.
1321
- Check dependency utility to determine child table references.
22+
23+
[Unreleased]: https://github.com/datajoint/pharus/compare/0.1.0a5...HEAD
24+
[0.1.0a5]: https://github.com/datajoint/pharus/releases/tag/0.1.0a5

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ Usage and API documentation currently available within method docstrings. See Py
2020

2121
## Run Locally w/ Docker
2222

23-
- 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.
24-
- Check the first comment which will provide best instruction on how to start the service.
23+
- 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.
24+
- 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:
25+
26+
```shell
27+
PY_VER=3.8 # Python version: 3.6|3.7|3.8
28+
IMAGE=djtest # Image type: djbase|djtest|djlab|djlabhub
29+
DISTRO=alpine # Distribution: alpine|debian
30+
AS_SCRIPT= # If 'TRUE', will not keep container alive but run tests and exit
31+
```
2532

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

34-
## Run Tests for Development w/ Docker
35-
36-
- Create a `.env` as appropriate for your setup:
37-
```shell
38-
PY_VER=3.8 # Python version: 3.6|3.7|3.8
39-
IMAGE=djtest # Image type: djbase|djtest|djlab|djlabhub
40-
DISTRO=alpine # Distribution: alpine|debian
41-
AS_SCRIPT= # If 'TRUE', will not keep container alive but run tests and exit
42-
```
43-
- 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...
44-
4541
## Run Tests for Development w/ Pytest and Flake8
4642

4743
- Set `pharus` testing environment variables:

docker-compose-base.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

docker-compose-build.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
# 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
1+
# 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
2+
#
3+
# Intended for updating dependencies and docker image.
4+
# Used to build release artifacts.
25
version: "2.4"
36
services:
47
pharus:
5-
extends:
6-
file: ./docker-compose-base.yaml
7-
service: pharus
88
build:
99
context: .
1010
args:
1111
- PY_VER
1212
- DISTRO
1313
- IMAGE
14+
image: datajoint/pharus:${PHARUS_VERSION}
15+
environment:
16+
- PHARUS_PRIVATE_KEY
17+
- PHARUS_PUBLIC_KEY
18+
user: ${HOST_UID}:anaconda
1419
volumes:
1520
- .:/main
1621
command:

docker-compose-deploy.yaml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') docker-compose -f docker-compose-deploy.yaml pull
2-
# PHARUS_VERSION=$(cat pharus/version.py | tail -1 | awk -F\' '{print $2}') docker-compose -f docker-compose-deploy.yaml up -d
3-
# Note: You must run both commands above
1+
# PHARUS_VERSION=0.1.0a5 docker-compose -f docker-compose-deploy.yaml pull
2+
# PHARUS_VERSION=0.1.0a5 docker-compose -f docker-compose-deploy.yaml up -d
3+
#
4+
# Intended for production deployment.
5+
# Note: You must run both commands above for minimal outage
6+
# Make sure to add an entry into your /etc/hosts file as `127.0.0.1 fakeservices.datajoint.io`
7+
# This serves as an alias for the domain to resolve locally.
8+
# With this config and the configuration below in NGINX, you should be able to verify it is
9+
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
410
version: "2.4"
11+
x-net: &net
12+
networks:
13+
- main
514
services:
615
pharus:
7-
extends:
8-
file: ./docker-compose-base.yaml
9-
service: pharus
16+
<<: *net
17+
image: datajoint/pharus:${PHARUS_VERSION}
18+
# environment: # configurable values with defaults
19+
# - PHARUS_PORT=5000
20+
# - PHARUS_PREFIX=/
21+
fakeservices.datajoint.io:
22+
<<: *net
23+
image: raphaelguzman/nginx:v0.0.15
1024
environment:
11-
- PHARUS_PORT=5000
12-
- PHARUS_PREFIX=/now
25+
- ADD_pharus_TYPE=REST
26+
- ADD_pharus_ENDPOINT=pharus:5000
27+
- ADD_pharus_PREFIX=/api
28+
- HTTPS_PASSTHRU=TRUE
1329
ports:
14-
- "5000:5000"
30+
- "443:443"
31+
- "80:80"
32+
depends_on:
33+
pharus:
34+
condition: service_healthy
35+
networks:
36+
main:

docker-compose-dev.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 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
2+
#
3+
# Intended for normal development. Supports hot/live reloading.
4+
# Note: If requirements or Dockerfile change, will need to add --build flag to docker-compose.
5+
# Make sure to add an entry into your /etc/hosts file as `127.0.0.1 fakeservices.datajoint.io`
6+
# This serves as an alias for the domain to resolve locally.
7+
# With this config and the configuration below in NGINX, you should be able to verify it is
8+
# running properly with a `curl https://fakeservices.datajoint.io/api/version`.
9+
version: "2.4"
10+
x-net: &net
11+
networks:
12+
- main
13+
services:
14+
pharus:
15+
<<: *net
16+
extends:
17+
file: ./docker-compose-build.yaml
18+
service: pharus
19+
environment:
20+
- FLASK_ENV=development # enables logging to console from Flask
21+
volumes:
22+
- ./pharus:/opt/conda/lib/python3.8/site-packages/pharus
23+
command: pharus
24+
fakeservices.datajoint.io:
25+
<<: *net
26+
image: raphaelguzman/nginx:v0.0.15
27+
environment:
28+
- ADD_pharus_TYPE=REST
29+
- ADD_pharus_ENDPOINT=pharus:5000
30+
- ADD_pharus_PREFIX=/api
31+
- HTTPS_PASSTHRU=TRUE
32+
ports:
33+
- "443:443"
34+
- "80:80"
35+
depends_on:
36+
pharus:
37+
condition: service_healthy
38+
networks:
39+
main:

docker-compose-test.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# 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
2-
# Note: If requirements or Dockerfile change, will need to add --build flag
1+
# 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
2+
#
3+
# Intended for running test suite locally.
4+
# Note: If requirements or Dockerfile change, will need to add --build flag.
35
version: "2.4"
46
x-net: &net
57
networks:
@@ -28,8 +30,8 @@ services:
2830
- sh
2931
- -c
3032
- |
31-
if [ ! -z "$${AS_SCRIPT}" ]; then
32-
set -e
33+
set -e
34+
if echo "${AS_SCRIPT}" | grep -i true &>/dev/null; then
3335
echo "------ SYNTAX TESTS ------"
3436
PKG_DIR=/opt/conda/lib/python3.8/site-packages/pharus
3537
flake8 $${PKG_DIR} --count --select=E9,F63,F7,F82 --show-source --statistics
@@ -39,7 +41,7 @@ services:
3941
flake8 $${PKG_DIR} --count --max-complexity=20 --max-line-length=95 --statistics
4042
else
4143
echo "=== Running ==="
42-
echo "Please see 'LNX-docker-compose.yaml' for detail on running tests."
44+
echo "Please see 'docker-compose-test.yaml' for detail on running tests."
4345
tail -f /dev/null
4446
fi
4547
depends_on:

0 commit comments

Comments
 (0)