Skip to content

Commit

Permalink
Merge pull request #10 from rszamszur/enhancement/#6
Browse files Browse the repository at this point in the history
Resolves #6
  • Loading branch information
rszamszur committed Jan 7, 2022
2 parents 51381cd + d5745bf commit cff9b70
Show file tree
Hide file tree
Showing 115 changed files with 3,285 additions and 1,058 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Install package
run: |
export POETRY_HOME=$HOME/.poetry
export POETRY_CACHE_DIR=$HOME/.poetry/store
make install
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Generate test-project
run: poetry run fastapi-mvc new test-project
- name: Run vagrant up
run: vagrant up

run: |
cd test-project
vagrant up
- name: Bootstrap minukube cluster and Redis operator
run: vagrant ssh -c "cd /syncd && make dev-env"

run: |
cd test-project
vagrant ssh -c "cd /syncd && make dev-env"
- name: Test exposed fastapi_mvc application
run: vagrant ssh -c 'curl "http://fastapi-mvc.$(minikube ip).nip.io/api/ready"'
run:
cd test-project
vagrant ssh -c 'curl "http://test-project.$(minikube ip).nip.io/api/ready"'
178 changes: 156 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
with:
path: ~/.poetry
key: poetry-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/poetry.lock') }}
- name: Install project
- name: Install package
run: |
export POETRY_HOME=$HOME/.poetry
export POETRY_CACHE_DIR=$HOME/.poetry/store
Expand Down Expand Up @@ -91,18 +91,8 @@ jobs:
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Style guide
run: |
poetry run flake8 --select=E,W,I --max-line-length 80 --import-order-style pep8 --exclude .git,__pycache__,.eggs,*.egg,.pytest_cache,fastapi_mvc/version.py,fastapi_mvc/__init__.py --tee --output-file=pep8_violations.txt --statistics --count fastapi_mvc
poetry run flake8 --select=D --ignore D301 --tee --output-file=pep257_violations.txt --statistics --count fastapi_mvc
- name: Code errors
run: poetry run flake8 --select=F --tee --output-file=flake8_code_errors.txt --statistics --count fastapi_mvc
- name: Code complexity
run: poetry run flake8 --select=C901 --tee --output-file=code_complexity.txt --count fastapi_mvc
- name: TODO
run: poetry run flake8 --select=T --tee --output-file=todo_occurence.txt --statistics --count fastapi_mvc tests
- name: Black
run: poetry run black -l 80 --check fastapi_mvc
- name: Run metrics checks
run: make metrics
unit-tests:
needs: install
runs-on: ubuntu-latest
Expand All @@ -126,14 +116,7 @@ jobs:
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run unit tests
run: poetry run py.test tests/unit --junit-xml=xunit-${{ matrix.python-version }}.xml
- name: Run coverage
run: poetry run pytest --cov=fastapi_mvc --cov-fail-under=70 --cov-report=xml --cov-report=term-missing tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: ./coverage.xml
run: make unit-test
integration-tests:
needs: install
runs-on: ubuntu-latest
Expand All @@ -157,4 +140,155 @@ jobs:
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run integration tests
run: poetry run py.test tests/integration --junit-xml=xunit-${{ matrix.python-version }}.xml
run: make integration-test
generate:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load Poetry cache
uses: actions/cache@v2
with:
path: ~/.poetry
key: poetry-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/poetry.lock') }}
- name: Init test-project cache
id: cached-project
uses: actions/cache@v2
with:
path: ~/.poetry
key: project-${{ matrix.python-version }}-${{ hashFiles('**/*.py') }}
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
if: steps.cached-project.outputs.cache-hit != 'true'
- name: Generate test-project
run: |
poetry run fastapi-mvc new test-project
mv test-project ~/.poetry/store
if: steps.cached-project.outputs.cache-hit != 'true'
- name: Install test-project
run: |
cd ~/.poetry/store/test-project
export POETRY_CACHE_DIR=$HOME/.poetry/store
make install
if: steps.cached-project.outputs.cache-hit != 'true'
template-metrics:
needs: generate
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9 ]

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load test-project cache
uses: actions/cache@v2
with:
path: ~/.poetry
key: project-${{ matrix.python-version }}-${{ hashFiles('**/*.py') }}
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run metrics checks
run: |
cd ~/.poetry/store/test-project
make metrics
template-unit-tests:
needs: generate
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load test-project cache
uses: actions/cache@v2
with:
path: ~/.poetry
key: project-${{ matrix.python-version }}-${{ hashFiles('**/*.py') }}
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run unit tests
run: |
cd ~/.poetry/store/test-project
make unit-test
template-integration-tests:
needs: generate
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load test-project cache
uses: actions/cache@v2
with:
path: ~/.poetry
key: project-${{ matrix.python-version }}-${{ hashFiles('**/*.py') }}
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run integration tests
run: |
cd ~/.poetry/store/test-project
make integration-test
coverage:
needs: generate
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9 ]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Load test-project cache
uses: actions/cache@v2
with:
path: ~/.poetry
key: project-${{ matrix.python-version }}-${{ hashFiles('**/*.py') }}
- name: Config path and poetry
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry config cache-dir $HOME/.poetry/store
- name: Run package coverage
run: poetry run pytest --cov=fastapi_mvc/cli --cov-fail-under=90 --cov-report=xml --cov-report=term-missing tests
- name: Run template coverage
run: |
cd ~/.poetry/store/test-project
poetry run pytest --cov=test_project --cov-fail-under=90 --cov-report=xml --cov-report=term-missing tests
mv coverage.xml $GITHUB_WORKSPACE/coverage-template.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
files: ./coverage.xml,./coverage-template.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ xunit-*.xml

