forked from ypcs/flask-template
-
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.
Moved from the base flask image repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'Lint Python code' | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint-python: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python_version: ['3.6', '3.8', '3.10'] | ||
steps: | ||
- name: Setup repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up python ${{ matrix.python_version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python_version }} | ||
|
||
- name: Install essential tools | ||
run: pip install flake8 | ||
|
||
- name: Run flake8 | ||
run: flake8 |
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 @@ | ||
*~ | ||
*.swp | ||
*.py[co] |
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,4 @@ | ||
FROM docker.io/ypcs/flask:latest | ||
FROM ghcr.io/seravo/flask:latest | ||
|
||
ARG APT_PROXY | ||
|
||
|
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,2 +1,53 @@ | ||
# flask-template | ||
# Flask template | ||
|
||
Flask project template | ||
|
||
## Usage | ||
|
||
To run hello world app, :8080 provides HTTP endpoint (to uWSGI), and :9000 provides uWSGI endpoint. So, let's try accessing via HTTP: | ||
|
||
docker run --rm -it -v $(pwd)/app:/app -e FLASK_APP=hello:app -p 127.0.0.1:8080:8080 ghcr.io/seravo/flask:latest | ||
|
||
now try to open http://127.0.0.1:8080/ , you should see familiar greeting. | ||
|
||
To publish your own app, mount your app to `/app`, and provide FLASK_APP environment variable with correct value. | ||
|
||
Eg. | ||
|
||
docker run --rm -it -v $(pwd)/app:/app -e FLASK_APP=app:app -p 127.0.0.1:8080:8080 ghcr.io/seravo/flask:latest | ||
|
||
if you had app code like | ||
|
||
app/app.py: | ||
|
||
from flask import Flask | ||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def some_view(): | ||
return "Hello myapp!" | ||
|
||
Usually you shouldn't expose this HTTP endpoint directly to internet, but use eg. `ypcs/nginx:latest` as a reverse proxy. | ||
|
||
## Live reload | ||
|
||
By default, you can manually reload the application by touching `/tmp/reload-app`. If you want your application to reload automatically after every save, set `FLASK_RELOAD` as `true`. | ||
|
||
docker run --rm -it -v $(pwd)/app:/app -e FLASK_APP=app:app -e FLASK_RELOAD=true -p 127.0.0.1:8080:8080 ghcr.io/seravo/flask:latest | ||
|
||
Now, if you modify the code in `app.py` and save, the app will reload and your changes will be in effect. | ||
|
||
## Tests | ||
|
||
Tests can be ran by executing `pytest-3` inside the container. For example, to run the tests for `hello.py` you would do it like this: | ||
|
||
docker exec -t {CONTAINER_NAME} pytest-3 hello.py -vv | ||
|
||
Test output should look something like this: | ||
|
||
platform linux -- Python 3.9.2, pytest-6.0.2, py-1.10.0, pluggy-0.13.0 -- /usr/bin/python3 | ||
cachedir: .pytest_cache | ||
rootdir: /app | ||
collected 1 item | ||
|
||
hello.py::test_hello PASSED |
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