Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgarde committed Mar 7, 2024
0 parents commit e3bcdb4
Show file tree
Hide file tree
Showing 13 changed files with 781 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build

on:
push:
branches:
- '*'
tags-ignore:
- '*'
paths-ignore:
- 'pyproject.toml'
- 'bumpver.toml'

jobs:
build:
name: build, lint, and test hysds-integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install poetry
run: pip3 install poetry
- name: Install dependencies
run: poetry install
- name: Setup git user
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# -- Testing & Linting --
- name: Lint
run: |
poetry run flake8 podaac/ tests/
poetry run pylint podaac/ tests/
- name: Test
run: poetry run pytest

# -- Version Bumping --
- name: Bump alpha version
if: github.ref == 'refs/heads/develop' && github.event_name != 'workflow_dispatch'
run: |
TAG=$(bumpver show -e | awk -F= '$1 == "TAG" {print $2};')
if [ $TAG == 'final' ]; then
# Bump patch version first then append tag
bumpver update --patch --tag alpha --tag-num
else
bumpver update --tag alpha --tag-num
fi
echo "TARGET_ENV=SIT" >> $GITHUB_ENV
- name: Bump rc version
if: startsWith(github.ref, 'refs/heads/release/') && github.event_name != 'workflow_dispatch'
run: |
bumpver --tag rc --tag-num
echo "TARGET_ENV=UAT" >> $GITHUB_ENV
- name: Release version
if: github.ref == 'refs/heads/main' && github.event_name != 'workflow_dispatch'
run: bumpver --tag final

# -- Build --
- name: Build
run: scripts/build.sh
- name: Publish Docker images
run: docker image push ghcr.io/podaac/swodlr-api
166 changes: 166 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# macOS
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VS Code
.vscode/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "podaac/swodlr_hysds/schemas"]
path = podaac/swodlr_hysds/schemas
url = https://github.com/podaac/swodlr-schemas.git
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# swodlr-hysds-integration

A SWODLR integration for HySDS
14 changes: 14 additions & 0 deletions bumpver.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[bumpver]
current_version = "0.0.1"
version_pattern = "MAJOR.MINOR.PATCH[-TAGNUM]"
commit = true
tag = true
push = true

[bumpver.file_patterns]
"pyproject.toml" = [
'version = "{version}"'
]
"bumpver.toml" = [
'current_version = "{version}"',
]
6 changes: 6 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.10-alpine
ARG WHL_FILE

COPY ${WHL_FILE} .
RUN pip3 install *.whl
RUN rm *.whl
17 changes: 17 additions & 0 deletions docker/hysds-io.json.notify_swodlr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"label": "Notify SWODLR",
"params": [
{
"name": "job_id",
"from": "dataset_jpath:_source.payload_id"
},
{
"name": "status",
"from": "dataset_jpath:_source.status"
},
{
"name": "products_staged",
"from": "dataset_jpath:_source.job.job_info.metrics.products_staged"
}
]
}
27 changes: 27 additions & 0 deletions docker/job-spec.json.notify_swodlr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"command": "notify_swodlr",
"disk_usage": "5MB",
"soft_time_limit": 120,
"time_limit": 150,
"recommended_queues": ["system-jobs-queue"],
"disable_pre_builtins": true,
"disable_post_builtins": true,
"imported_worker_files": {
"$HOME/.aws": "/root/.aws:ro",
"$HOME/.swodlr": "/root/.swodlr:ro"
},
"params": [
{
"name": "job_id",
"destination": "context"
},
{
"name": "status",
"destination": "context"
},
{
"name": "products_staged",
"destination": "context"
}
]
}
42 changes: 42 additions & 0 deletions podaac/swodlr_hysds/notify_swodlr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json
from importlib import resources
from os import environ
from os.path import expanduser

import boto3
from dotenv import load_dotenv
import fastjsonschema

def notify_swodlr(context):
topic_arns = environ['SWODLR_SNS_TOPIC_ARNS'].split(',')
sns = boto3.client('sns')

update_schema = json.load(
resources.files.join_path('schemas/sds_update.json').open('r')
)

message_body = fastjsonschema.validate(update_schema, {
'job_id': context['job_id'],
'status': context['status'],
'products_staged': context['products_staged']
})

for arn in topic_arns:
sns.publish(
TopicArn=arn,
Message=json.dumps(
message_body,
separators=(',', ':'),
indent=None
)
)


def main():
load_dotenv(dotenv_path=expanduser('~/.swodlr'))
context = json.load(open('_context.json', 'r'))
notify_swodlr(context)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions podaac/swodlr_hysds/schemas
Submodule schemas added at 3b3e1c
Loading

0 comments on commit e3bcdb4

Please sign in to comment.