-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
858ed0b
commit 46751e8
Showing
17 changed files
with
165 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
.terraform | ||
.mypy_cache | ||
.coveragerc | ||
.coverage | ||
|
||
coverage_report | ||
terraform.tfstate | ||
terraform.tfstate.backup | ||
venv | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"pylint.args": ["--rcfile=pyproject.toml"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,93 @@ | ||
# Kubernetes GCP Python Starter App | ||
|
||
## Install | ||
|
||
OSX system requirements: | ||
|
||
- pyenv - `brew install pyenv` | ||
- docker - `brew install --cask docker` | ||
- httpie - `brew install httpie` | ||
|
||
These are listed individually to avoid polluting your global installation unknowingly. | ||
|
||
After installing the above, you can run the following command to setup your local dependencies. It sets up on a virtualenv for you. | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
You should run this command every time your python dependencies change. | ||
|
||
## Development | ||
|
||
The project runs the application code inside of a pipenv virtualenv, but requires some amount of configuration for your global python installation. | ||
The development workflow involves using one or two terminal windows, depending on the type of work you are doing. | ||
|
||
All of our python commands use `inv` / `invoke` eg [`pyinvoke`](https://www.pyinvoke.org/), a makefile replacement written in python. This allows us a degree of flexibility and comfort with our dev time tooling. | ||
|
||
For the context of this API, all of the work you do should be able to be covered by 100% unit test coverage. Also, the primary mechanism of testing development work should be [`pytest-watch`](https://pypi.org/project/pytest-watch/). | ||
|
||
When testing via a more "hands on" approach, we use a combination of `flask run` (via invoke) and `httpie`. `httpie` is used as a UX friendly alternative to `curl`, although we do utilize `curl` to confirm that we are aligned with the project spec. | ||
|
||
### Pytest | ||
|
||
```bash | ||
$ source ./venv/bin/activate | ||
$ invoke test | ||
``` | ||
|
||
### Pytest Watch | ||
|
||
```bash | ||
$ source ./venv/bin/activate | ||
$ invoke test-watch | ||
``` | ||
|
||
This terminal will now watch for changes, and automatically re-run the tests when it finds them. | ||
|
||
The majority of our tests were written in this way. | ||
|
||
### httpie | ||
|
||
```bash | ||
# first terminal | ||
$ source ./venv/bin/activate | ||
$ invoke serve | ||
``` | ||
|
||
```bash | ||
# second terminal | ||
$ http :8080/api/healthcheck | ||
> HTTP/1.1 200 OK | ||
``` | ||
|
||
### curl | ||
|
||
```bash | ||
# inside ~/.zshrc, or similar | ||
export PIPENV_VENV_IN_PROJECT=1 | ||
# first terminal | ||
$ source ./venv/bin/activate | ||
$ invoke serve | ||
``` | ||
|
||
```bash | ||
# run once, or whenever you are working on a new machine | ||
pip install invoke pipenv pyyaml | ||
# second terminal | ||
$ curl http://0.0.0.0:8080/api/healthcheck | ||
> OK | ||
``` | ||
|
||
### Updating Dependencies | ||
|
||
You can update dependencies via | ||
|
||
```bash | ||
pipenv install < some package > | ||
make install upgrade install | ||
``` | ||
|
||
## Deployment | ||
|
||
This deployment command assumes you are locally authenticated to both gcloud and kubectl. Directions on how to do so are out of scope for this documentation. Please consult your team's local deployment tooling and instructions! | ||
|
||
```bash | ||
source ./venv/bin/activate | ||
invoke deploy # see tasks.py for source code | ||
``` |
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[tool.pylint.main] | ||
fail-under = 100 | ||
suggestion-mode = true | ||
|
||
[tool.pylint.messages-control] | ||
disable = [ | ||
"missing-module-docstring", | ||
"missing-function-docstring", | ||
"missing-class-docstring", | ||
"broad-exception-raised", | ||
"broad-exception-caught", | ||
] | ||
max-line-length = 100 |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import flask | ||
|
||
|
||
blueprint = flask.Blueprint("api", __name__, url_prefix="/api") | ||
|
||
|
||
@blueprint.route("/healthcheck") | ||
def healthcheck(): | ||
"""used for debugging purposes""" | ||
return flask.jsonify( | ||
{ | ||
"status": "ok", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import flask | ||
import src.main.api | ||
|
||
|
||
def create_app(): | ||
"""Create and configure an instance of the Flask application.""" | ||
app = flask.Flask(__name__) | ||
app.register_blueprint(src.main.api.blueprint) | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import src.main.app | ||
|
||
app = src.main.app.create_app() | ||
|
||
if __name__ == "__main__": | ||
# Run a debug server. | ||
app.run(debug=True, host="0.0.0.0") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import src.main.app | ||
|
||
|
||
app = src.main.app.create_app() | ||
app.config["TESTING"] = True | ||
client = app.test_client() | ||
|
||
|
||
def test_true(): | ||
"""When all seems lost, the true test will always be there for you.""" | ||
assert True | ||
|
||
|
||
def test_healthcheck(): | ||
response = client.get("/api/healthcheck") | ||
assert response.status_code == 200 | ||
assert response.json == {"status": "ok"} |