generated from ghga-de/microservice-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/step1 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
e-buerger
wants to merge
34
commits into
main
Choose a base branch
from
feature/step1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
fd7fce9
create classfiles
e-buerger dad4372
adapting code for passing precommit
e-buerger f59a516
adapt code for passing precommit
e-buerger a19747c
adapt code for passing precommit
e-buerger 7588dde
implement a few functions
e-buerger 56af3aa
change type of db columns
e-buerger 566dbe1
satisfy pre-commit
e-buerger 37ae4a4
implement exec method of PythonJob
e-buerger 5529827
suppres bandit warnigns and add comments
e-buerger 5f17ab3
remove __init__.py from dao directory
e-buerger cd6f426
remove context manager
e-buerger 792ce11
fix session error in job_dao.py
e-buerger 4eeafcf
change db commands
e-buerger af7d7a9
change db commands
e-buerger a1d9e61
change db commands
e-buerger 1993d54
fix import errors by using absolute path and an __init__ file
e-buerger ae53782
remove content from exec method
e-buerger 211f348
add license headers
e-buerger 46f313e
add license headers
e-buerger c5253c3
implement PyExecSession
e-buerger 97c902a
implement unit tests for job_dao
e-buerger 6491949
satisfy pipeline
e-buerger c344999
satisfy pipeline
e-buerger d93859c
add license header
e-buerger c862e18
update README
e-buerger 37b711c
update doc strings; change job_dao functions for better unit tests
e-buerger bf7255d
change engine type
e-buerger f671e43
draft of OOP structure for python-centric jobs
e-buerger c286f37
refactor
KerstenBreuer 5ab918d
resolve merge conflicts
e-buerger 9370930
restructure modules
e-buerger e5e559b
remove unneccassery class
e-buerger 86b72dd
satisfy pipeline
e-buerger 9856610
update doc strings
e-buerger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,143 +1,35 @@ | ||
|
|
||
|
|
||
|
|
||
| # Microservice Repository Template | ||
|
|
||
| This repo is a template for creating a new microservice. | ||
|
|
||
| The directories, files, and their structure herein are recommendations | ||
| from the GHGA Dev Team. | ||
|
|
||
| ## Naming Conventions | ||
| The github repository contains only lowercase letters, numbers, and hyphens "-", | ||
| e.g.: `my-microservice` | ||
|
|
||
| The python package (and thus the source repository) contains underscores "_" | ||
| instead of hyphens, e.g.: `exec_manager` | ||
|
|
||
| The command-line script that is used to run the service, the docker repository | ||
| (published to docker hub), and the helm chart (not part of this repository) use the | ||
| same pattern as the repository name, e.g.: `my-microservice` | ||
| ## Adapt to your service | ||
| This is just a template and needs some adaption to your specific use case. | ||
|
|
||
| Please search for **"please adapt"** comments. They will indicate all locations | ||
| that need modification. Once the adaptions are in place, please remove these # | ||
| comments. | ||
|
|
||
| The following should serve as a template for the final repo's README, | ||
| please adapt it accordingly (e.g. replace all occurences of `my-microservice` or `exec_manager` with the final package name and don't forget to adapt the links): | ||
|
|
||
| --- | ||
|
|
||
| **\# please adapt the links of following badges:** | ||
|  | ||
| [](https://coveralls.io/github/ghga-de/my-microservice?branch=main) | ||
| # My-Microservice | ||
|
|
||
| A description explaining the use case of this service. | ||
|
|
||
| ## Documentation: | ||
|
|
||
| An extensive documentation can be found [here](...) (coming soon). | ||
|
|
||
| ## Quick Start | ||
| ### Installation | ||
| We recommend using the provided Docker container. | ||
|
|
||
| A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/my-microservice): | ||
| ```bash | ||
| # Please feel free to choose the version as needed: | ||
| docker pull ghga/my-microservice:<version> | ||
| ``` | ||
|
|
||
| Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile): | ||
| ```bash | ||
| # Execute in the repo's root dir: | ||
| # (Please feel free to adapt the name/tag.) | ||
| docker build -t ghga/my-microservice:<version> . | ||
| ``` | ||
|
|
||
| For production-ready deployment, we recommend using Kubernetes, however, | ||
| for simple use cases, you could execute the service using docker | ||
| on a single server: | ||
| ```bash | ||
| # The entrypoint is preconfigured: | ||
| docker run -p 8080:8080 ghga/my-microservice:<version> | ||
| ``` | ||
|
|
||
| If you prefer not to use containers, you may install the service from source: | ||
| ```bash | ||
| # Execute in the repo's root dir: | ||
| pip install . | ||
|
|
||
| # to run the service: | ||
| my-microservice | ||
| ``` | ||
|
|
||
| ### Configuration: | ||
| The [`./example-config.yaml`](./example-config.yaml) gives an overview of the available configuration options. | ||
| Please adapt it and choose one of the following options for injecting it into the service: | ||
| - specify the path to via the `exec_manager_CONFIG_YAML` env variable | ||
| - rename it to `.exec_manager.yaml` and place it into one of the following locations: | ||
| - the current working directory were you are execute the service (on unix: `./.exec_manager.yaml`) | ||
| - your home directory (on unix: `~/.exec_manager.yaml`) | ||
|
|
||
| The config yaml will be automatically parsed by the service. | ||
|
|
||
| **Important: If you are using containers, the locations refer to paths within the container.** | ||
|
|
||
| All parameters mentioned in the [`./example-config.yaml`](./example-config.yaml) | ||
| could also be set using environment variables or file secrets. | ||
|
|
||
| For naming the environment variables, just prefix the parameter name with `exec_manager_`, | ||
| e.g. for the `host` set an environment variable named `exec_manager_HOST` | ||
| (you may use both upper or lower cases, however, it is standard to define all env | ||
| variables in upper cases). | ||
|
|
||
| To using file secrets please refer to the | ||
| [corresponding section](https://pydantic-docs.helpmanual.io/usage/settings/#secret-support) | ||
| of the pydantic documentation. | ||
|
|
||
|
|
||
| ## Development | ||
| For setting up the development environment, we rely on the | ||
| [devcontainer feature](https://code.visualstudio.com/docs/remote/containers) of vscode | ||
| in combination with Docker Compose. | ||
|
|
||
| To use it, you have to have Docker Compose as well as vscode with its "Remote - Containers" extension (`ms-vscode-remote.remote-containers`) installed. | ||
| Then open this repository in vscode and run the command | ||
| `Remote-Containers: Reopen in Container` from the vscode "Command Palette". | ||
|
|
||
| This will give you a full-fledged, pre-configured development environment including: | ||
| - infrastructural dependencies of the service (databases, etc.) | ||
| - all relevant vscode extensions pre-installed | ||
| - pre-configured linting and auto-formating | ||
| - a pre-configured debugger | ||
| - automatic license-header insertion | ||
|
|
||
| Moreover, inside the devcontainer, there are two convenience commands available | ||
| (please type them in the integrated terminal of vscode): | ||
| - `dev_install` - install the service with all development dependencies, | ||
| installs pre-commit, and applies any migration scripts to the test database | ||
| (please run that if you are starting the devcontainer for the first time | ||
| or if you added any python dependencies to the [`./setup.cfg`](./setup.cfg)) | ||
| - `dev_launcher` - starts the service with the development config yaml | ||
| (located in the `./.devcontainer/` dir) | ||
|
|
||
| If you prefer not to use vscode, you could get a similar setup (without the editor specific features) | ||
| by running the following commands: | ||
| ``` bash | ||
| # Execute in the repo's root dir: | ||
| cd ./.devcontainer | ||
|
|
||
| # build and run the environment with docker-compose | ||
| docker-compose up | ||
|
|
||
| # attach to the main container: | ||
| # (you can open multiple shell sessions like this) | ||
| docker exec -it devcontainer_app_1 /bin/bash | ||
| # Execution Manager for WorkflUX | ||
|
|
||
| The execution manager manages the execution of jobs which will be runned with workflUX. There will be three types to execute a workflow: by Python, Bash or WES. | ||
|
|
||
| ## Execution Profiles | ||
| Yet, there is only the python exec profile but in future there will be the bash exec profile and the WES exec profile as well. The execution contains four steps: prepare, exec, eval, finalize. But only the exec step is required and the others are optional. | ||
| - __prepare:__ | ||
| This step will be executed before the actual workflow execution. For example there can be load required python or conda environments. | ||
| - __exec:__ | ||
| This step will execute the actual workflow and is the only required step. At the end of this step, the status of the job should be updated depending on the exit code of the job execution. | ||
| - __eval:__ | ||
| This step can evaluate the success of the workflow execution. But the exit code in the exec step should be used to set the new status (FAILED or SUCCEDED) of the job. | ||
|
|
||
| - __finalize:__ | ||
| This step will be executed at the end of the whole job execution. It can be used for cleaning up temporary files. | ||
|
|
||
|
|
||
| ### Python | ||
| For the python exec profile you have to implement the exec method from the PythonJob class. Therefore you create a new python file which contains a class that inherit the PythonJob class. Then you implement at least the exec method. | ||
| After that you have to create yaml file which looks like the file below: | ||
| ```yaml | ||
| EXEC_PROFILES: | ||
| NAMEOFEXECPROFILE: | ||
| type: python | ||
| max_retries: 2 # please adat this number | ||
| py_module: ./python_script_with_implemented_methods.py | ||
| py_class: ClassOfImplementedMethods | ||
| ``` | ||
| ```max_retries``` gives an numeric value for the maximum retries when the execution (consisting of the four steps) fails. | ||
|
|
||
| ## License | ||
| This repository is free to use and modify according to the [Apache 2.0 License](./LICENSE). |
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| # Copyright 2021 - 2022 German Cancer Research Center (DKFZ) | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Package containing DAO classes.""" |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Du kannst den UUID Typ von SQLalchemy benutzen: