Skip to content

Commit

Permalink
Merge pull request #5 from nasa/HARMONY-388
Browse files Browse the repository at this point in the history
HARMONY-388: Better consistency across Python repos
  • Loading branch information
vinnyinverso authored Jun 8, 2021
2 parents 4964237 + 21d4163 commit 90fdb97
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 57 deletions.
17 changes: 8 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
deps

# Temporary output directories
tmp*
.DS_Store
tmp
config-*.json
config.json

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -132,5 +123,13 @@ dmypy.json
# Pyre type checker
.pyre/

# Temporary output directories
tmp*
.DS_Store
tmp
config-*.json
config.json
deps

# Pycharm IDE
.idea
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: install test lint build-image push-image build-test-image test-in-docker run-in-docker

install:
pip install -r requirements/core.txt -r requirements/dev.txt

test:
bin/test

lint:
flake8 harmony_netcdf_to_zarr

build-image:
LOCAL_SVCLIB_DIR=${LOCAL_SVCLIB_DIR} bin/build-image

push-image:
bin/push-image

build-test-image:
bin/build-test-image

test-in-docker:
LOCAL_SVCLIB_DIR=${LOCAL_SVCLIB_DIR} bin/test-in-docker

run-in-docker:
LOCAL_SVCLIB_DIR=${LOCAL_SVCLIB_DIR} bin/run-in-docker example/harmony-operation.json
68 changes: 20 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,95 +35,67 @@ and update the `.env` with the correct values.

#### Python & Project Dependencies (Optional)

If you would like to do local development outside of Docker, install Python, create a Python virtualenv,
and install the project dependencies.

If you have [pyenv](https://github.com/pyenv/pyenv) and
[pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) installed (recommended), install Python and
create a virtualenv:

$ pyenv install 3.7.4
$ pyenv virtualenv 3.7.4 harmony-ntz
$ pyenv activate harmony-ntz
$ pyenv version > .python-version

The last step above creates a local .python-version file which will be automatically activated when cd'ing into the
directory if pyenv-virtualenv has been initialized in your shell (See the pyenv-virtualenv docs linked above).
If you would like to do local development outside of Docker, install Python (3.7.4), and create a Python virtual environment.

Install project dependencies:

$ pip install -r requirements/core.txt -r requirements/dev.txt

NOTE: All steps in this README which install dependencies need to be performed while on the NASA VPN
in order to download and install the Harmony Service Lib, which is published on the
[Nexus artifact repository](https://maven.earthdata.nasa.gov/).
$ make install

### Development with Docker

If you'd rather not build the image locally (as instructed below), you can simply pull the latest image:

$ docker pull harmonyservices/netcdf-to-zarr

Some of the [Makefile](./Makefile) targets referenced below include an optional argument that allows us to use a local copy of
`harmony-service-lib-py` (which is useful for concurrent development):

$ make target-name LOCAL_SVCLIB_DIR=../harmony-service-lib-py

#### Testing & Running the Service Independently

To run unit tests, coverage reports, or run the service on a sample message _outside_ of the
entire Harmony stack, start by building new runtime and test images:

*IMPORTANT*: Be sure to do these steps in a shell in which has *not* been updated to point to
*IMPORTANT*: If Minikube is installed, be sure to do these steps in a shell in which has *not* been updated to point to
the Minikube Docker daemon. This is usually done via a shell `eval` command. Doing so will
cause tests and the service to fail due to limitations in Minikube.

$ bin/build-image
$ bin/build-test-image
$ make build-image
$ make build-test-image

Run unit tests and generate overage reports. This will mount the local directory into the
container and run the unit tests. So all tests will reflect local changes to the service.

$ bin/test-in-docker

You may be concurrently making changes to the Harmony Service Lib. To run the unit tests using
the local clone of that Harmony Service Lib and any changes made to it:

$ LOCAL_SVCLIB_DIR=../harmony-service-lib-py bin/test-in-docker
$ make test-in-docker

Finally, run the service using an example Harmony operation request
([example/harmony-operation.json](example/harmony-operation.json) as input. This will reflect
([example/harmony-operation.json](example/harmony-operation.json)) as input. This will reflect
local changes to this repo, but will not include local changes to the Harmony Service Lib.

$ bin/run-in-docker example/harmony-operation.json

To run the example and also include local Harmony Service Lib changes:

$ LOCAL_SVCLIB_DIR=../harmony-service-lib-py bin/run-in-docker example/harmony-operation.json
$ make run-in-docker

#### Testing & Running the Service in Harmony

*Without local Harmony Service Lib changes*:

Be sure your environment is pointed to the Minikube Docker daemon:
If using Minikube, be sure your environment is pointed to the Minikube Docker daemon:

$ eval $(minikube docker-env)

Build the image:

$ bin/build-image

You can now run a workflow in your local Harmony stack and it will execute using this image.

*With local Harmony Service Lib changes*:

To run this service in Harmony *with* a local copy of the Service Lib, build
the image, but specify the location of the local Harmony Service Lib clone:

$ LOCAL_SVCLIB_DIR=../harmony-service-lib-py bin/build-image
$ make build-image

You can now run a workflow in your local Harmony stack and it will execute using this image.
Note that this also means that the image needs to be rebuilt (using the same command) to
include any further changes to the Harmony Service Lib or this service.

### Development without Docker

#### Testing & running the Service Independently

Run tests with coverage reports:

$ bin/test
$ make test

Run an example:

Expand Down
6 changes: 6 additions & 0 deletions example/dotenv
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ USE_LOCALSTACK=true

# The shared secret key used for encrypting & decrypting data in the Harmony message
SHARED_SECRET_KEY=_THIS_IS_MY_32_CHARS_SECRET_KEY_

# Set to 'true' if running Docker in Docker and the docker daemon is somewhere other than the current context
DIND=true

# Indicates where docker commands should find the docker daemon
DOCKER_DAEMON_ADDR=host.docker.internal:2375

0 comments on commit 90fdb97

Please sign in to comment.