# virtual
venv
.venv

# vagrant
.vagrant
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ This file documents changes to [fastapi-mvc](https://github.com/rszamszur/fastap

### Unreleased

### Features

- [x] Refactor project from the pure template into the package which generates fastapi-mvc projects from cookiecutter template (#6). PR #10

### Fixed

- [x] Add missing FASTAPI_USE_REDIS env var in Helm chart config map and deployment.

### Internal

- [x] Rename project to fastapi-mvc.
- [x] Add FASTAPI_DEBUG env var in Helm chart config map and deployment.
- [x] Add K8s integration test workflow.
- [x] Rename Test workflow to CI.
- [x] Extend make targets for package and template.
- [x] Add minor improvements to package and template GitHub workflows.

### 0.4.0

Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ clean-image: ## Clean fastapi-mvc image
install: ## Install fastapi-mvc with poetry
@build/install.sh

.PHONY: dev-env
dev-env: image ## Start a local Kubernetes cluster using minikube and deploy application
@build/dev-env.sh
.PHONY: metrics
metrics: install ## Run fastapi-mvc metrics checks
@build/metrics.sh

.PHONY: clean
clean: ## Remove .cache directory and cached minikube
minikube delete && rm -rf ~/.cache ~/.minikube
.PHONY: unit-test
unit-test: install ## Run fastapi-mvc unit tests
@build/unit-test.sh

.PHONY: integration-test
integration-test: install ## Run fastapi-mvc integration tests
@build/integration-test.sh

.PHONY: show-version
show-version:
Expand Down
8 changes: 4 additions & 4 deletions build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ if [[ ${PYTHON_VERSION} < "3.7.0" ]]; then
exit 1
fi

POETRY_HOME="${POETRY_HOME:=${HOME}/.local}"
POETRY_HOME="${POETRY_HOME:=${HOME}/.poetry}"
if ! command -v "$POETRY_HOME"/bin/poetry &> /dev/null; then
echo "[install] Poetry is not installed. Begin download and install."
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | POETRY_HOME=$POETRY_HOME $PYTHON -
fi

echo "[install] Begin installing project."
"$POETRY_HOME"/bin/poetry install --extras "aioredis aiohttp" --no-interaction
"$POETRY_HOME"/bin/poetry install --no-interaction

cat <<EOF
Project successfully installed.
To activate virtualenv run: $ poetry shell
Now you should access CLI script: $ fastapi --help
Alternatively you can access CLI script via poetry run: $ poetry run fastapi --help
Now you should access CLI script: $ fastapi-mvc --help
Alternatively you can access CLI script via poetry run: $ poetry run fastapi-mvc --help
To deactivate virtualenv simply type: $ deactivate
EOF
13 changes: 13 additions & 0 deletions build/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if [ -n "$DEBUG" ]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)

poetry run pytest tests/integration
17 changes: 17 additions & 0 deletions build/metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

if [ -n "$DEBUG" ]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)

poetry run flake8 --select=E,W,I --max-line-length 80 --import-order-style pep8 --exclude .git,__pycache__,.eggs,*.egg,.pytest_cache,fastapi_mvc/version.py,fastapi_mvc/__init__.py,fastapi_mvc/template --tee --output-file=pep8_violations.txt --statistics --count fastapi_mvc
poetry run flake8 --select=D --ignore D301 --tee --exclude fastapi_mvc/template --output-file=pep257_violations.txt --statistics --count fastapi_mvc
poetry run flake8 --select=C901 --tee --exclude fastapi_mvc/template --output-file=code_complexity.txt --count fastapi_mvc
poetry run flake8 --select=T --tee --exclude fastapi_mvc/template--output-file=todo_occurence.txt --statistics --count fastapi_mvc tests
poetry run black -l 80 --exclude fastapi_mvc/template --check fastapi_mvc
13 changes: 13 additions & 0 deletions build/unit-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

if [ -n "$DEBUG" ]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)

poetry run pytest tests/unit
14 changes: 0 additions & 14 deletions charts/fastapi-mvc/templates/service.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions charts/fastapi-mvc/templates/serviceaccount.yaml

This file was deleted.

Loading

0 comments on commit cff9b70

Please sign in to comment.