-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAS-2254: wrap gridding code with harmony_service (#3)
- Loading branch information
1 parent
df84655
commit f52ec3a
Showing
33 changed files
with
817 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
**/__pycache__ | ||
/.coverage | ||
/reports/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Contributing to SMAP-L2-Gridding-Service | ||
|
||
Thanks for contributing! | ||
|
||
## Making Changes | ||
|
||
To allow us to incorporate your changes, please use the | ||
[Fork-and-Pull](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/about-collaborative-development-models#fork-and-pull-model) | ||
development model: | ||
|
||
1. Fork this repository to your personal account. | ||
2. Create a branch and make your changes. | ||
3. Test the changes locally/in your personal fork. | ||
4. Submit a pull request to open a discussion about your proposed changes. | ||
5. The maintainers will talk with you about it and decide to merge or request | ||
additional changes. | ||
|
||
For larger items, consider contacting the maintainers first to coordinate | ||
development efforts. | ||
|
||
## Commits | ||
|
||
Our ticketing and CI/CD tools are configured to sync statuses amongst each | ||
other. Commits play an important role in this process. Please start all commits | ||
with the Jira ticket number associated with your feature, task, or bug. All | ||
commit messages should follow the format | ||
"[Jira Project]-XXXX - [Your commit message here]" | ||
|
||
## General coding practices: | ||
|
||
This repository adheres to Python coding style recommendations from | ||
[PEP8](https://peps.python.org/pep-0008/). Additionally, type hints are | ||
required in all function signatures. | ||
|
||
When adding or updating functionality, please ensure unit tests are added to | ||
an appropriate module in the `tests` sub directories, which cover each branch | ||
of the code. | ||
|
||
## Disclaimer | ||
|
||
SMAP-L2-Gridding-Service maintainers will review all pull requests submitted. Only requests that | ||
meet the standard of quality set forth by existing code, following the patterns | ||
set forth by existing code, and adhering to existing design patterns will be | ||
considered and/or accepted. | ||
|
||
For general tips on open source contributions, see | ||
[Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
############################################################################### | ||
# | ||
# Build a Docker image of the Harmony-SMAP-L2-Gridder service. | ||
# | ||
############################################################################### | ||
|
||
image="ghcr.io/nasa/harmony-smap-l2-gridder" | ||
|
||
# Retrieve the tag from the script arguments, or default to "latest". Bamboo | ||
# will pass the contents of `docker/service_version.txt` as this argument, | ||
# which contains a semantic version number. | ||
# | ||
tag=${1:-latest} | ||
|
||
|
||
# Remove old versions of: ghcr.io/nasa/harmony-smap-l2-gridder and | ||
# ghcr.io/nasa/harmony-smap-l2-gridder-test images | ||
./bin/clean-images | ||
|
||
# Build the image | ||
# This command tags the image with two tags: | ||
# - The one supplied as a script argument. Bamboo will provide the semantic | ||
# version number from `docker/service_version.txt`. | ||
# - "latest", so the test Dockerfile can use the service image as a base image. | ||
# | ||
docker build -t ${image}:${tag} -t ${image}:latest -f docker/service.Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
############################################################################### | ||
# | ||
# Build a Docker container to run the test suite for the SMAP-L2-Gridding-Service | ||
# | ||
# To build the ghcr.io/nasa/harmony-smap-l2-gridder-test image, the | ||
# ghcr.io/nasa/harmony-smap-l2-gridder image must also be present | ||
# locally, as it is used as the base image in `docker/tests.Dockerfile`. | ||
# | ||
############################################################################### | ||
|
||
image="ghcr.io/nasa/harmony-smap-l2-gridder-test" | ||
tag=${1:-latest} | ||
|
||
|
||
# Look for old version of image and remove | ||
old=$(docker images | grep "$image" | grep "$tag" | awk '{print $3}') | ||
if [ ! -z "$old" ] && [ "$2" != "--no-delete" ]; then | ||
docker rmi "$old" | ||
fi | ||
|
||
# Build the image | ||
docker build -t ${image}:${tag} -f docker/tests.Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
############################################################################### | ||
# | ||
# remove all images containing the string | ||
# "ghcr.io/nasa/harmony-smap-l2-gridder" and remove them. | ||
# This is used for clean-up after development. | ||
# | ||
############################################################################### | ||
remove_image_by_name() { | ||
echo "Removing images for: $1" | ||
matching_images=$(docker images --filter reference="$1" --format="{{.ID}}") | ||
|
||
if [ ! -z "${matching_images}" ]; then | ||
docker rmi "${matching_images}" | ||
fi | ||
} | ||
|
||
image_base_name="ghcr.io/nasa/harmony-smap-l2-gridder" | ||
|
||
# First remove test images: | ||
remove_image_by_name "${image_base_name}-test" | ||
|
||
# Next remove service images: | ||
remove_image_by_name "${image_base_name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
############################################################################### | ||
# | ||
# Execute the ghcr.io/nasa/harmony-smap-l2-gridder-test Docker image | ||
# | ||
############################################################################### | ||
|
||
set -ex | ||
|
||
# Remove cached bytecode Python files, to ensure latest code is used | ||
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf | ||
|
||
# Make the directory into which XML format test reports will be saved | ||
mkdir -p reports/test-reports | ||
|
||
# Make the directory into which coverage reports will be saved | ||
mkdir -p reports/coverage | ||
|
||
# Run the tests in a Docker container with mounted volumes for XML report | ||
# output and test coverage reporting | ||
docker run --rm \ | ||
-v $(pwd)/reports/test-reports:/home/reports/test-reports \ | ||
-v $(pwd)/reports/coverage:/home/reports/coverage \ | ||
ghcr.io/nasa/harmony-smap-l2-gridder-test "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
############################################################################### | ||
# | ||
# Service image for ghcr.io/nasa/harmony-smap-l2-gridder | ||
|
||
# Harmony-SMAP-L2-Gridder backend service that transforms L2G (gridded | ||
# trajectory) data into actual gridded data. | ||
# | ||
# This image installs dependencies via Pip. The service code is then copied | ||
# into the Docker image. | ||
# | ||
############################################################################### | ||
FROM python:3.12-slim-bookworm | ||
|
||
WORKDIR "/home" | ||
|
||
RUN apt-get update | ||
|
||
# Install Pip dependencies | ||
COPY pip_requirements.txt /home/ | ||
|
||
RUN pip install --no-input --no-cache-dir \ | ||
-r pip_requirements.txt | ||
|
||
# Copy service code. | ||
COPY ./harmony_service harmony_service | ||
COPY ./smap_l2_gridder smap_l2_gridder | ||
|
||
# Configure a container to be executable via the `docker run` command. | ||
ENTRYPOINT ["python", "-m", "harmony_service"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
############################################################################### | ||
# | ||
# Test image for the SMAP-L2-Gridding-Service. This test image uses the main | ||
# service image as a base layer for the tests. This ensures that the contents | ||
# of the service image are tested, preventing discrepancies between the service | ||
# and test environments. | ||
############################################################################### | ||
FROM ghcr.io/nasa/harmony-smap-l2-gridder | ||
|
||
# Install additional Pip requirements (for testing) | ||
COPY tests/pip_test_requirements.txt . | ||
|
||
RUN pip install --no-input --no-cache-dir \ | ||
-r pip_test_requirements.txt | ||
|
||
# Copy test directory containing Python unittest suite, test data and utilities | ||
COPY ./tests tests | ||
|
||
# Configure a container to be executable via the `docker run` command. | ||
ENTRYPOINT ["/home/tests/run_tests.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Initialize the harmony_service package.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Run the Harmony-SMAP-L2-Gridder via the Harmony CLI.""" | ||
|
||
from argparse import ArgumentParser | ||
from sys import argv | ||
|
||
from harmony_service_lib import is_harmony_cli, run_cli, setup_cli | ||
|
||
from harmony_service.adapter import SMAPL2GridderAdapter | ||
from harmony_service.exceptions import SERVICE_NAME | ||
|
||
|
||
def main(arguments: list[str]): | ||
"""Parse command line arguments and invoke the appropriate method.""" | ||
parser = ArgumentParser(prog=SERVICE_NAME, description='Run SMAP L2 Gridder.') | ||
|
||
setup_cli(parser) | ||
harmony_arguments, _ = parser.parse_known_args(arguments[1:]) | ||
|
||
if is_harmony_cli(harmony_arguments): | ||
run_cli(parser, harmony_arguments, SMAPL2GridderAdapter) | ||
else: | ||
parser.error('Only --harmony CLIs are supported') | ||
|
||
|
||
if __name__ == '__main__': | ||
main(argv) |
Oops, something went wrong.