Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mephenor committed Sep 18, 2024
0 parents commit ef8ea2d
Show file tree
Hide file tree
Showing 79 changed files with 7,607 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Please only mention the non-default settings here:

language: Greek
service_instance_id: "1"
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm

ENV PYTHONUNBUFFERED 1

# Update args in docker-compose.yaml to set the UID/GID of the "vscode" user.
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then groupmod --gid $USER_GID vscode && usermod --uid $USER_UID --gid $USER_GID vscode; fi

# [Option] Install Node.js
ARG INSTALL_NODE="false"
ARG NODE_VERSION="lts/*"
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# Copy install and launcher script to bin:
COPY ./dev_install /bin
COPY ./dev_launcher /bin

CMD ["sleep", "infinity"]
16 changes: 16 additions & 0 deletions .devcontainer/dev_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# install service in dev container

cd /workspace

# upgrade pip
python -m pip install --upgrade pip

# install or upgrade dependencies for development and testing
pip install --no-deps -r ./lock/requirements-dev.txt

# install the package itself in edit mode:
pip install --no-deps -e .

# install pre-commit hooks to git
pre-commit install
4 changes: 4 additions & 0 deletions .devcontainer/dev_launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# adapt to package name
my-microservice
75 changes: 75 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3-postgres
{
"name": "${localWorkspaceFolderBasename}",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"files.eol": "\n",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.formatOnSave": true,
"editor.renderWhitespace": "all",
"editor.rulers": [
88
],
"ruff.organizeImports": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"licenser.license": "Custom",
"licenser.customHeaderFile": "/workspace/.devcontainer/license_header.txt"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"mikestead.dotenv",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"njpwerner.autodocstring",
"redhat.vscode-yaml",
"42crunch.vscode-openapi",
"arjun.swagger-viewer",
"eamodio.gitlens",
"github.vscode-pull-request-github",
"streetsidesoftware.code-spell-checker",
"yzhang.markdown-all-in-one",
"visualstudioexptteam.vscodeintellicode",
"ymotongpoo.licenser",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"-ms-python.autopep8"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5432],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "dev_install",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"containerEnv": {
// for testcontainers to connect to the docker host:
"TC_HOST": "host.docker.internal",
"DOCKER_HOST": "unix:///var/run/docker.sock"
},
"features": {
// details can be found here: https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
}
}
69 changes: 69 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
services:
app:
build:
context: .
dockerfile: ./Dockerfile
args:
# [Choice] Install Node.js
INSTALL_NODE: "false"
NODE_VERSION: "lts/*"
# Please adapt to package name:
PACKAGE_NAME: "my_microservice"
# 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

init: true

# Makes testcontainers work on linux based hosts
extra_hosts:
- host.docker.internal:host-gateway

volumes:
- ..:/workspace:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Uncomment the next line to use a non-root user for all processes.
user: vscode

# define environment variables
environment:
# Please adapt to package name:
MY_MICROSERVICE_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
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: {}
14 changes: 14 additions & 0 deletions .devcontainer/license_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
for the German Human Genome-Phenome Archive (GHGA)

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.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# CRLF line endings cause problems in Docker, so we force git
# to check in and out using only LF line endings.

*.cfg text eol=lf
*.ini text eol=lf
*.json text eol=lf
*.md text eol=lf
*.py text eol=lf
*.txt text eol=lf
*.yaml text eol=lf
*.yml text eol=lf

.editorconfig text eol=lf
.flake8 text eol=lf
.pylintrc text eol=lf

.git* text eol=lf
*_files text eol=lf
*_files_ignore text eol=lf

**/dev_* text eol=lf
**/Dockerfile text eol=lf
25 changes: 25 additions & 0 deletions .github/workflows/check_config_docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check if the config schema and the example are up to date

on: push

jobs:
static-code-analysis:
name: Check config schema and example

runs-on: ubuntu-latest

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Common steps
id: common
uses: ghga-de/gh-action-common@v6

- name: Check config docs
id: check-config-docs
run: |
export ${{ steps.common.outputs.CONFIG_YAML_ENV_VAR_NAME }}="${{ steps.common.outputs.CONFIG_YAML }}"
./scripts/update_config_docs.py --check
26 changes: 26 additions & 0 deletions .github/workflows/check_openapi_spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is only needed if your repository uses FastAPI
name: Check if OpenAPI spec is up to date

on: push

jobs:
static-code-analysis:
name: Check OpenAPI spec

runs-on: ubuntu-latest

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Common steps
id: common
uses: ghga-de/gh-action-common@v6

- name: Check openapi.yaml
id: check-openapi-docs
run: |
export ${{ steps.common.outputs.CONFIG_YAML_ENV_VAR_NAME }}="${{ steps.common.outputs.CONFIG_YAML }}"
./scripts/update_openapi_docs.py --check
23 changes: 23 additions & 0 deletions .github/workflows/check_pyproject.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check if pyproject.toml file is up to date

on: push

jobs:
static-code-analysis:
name: Check pyproject file

runs-on: ubuntu-latest

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Common steps
id: common
uses: ghga-de/gh-action-common@v6

- name: Check pyproject.toml
id: check-pyproject
run: |
./scripts/update_pyproject.py --check
23 changes: 23 additions & 0 deletions .github/workflows/check_readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check if the README file is up to date

on: push

jobs:
static-code-analysis:
name: Check README file

runs-on: ubuntu-latest

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Common steps
id: common
uses: ghga-de/gh-action-common@v6

- name: Check README
id: check-readme
run: |
./scripts/update_readme.py --check
30 changes: 30 additions & 0 deletions .github/workflows/check_template_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check template files

on: push

jobs:
check-template-files:
name: Check template files

runs-on: ubuntu-latest

steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4

- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Check template files
id: check-template-files
run: |
if [ "${{ github.event.repository.name }}" == "microservice-repository-template" ]
then
echo "Skipping this test as operating on the template repo."
else
./scripts/update_template_files.py --check
fi
23 changes: 23 additions & 0 deletions .github/workflows/ci_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI on release

on:
release:
types: [published]

jobs:
push_to_docker_hub:
name: Push to Docker Hub

strategy:
matrix:
flavor: ["", "debian"]

runs-on: ubuntu-latest

steps:
- uses: ghga-de/gh-action-ci@v1
with:
tag: ${{ github.event.release.tag_name }}
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
flavor: ${{ matrix.flavor }}
Loading

0 comments on commit ef8ea2d

Please sign in to comment.