Giter Club home page Giter Club logo

flask-example-cicd's Introduction

flask-example-cicd

This is a simple python flask application to host a simple web app.

After starting the flask application you can access following URL's on the server:

Function URL
index http://<server>:<port>/
json http://<server>:<port>/json/
hello http://<server>:<port>/hello/
hello <name> http://<server>:<port>/hello/<name>
primes 100 http://<server>:<port>/primes/
primes <count> http://<server>:<port>/primes/<count>

How to run

You can run the application in 2 ways:

Docker instructions

Requirements:

Build the docker image in the project root folder with:

docker build . -t flask-example-cicd:latest

To run the docker image in interactive mode:

docker run --rm -it -p 8080:8080/tcp --name flask-example flask-example-cicd:latest

To run the docker image in detached mode:

docker run --rm -d -p 8080:8080/tcp --name flask-example flask-example-cicd:latest

You can change the environmental variable for flask in the Dockerfile, for example you can change the port by changing ENV FLASK_RUN_PORT=8080.

Stop the running container:

docker stop flask-example

Build from source

Requirements:

  • python3
  • python3-dev
  • python3-pip
  • gcc (to compile cython)
  • musl-dev (to compile cython)

Instructions for Debian/Ubuntu

  1. Install requirements:
apt update
apt install gcc musl-dev python3 python3-dev python3-pip
  1. Build/Install project:
. build.sh
  1. Run the server on localhost:8080:
. run.sh

Development

Virtual Environment

For local development you can use a virtual environment โ†’ How to install virtualenv.

Create a virtual environment:

# linux example
python3 -m venv "venv"
source venv/bin/activate

With deactivate you can disable the virtual environment.

Debugging

Built-In flask debugger

You can debug the flask app by running following commands:

Linux (Bash)
export FLASK_APP=flaskr.app
export FLASK_ENV=development
flask run
Windows (CMD)
set FLASK_APP=flaskr.app
set FLASK_ENV=development
flask run
Windows (PowerShell)
$env:FLASK_APP = "flaskr.app"
$env:FLASK_ENV = "development"
flask run

External Debugger

When using an external debugger, the app should still be in debug mode, but it an be useful to disable the built-in debugger and reloader, which can interfere.

  • flask run --no-debugger
  • flask run --no-reload
  • flask run --no-debugger --no-reload
Example configuration for VS Code

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "flaskr/app.py",
                "FLASK_ENV": "development",
                "FLASK_RUN_PORT" : "8080",
                "FLASK_DEBUG": "1"
            },
            "args": [
                "run",
                "--no-debugger"
            ],
            "jinja": true
        }
    ]
}

Testing

To run unit tests:

# install pytest manually or use "reset-dev.sh"
pip3 install pytest 
pytest

Reset development environment

You can use the script reset-dev.sh to reset your development environment:

. reset-dev.sh

The script will do following:

  • (Re)create the virtual environment venv without dependencies installed
  • Activating venv in current terminal
  • Install development/testing tools in venv
    • flake8 (Linting)
    • pylint (Linting)
    • autopep8 (Formatting)
    • pytest (Testing)
  • Remove all folders created by build/install
    • package info (*egg-info)
    • build folder
    • dist folder
    • pycache folders
    • built cython files (*.so, *.pyd)

Now you can build the project manually or with build.sh.

flask-example-cicd's People

Contributors

mgrum avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.