Skip to content

Commit

Permalink
Sync branch 'feature-multiinformant' with feature/multiinformant-metapod
Browse files Browse the repository at this point in the history
This sync come after merge dev branch into feature-multiinformant
  • Loading branch information
rcmerlo committed May 15, 2024
1 parent 555ca93 commit 11eafff
Show file tree
Hide file tree
Showing 71 changed files with 3,490 additions and 2,978 deletions.
2 changes: 1 addition & 1 deletion .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SECRETS__SECRET_KEY=0eb7f5d4c1367199c21e9a2ec793b5a481b60fe2af24464bcb18ac7fa48a
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
OTEL_SERVICE_NAME=mindlogger_backend
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://opentelemetry:4317
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
# Variables below need only for AWS X-Ray
# OTEL_PROPAGATORS=
# OTEL_PYTHON_ID_GENERATOR=
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Coverage
on:
push:
branches:
- develop

permissions:
statuses: write

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: KengoTODA/actions-setup-docker-compose@v1
with:
version: '2.23.3'

- name: "Get coverage"
run: |
cp .env.default .env
echo -e "\nRABBITMQ__USE_SSL=False" >> .env
make run_local
- run: make ctest

- run: make creport SHA=${{ github.sha }}

- run: pip install smokeshow

- run: smokeshow upload htmlcov
env:
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 80
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
SMOKESHOW_GITHUB_CONTEXT: coverage
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}

57 changes: 57 additions & 0 deletions .github/workflows/create_db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Create-RDS-Database

on:
workflow_run:
workflows: ["Name-of-Your-Triggering-Workflow"]
types:
- completed

jobs:
create_database:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install PostgreSQL client 16
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt-get install -y wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-16
- name: Create Database
run: |
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.USERNAME }}" -d "${{ secrets.DATABASE_NAME }}" -c "CREATE DATABASE <DATABASE_NAME>;"
on-failure:
runs-on: ubuntu-latest
if: ${{ always() && (needs.create_database.result == 'failure' || needs.create_database.result == 'timed_out') }}
needs:
- create_database
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on failure"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: failure
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
SLACK_TITLE: Create Database
SLACK_MESSAGE: 'Error during database creation!'

on-success:
runs-on: ubuntu-latest
if: ${{ always() && (needs.create_database.result == 'success') }}
needs:
- create_database
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on success"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: success
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
SLACK_TITLE: Create Database
SLACK_MESSAGE: 'The database has been successfully created!'
53 changes: 53 additions & 0 deletions .github/workflows/run_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: run_build
on: [push, pull_request]
env:
AWS_REGION : "us-east-1"

permissions:
id-token: write
contents: read

jobs:

run_codebuild_project:
runs-on: ubuntu-latest
env:
GITHUB_ORGANIZATION: ${{ github.repository_owner }}
GITHUB_REPO_NAME: ${{ github.event.repository.name }}
GITHUB_BRANCH_OR_TAG: ${{ github.ref_name }}
GITHUB_REF: ${{ github.ref }}
BUILD_NAME: ${{github.event_name}}
BUILD_NUMBER: ${{github.run_id}}
ECR_ADDRESS: 917902836630.dkr.ecr.us-east-1.amazonaws.com
TEST_COMMAND: sleep 1
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
OUT_DIR: ./out

steps:
- name: Git clone the repository
uses: actions/checkout@v4

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::917902836630:role/cmiml-devops-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}

- name: Get secrets by name and by ARN
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
parse-json-secrets: true
secret-ids: |
,cmiml-devops
- name: Run CodeBuild
uses: aws-actions/aws-codebuild-run-build@v1
env:
DOCKER_USER: ${{ env.DOCKER_USER }}
DOCKER_PASSWORD: ${{ env.DOCKER_PASSWORD }}
REPORT_SERVER_PUBLIC_KEY: ${{ env.REPORT_SERVER_PUBLIC_KEY }}
with:
project-name: mindlogger-backend-refactor-builder
env-vars-for-codebuild: |
GITHUB_ORGANIZATION, GITHUB_REPO_NAME, GITHUB_BRANCH_OR_TAG, GITHUB_REF, BUILD_NAME, BUILD_NUMBER, ECR_ADDRESS, TEST_COMMAND, ECR_REPO, OUT_DIR, DOCKER_USER, DOCKER_PASSWORD, REPORT_SERVER_PUBLIC_KEY
30 changes: 30 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ jobs:
echo -e "\nRABBITMQ__USE_SSL=False" >> .env
docker compose up -d
make dtest
on-failure:
runs-on: ubuntu-latest
if: ${{ always() && (needs.tests.result == 'failure' || needs.tests.result == 'timed_out') }}
needs:
- tests
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on failure"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: failure
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
SLACK_TITLE: Run Unit Tests
SLACK_MESSAGE: 'Error when executing Unit tests!'

on-success:
runs-on: ubuntu-latest
if: ${{ always() && (needs.tests.result == 'success') }}
needs:
- tests
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on success"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: success
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
SLACK_TITLE: Run Unit Tests
SLACK_MESSAGE: 'Unit tests performed successfully!'
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ PORT = 8000
HOST = localhost

TEST_COMMAND = pytest -s -vv
COVERAGE_COMMAND = coverage run --branch --concurrency=thread,gevent -m pytest
REPORT_COVERAGE_COMMAND = coverage html --show-contexts --title "Coverage for ${SHA}"
EXPORT_COMMAND = python src/export_spec.py

RUFF_COMMAND = ruff
ISORT_COMMAND = isort
MYPY_COMMAND = mypy

DOCKER_EXEC = docker-compose run --rm app
COVERAGE_DOCKER_EXEC = docker-compose run --rm -u root app

# ###############
# Local
Expand All @@ -27,6 +30,14 @@ run_local:
test:
${TEST_COMMAND} ./

.PHONY: migrate
migrate:
./compose/fastapi/migrate

.PHONY: migrate-arbitrary
migrate-arbitrary:
./compose/fastapi/migrate arbitrary

# NOTE: cq == "Code quality"
.PHONY: cq
cq:
Expand All @@ -47,6 +58,16 @@ dtest:
${DOCKER_EXEC} \
${TEST_COMMAND} ./

.PHONY: ctest
ctest:
${COVERAGE_DOCKER_EXEC} \
${COVERAGE_COMMAND}

.PHONY: creport
creport:
${COVERAGE_DOCKER_EXEC} \
${REPORT_COVERAGE_COMMAND}


.PHONY: dcheck
dcheck:
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "pypi"
[packages]
aioredis = "~=2.0.1"
alembic = "~=1.8.1"
asyncpg = "~=0.27.0"
asyncpg = "~=0.29.0"
boto3 = "==1.26.10"
fastapi = "==0.110.0"
# The latest version of the fastapi is not taken because of the issue
Expand Down Expand Up @@ -89,7 +89,7 @@ greenlet = "~=2.0.1"
# JSONLD deps only for dev
reproschema = "*"
cachetools = "==5.3.0"
pyld = "==2.0.3"
pyld = "==2.0.4"


[requires]
Expand Down

0 comments on commit 11eafff

Please sign in to comment.