Skip to content

Commit

Permalink
Merge pull request #33 from ai-cfia/32-fix-every-workflow-inside-this…
Browse files Browse the repository at this point in the history
…-repository

issue #32: added every useful workflows
  • Loading branch information
ThomasCardin authored Jan 26, 2024
2 parents 0db4293 + 5f2647a commit e075c63
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 34 deletions.
19 changes: 15 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:3.11",
"postCreateCommand": "pip3 install --user -r requirements.txt"
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:3.11",
"postCreateCommand": "pip3 install --user -r requirements.txt",
"customizations": {
"vscode": {
"extensions": [
"charliermarsh.ruff",
"GitHub.vscode-pull-request-github",
"ms-python.python",
"ms-python.black-formatter",
"stkb.rewrap",
"DavidAnson.vscode-markdownlint"
]
}
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Docker build and push to ghcr.io/ai-cfia and lint test
name: python-backend-workflows

on:
on:
pull_request:
types:
- opened
Expand All @@ -12,6 +12,16 @@ jobs:
uses: ai-cfia/github-workflows/.github/workflows/workflow-lint-test-python.yml@main
secrets: inherit

markdown-check:
uses: ai-cfia/github-workflows/.github/workflows/workflow-markdown-check.yml@main
with:
config-file-path: '.mlc_config.json'
secrets: inherit

repo-standard:
uses: ai-cfia/github-workflows/.github/workflows/workflow-repo-standards-validation.yml@main
secrets: inherit

deploy:
uses: ai-cfia/github-workflows/.github/workflows/workflow-build-push-container-github-registry.yml@63-as-a-devops-i-would-like-to-create-a-workflow-to-push-images-to-this-organisation-docker-registry
with:
Expand Down
3 changes: 3 additions & 0 deletions .mlc_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"aliveStatusCodes": [999,200,403]
}
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"stkb.rewrap",
"DavidAnson.vscode-markdownlint"
],
"unwantedRecommendations": [

]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.rulers": [80], // used for .md files
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true
}
7 changes: 7 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Testing

Run:

```bash
python -m unittest discover -s tests
```
4 changes: 2 additions & 2 deletions app/blueprints/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from flask import Blueprint, current_app, jsonify, request
from index_search import AzureIndexSearchQueryError, search
from index_search import AzureIndexSearchError, search

from app.ailab_db import DBError, ailab_db_search
from app.blueprints.common import create_error_response
Expand All @@ -15,7 +15,7 @@ class EmptyQueryError(Exception):
"""Raised when the search query is empty."""


@search_blueprint.errorhandler(AzureIndexSearchQueryError)
@search_blueprint.errorhandler(AzureIndexSearchError)
def handle_azure_error(error):
message = current_app.config["ERROR_AZURE_FAILED"]
return create_error_response(error, message, 500)
Expand Down
9 changes: 6 additions & 3 deletions docs/DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Deployment

Note on the container: Create and set the environment variables based on `.env.template`. Make sure
`FINESSE_BACKEND_DEBUG_MODE` is NOT set to `True` in PRODUCTION builds.
Note on the container: Create and set the environment variables based on
`.env.template`. Make sure `FINESSE_BACKEND_DEBUG_MODE` is NOT set to `True` in
PRODUCTION builds.

Refer to the [infrastructure repository](https://github.com/ai-cfia/infra) for a Kubernetes deployment. The secrets (in this case environment variables) are managed with Hashicorp Vault.
Refer to the [infrastructure repository](https://github.com/ai-cfia/infra) for a
Kubernetes deployment. The secrets (in this case environment variables) are
managed with Hashicorp Vault.
28 changes: 14 additions & 14 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

1. Clone the repository:

```bash
git clone https://github.com/ai-cfia/finesse-backend.git
```
```bash
git clone https://github.com/ai-cfia/finesse-backend.git
```

2. Open in devcontainer.

Alternatively,

1. Clone the repository:

```bash
git clone https://github.com/ai-cfia/finesse-backend.git
cd finesse-frontend
```
```bash
git clone https://github.com/ai-cfia/finesse-backend.git
cd finesse-frontend
```

2. Create a virtual environment:

```bash
python -m venv venv
source venv/bin/activate
```
```bash
python -m venv venv
source venv/bin/activate
```

3. Install the dependencies:

```bash
pip install -r requirements.txt
```
```bash
pip install -r requirements.txt
```
10 changes: 6 additions & 4 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

## With your local environment

Create and set the environment variables based on `.env.template`. You will need to create a `.env` file.
Create and set the environment variables based on `.env.template`. You will need
to create a `.env` file.

### Running:
### Running

```bash
flask run -h 0.0.0.0 --debug
```

Alternatively, set the `FINESSE_BACKEND_DEBUG_MODE` environment variable to
Alternatively, set the `FINESSE_BACKEND_DEBUG_MODE` environment variable to
`True` and run:

```bash
Expand All @@ -19,7 +20,8 @@ python run.py

## With docker

Create and set the environment variables based on `.env.template`. You will need to create a `.env` file.
Create and set the environment variables based on `.env.template`. You will need
to create a `.env` file.

Build the container:

Expand Down
4 changes: 2 additions & 2 deletions tests/test_azure_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import patch

from app.app_creator import create_app
from app.blueprints.search import AzureIndexSearchQueryError
from app.blueprints.search import AzureIndexSearchError
from tests.common import TestConfig


Expand All @@ -25,6 +25,6 @@ def test_search_azure_no_query(self):

def test_search_azure_error(self):
with patch("app.blueprints.search.search") as mock_search:
mock_search.side_effect = AzureIndexSearchQueryError("Azure search failed")
mock_search.side_effect = AzureIndexSearchError("Azure search failed")
response = self.client.post("/search/azure", json={"query": "azure query"})
self.assertEqual(response.status_code, 500)
6 changes: 3 additions & 3 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from unittest.mock import patch

from app.app_creator import create_app
from app.blueprints.search import AzureIndexSearchQueryError
from app.blueprints.search import AzureIndexSearchError
from tests.common import TestConfig


Expand Down Expand Up @@ -50,7 +50,7 @@ def test_search_azure_no_query(self):
def test_error_handling_debug_mode(self):
self.app.config["DEBUG"] = True
with patch("app.blueprints.search.search") as mock_func:
mock_func.side_effect = AzureIndexSearchQueryError("Sample Error")
mock_func.side_effect = AzureIndexSearchError("Sample Error")
response = self.client.post("/search/azure", json={"query": "test query"})
self.assertEqual(response.status_code, 500)
self.assertIn("trace", response.json)
Expand All @@ -59,7 +59,7 @@ def test_error_handling_debug_mode(self):
def test_error_handling_non_debug_mode(self):
self.app.config["DEBUG"] = False
with patch("app.blueprints.search.search") as mock_func:
mock_func.side_effect = AzureIndexSearchQueryError("Sample Error")
mock_func.side_effect = AzureIndexSearchError("Sample Error")
response = self.client.post("/search/azure", json={"query": "test query"})
self.assertEqual(response.status_code, 500)
self.assertNotIn("trace", response.json)
Expand Down

0 comments on commit e075c63

Please sign in to comment.