Skip to content

Commit

Permalink
Merge pull request #1 from ghga-de/feature/initialize_repo-GDEV-1803
Browse files Browse the repository at this point in the history
Initialize repo (GDEV-1803)
  • Loading branch information
TheByronHimes authored Apr 6, 2023
2 parents 0eb8e45 + b511f84 commit 59f63ed
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 628 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Please only mention the non-default settings here:

language: Greek
service_instance_id: 001
kafka_servers: ["kafka:9092"]
3 changes: 1 addition & 2 deletions .devcontainer/dev_launcher
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash

# adapt to package name
my-microservice
ns
15 changes: 1 addition & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3-postgres
// Update the VARIANT arg in docker-compose.yml to pick a Python version: 3, 3.8, 3.7, 3.6
{
"name": "my-microservice",
"name": "notification-service",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
Expand All @@ -15,18 +15,6 @@
"path": "/bin/bash"
}
},
"sqltools.connections": [
{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "postgres"
}
],
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
Expand All @@ -45,7 +33,6 @@
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.rulers": [
88
],
Expand Down
59 changes: 26 additions & 33 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ services:
# [Choice] Install Node.js
INSTALL_NODE: "true"
NODE_VERSION: "lts/*"
# Please adapt to package name:
PACKAGE_NAME: "my_microservice"
PACKAGE_NAME: "ns"
# On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000.
USER_UID: 1000
USER_GID: 1000
Expand All @@ -31,40 +30,34 @@ services:

# define environment variables
environment:
# Please adapt to package name:
MY_MICROSERVICE_CONFIG_YAML: /workspace/.devcontainer/.dev_config.yaml
NS_CONFIG_YAML: /workspace/.devcontainer/.dev_config.yaml
# Used by db migration:
DB_URL: postgresql://postgres:postgres@postgresql/postgres
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)


# Please remove service dependencies that are not needed:
mongodb:
image: mongo:latest
restart: unless-stopped
volumes:
- mongo_fs:/data/db

localstack:
image: localstack/localstack
zookeeper:
image: confluentinc/cp-zookeeper:7.3.1
# used ports: 2181
environment:
SERVICES: s3
DEFAULT_REGION: eu-west-1
AWS_DEFAULT_REGION: eu-west-1
# accessible at localhost
HOSTNAME_EXTERNAL: localhost
USE_SSL: "false"
DATA_DIR: /var/lib/localstack/data
DEBUG: 1
volumes:
- type: volume
source: s3_fs
target: /var/lib/localstack
volume:
nocopy: true
# useful ports: 4566 - AWS API

volumes:
s3_fs: {}
mongo_fs: {}
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

kafka:
image: confluentinc/cp-server:7.3.1
restart: always
depends_on:
- zookeeper
# used ports: 9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
19 changes: 0 additions & 19 deletions .github/workflows/check_openapi_spec.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .mandatory_files_ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Optional list of files which are actually mandatory in the template
# but are allowed to be removed in the current repository
scripts/script_utils/fastapi_app_location.py
3 changes: 3 additions & 0 deletions .static_files_ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Optional list of files which are actually static in the template
# but are allowed to have different content in the current repository
.github/workflows/check_openapi_spec.yaml

scripts/update_openapi_docs.py
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ WORKDIR /home/appuser
USER appuser
# set environment
ENV PYTHONUNBUFFERED=1
# Please adapt to package name:
ENTRYPOINT ["my-microservice"]

ENTRYPOINT ["ns"]
68 changes: 20 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@

![tests](https://github.com/ghga-de/notification-service/actions/workflows/unit_and_int_tests.yaml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/ghga-de/notification-service/badge.svg?branch=main)](https://coveralls.io/github/ghga-de/notification-service?branch=main)
# Notification-Service


# 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.: `my_microservice`

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 occurrences of `my-microservice` or `my_microservice`
with the final package name and don't forget to adapt the links):

---

**\# please adapt the links of following badges:**
![tests](https://github.com/ghga-de/my-microservice/actions/workflows/unit_and_int_tests.yaml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/ghga-de/my-microservice/badge.svg?branch=main)](https://coveralls.io/github/ghga-de/my-microservice?branch=main)
# My-Microservice

A description explaining the use case of this service.
This service is used to handle notifications, especially email notifications.
Other microservices in the ecosystem can publish the appropriate notification event and
this service will process it accordingly. The primary use is to send emails based on
notification event content. For instance, a service might want to notify a user that
their upload was successful. The service in question could publish an event with that
information, and the notification service would take care of the rest.

## Documentation:

Expand All @@ -46,25 +18,25 @@ An extensive documentation can be found [here](...) (coming soon).
### 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):
A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/notification-service):
```bash
# Please feel free to choose the version as needed:
docker pull ghga/my-microservice:<version>
docker pull ghga/notification-service:<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> .
docker build -t ghga/notification-service:<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 pre-configured:
docker run -p 8080:8080 ghga/my-microservice:<version>
docker run -p 8080:8080 ghga/notification-service:<version>
```

If you prefer not to use containers, you may install the service from source:
Expand All @@ -73,16 +45,16 @@ If you prefer not to use containers, you may install the service from source:
pip install .

# to run the service:
my-microservice
ns
```

### 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 `MY_MICROSERVICE_CONFIG_YAML` env variable
- rename it to `.my_microservice.yaml` and place it into one of the following locations:
- the current working directory were you are execute the service (on unix: `./.my_microservice.yaml`)
- your home directory (on unix: `~/.my_microservice.yaml`)
- specify the path to via the `NS_CONFIG_YAML` env variable
- rename it to `.ns.yaml` and place it into one of the following locations:
- the current working directory were you are execute the service (on unix: `./.ns.yaml`)
- your home directory (on unix: `~/.ns.yaml`)

The config yaml will be automatically parsed by the service.

Expand All @@ -91,8 +63,8 @@ The config yaml will be automatically parsed by the service.
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 `MY_MICROSERVICE_`,
e.g. for the `host` set an environment variable named `MY_MICROSERVICE_HOST`
For naming the environment variables, just prefix the parameter name with `NS_`,
e.g. for the `host` set an environment variable named `NS_HOST`
(you may use both upper or lower cases, however, it is standard to define all env
variables in upper cases).

Expand Down
Loading

0 comments on commit 59f63ed

Please sign in to comment.