Skip to content

Commit

Permalink
Merge branch 'pip-refactor' into 'main'
Browse files Browse the repository at this point in the history
Pip refactor

See merge request johndutchover/insight-ai-api!21
  • Loading branch information
John Dutchover committed Feb 10, 2024
2 parents 6039b45 + 99c8878 commit e433aaf
Show file tree
Hide file tree
Showing 52 changed files with 452 additions and 1,778 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,4 @@ $RECYCLE.BIN/
*.msm
*.msp
*.lnk

### Custom ###
venv-fe/**
secrets.toml
# End of file
67 changes: 9 additions & 58 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ workflow:
- when: never

default:
image: python:3.11.6
image: python:3.11.7
before_script:
- apt-get update -qq && apt-get install -y curl
- curl -L https://fly.io/install.sh | sh
- export FLYCTL_INSTALL="/root/.fly"
- export PATH="$FLYCTL_INSTALL/bin:$PATH"
- python --version
- pip install virtualenv
- python -m pip install virtualenv
- python -m venv .venv

variables:
Expand All @@ -29,12 +29,14 @@ install_dependencies:
stage: install
script:
- source .venv/bin/activate
- pip install -r app/requirements_dev.txt
- pip install -r app/requirements.txt
- pip install pre-commit
- python -m pip install -r app/requirements/requirements-dev.txt

Check failure on line 32 in .gitlab-ci.yml

View workflow job for this annotation

GitHub Actions / MegaLinter

32:7 [hyphens] too many spaces after hyphen
- python -m pip install -r app/requirements/requirements.txt

Check failure on line 33 in .gitlab-ci.yml

View workflow job for this annotation

GitHub Actions / MegaLinter

33:7 [hyphens] too many spaces after hyphen
- python -m pip install pre-commit

Check failure on line 34 in .gitlab-ci.yml

View workflow job for this annotation

GitHub Actions / MegaLinter

34:7 [hyphens] too many spaces after hyphen
rules:
- changes:
- Makefile
- base.in
- requirements-requirements-test.in
- requirements-dev.in
- requirements.in
- pyproject.toml
Expand All @@ -43,7 +45,7 @@ install_dependencies:

config_changes:
stage: test
image: python:3.11.6
image: python:3.11.7
script:
- source .venv/bin/activate
rules:
Expand All @@ -55,53 +57,16 @@ config_changes:
when: never
- when: always

#mega-linter:
# stage: code_quality
# # You can override MegaLinter flavor used to have faster performances
# # More info at https://megalinter.io/flavors/
# image: oxsecurity/megalinter-python:v7.5.0
# script: ["true"]
# variables:
# # All available variables are described in documentation
# # https://megalinter.io/configuration/
# DEFAULT_WORKSPACE: $CI_PROJECT_DIR
# # ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# ENABLE_LINTERS: MAKEFILE_CHECKMAKE,PYTHON_BLACK,PYTHON_FLAKE8
# artifacts:
# when: always
# paths:
# - megalinter-reports
# expire_in: 1 week
# rules:
# - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
# - when: always
# - if: $CI_MERGE_REQUEST_TITLE =~ /^Draft:/
# when: never

bandit:
stage: code_quality
script:
- source .venv/bin/activate
- pip install pre-commit
- python -m pip install pre-commit
- pre-commit run bandit --all-files
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == "main"'
- when: always

# Add a new deploy-backend-staging job
deploy-backend-staging:
stage: deploy
script:
- echo "Deploy backend app to staging from $CI_COMMIT_BRANCH branch"
- flyctl auth token $FLY_API_TOKEN
- flyctl deploy --ha=false --config app/fly.staging.toml
environment: staging
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(dev|feature-.*)$/'
- when: manual
- if: $CI_MERGE_REQUEST_TITLE =~ /^Draft:/
when: never

deploy-backend:
stage: deploy
script:
Expand All @@ -114,17 +79,3 @@ deploy-backend:
- when: manual
- if: $CI_MERGE_REQUEST_TITLE =~ /^Draft:/
when: never

deploy-frontend:
stage: deploy
script:
- echo "Deploy frontend app from $CI_COMMIT_BRANCH branch"
- export PYTHONPATH="client/"
- flyctl auth token $FLY_API_TOKEN
- flyctl deploy --ha=false --config frontend/fly.production.toml
environment: production
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
- when: manual
- if: $CI_MERGE_REQUEST_TITLE =~ /^Draft:/
when: never
3 changes: 2 additions & 1 deletion .idea/inspectionProfiles/python_inspect.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions .idea/runConfigurations/login__frontend_.xml

This file was deleted.

8 changes: 7 additions & 1 deletion .idea/runConfigurations/main__api_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions .idea/runConfigurations/main__cli_.xml

This file was deleted.

25 changes: 0 additions & 25 deletions .idea/runConfigurations/poethepoet_tests.xml

This file was deleted.

9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.1.1
hooks:
- id: black
types:
- python
args: ["--config=pyproject.toml"]

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
types:
- python

- repo: https://github.com/pycqa/bandit
rev: 1.7.5
rev: 1.7.7
hooks:
- id: bandit
args: ["-c", "pyproject.toml", "-ll"]
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.6
3.11.7
59 changes: 0 additions & 59 deletions Makefile

This file was deleted.

34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,29 @@ This is a simplistic FastAPI app that uses AI features to enhance api service.

Set Python version using pyenv

`pyenv local 3.11.6`
`pyenv local 3.11.7`

- writes to `.python-version`

### Initialize virtualenv
### Initialize for development

From repository root:

1. `make venv`
1. `python -m venv .venv`
2. `source .venv/bin/activate`
3. `python -m pip install -Ur local.in`

### Dependency management

#### Makefile

Makefile command table

| Command | Purpose |
|---------------------------------|------------------------------------------------------------------------------------|
| `make venv` | Target to create and activate the app virtual environment |
| `make venv-fe` | Target to create and activate the frontend virtual environment |
| `make app/requirements` | Generate "app/requirements.txt" by compiling "requirements.in" |
| `make app/requirements_dev` | Generate "app/requirements_dev.txt" by compiling "requirements-dev.in" |
| `make app-requirements` | Generate "app/requirements.txt" and "app/requirements_dev.txt" |
| `make frontend-requirements` | Generate "frontend/requirements_fe.txt" by compiling "requirements-fe.in" |
| `make cli-requirements` | Generate "cli/requirements_fe.txt" by compiling "requirements-cli.in" |
| `make compile-requirements` | Regenerate both "app/requirements.txt" and "app/requirements_dev.txt" |
| `make compile-requirements-dev` | Regenerate "app/requirements_dev.txt" using "pip-compile" |
| `make deploy-api` | Deploy app (api) using flyctl |
| `make deploy-fe` | Deploy frontend using flyctl |
| `make sync-requirements-app` | Synchronize .venv/ with the packages in requirements.txt and requirements_dev.txt |
| `make sync-requirements-cli` | Synchronize cli/venv-cli/ with the packages in requirements_cli.txt |
| `make sync-requirements-fe` | Synchronize frontend/venv-fe/ with the packages in requirements_frontend.txt |
| Command | Purpose |
|--------------------|------------------------------------------|
| `make init` | Initialize Python environment |
| `make update` | Update and Initialize Python environment |
| `make update-deps` | Update Python dependencies |

### GitLab CI

Expand Down Expand Up @@ -96,4 +86,8 @@ Makefile command table

### Fly

- app/fly.toml
#### Production
- app/fly.production.toml

#### Staging
- app/fly.staging.toml
Loading

0 comments on commit e433aaf

Please sign in to comment.