diff --git a/doc/apps/django.md b/doc/apps/django.md index 7ea41bdc..eacb68fa 100644 --- a/doc/apps/django.md +++ b/doc/apps/django.md @@ -54,7 +54,7 @@ Now, open [http://0.0.0.0:5000/](http://0.0.0.0:5000/) to see your app. Once you have all your files, create a zip file. -To deploy a Flask app from the deployment menu, follow these instructions: +To deploy a Django app from the deployment menu, follow these instructions: ![](../static/docker.png) diff --git a/doc/apps/docker.md b/doc/apps/docker.md index 4e946649..ca3148f9 100644 --- a/doc/apps/docker.md +++ b/doc/apps/docker.md @@ -8,19 +8,19 @@ To deploy a Docker-based web application in Ploomber Cloud you need: ## `Dockerfile` -You need to provide a `Dockerfile`, you can use this [flask-based template](https://github.com/ploomber/doc/blob/main/examples/flask/basic-app/Dockerfile) to get started. +You need to provide a `Dockerfile`, you can use this [FastAPI-based template](https://github.com/ploomber/doc/blob/main/examples/fastapi/basic-app/Dockerfile) to get started. For a successful deployment, you app must run in port 80. -Here's an example using flask: +Here's an example using FastAPI: ```Dockerfile FROM python:3.11 COPY app.py app.py -RUN pip install flask gunicorn +RUN pip install fastapi uvicorn --no-cache-dir -ENTRYPOINT ["gunicorn", "app:app", "run", "--bind", "0.0.0.0:80"] +ENTRYPOINT ["uvicorn", "app:app", "--host=0.0.0.0", "--port=80"] ``` Once you have all your files, `.zip` them. For example, a simple app will contain two files: diff --git a/doc/apps/flask.md b/doc/apps/flask.md index d7452f7a..b3e04a72 100644 --- a/doc/apps/flask.md +++ b/doc/apps/flask.md @@ -15,35 +15,19 @@ myst: To deploy a Flask application in Ploomber Cloud you need: - A [Ploomber Cloud](https://platform.ploomber.io/register?utm_source=flask&utm_medium=documentation) account -- A `Dockerfile` -- Your code - -## `Dockerfile` - -You need to provide a `Dockerfile`, you can use this [template](https://github.com/ploomber/doc/blob/main/examples/flask/basic-app/Dockerfile) to get started. The template contains the minimal steps needed for a deployment but you need to modify so it installs any required dependencies and copies your code into the Docker image. - -```Dockerfile -FROM python:3.11 - -# assumes app.py contains your flask app -COPY app.py app.py -# install flask and gunicorn -RUN pip install flask gunicorn - -# this configuration is needed for your app to work, do not change it -ENTRYPOINT ["gunicorn", "app:app", "run", "--bind", "0.0.0.0:80"] -``` +- Your application file (`app.py`) +- A dependencies file (`requirements.txt`) ## Testing locally -To test your app, you can use `docker` locally: +To test your app, you can use `gunicorn` locally: ```sh -# build the docker image -docker build . -t flask +# Install requirements +pip install -r requirements.txt -# run it -docker run -p 5000:80 flask +# Start the flask application +gunicorn app:server run --bind 0.0.0.0:5000 ``` Now, open [http://0.0.0.0:5000/](http://0.0.0.0:5000/) to see your app. @@ -51,12 +35,59 @@ Now, open [http://0.0.0.0:5000/](http://0.0.0.0:5000/) to see your app. ## Deploy +`````{tab-set} + +````{tab-item} Web +__Deploy from the menu__ + Once you have all your files, create a zip file. To deploy a Flask app from the deployment menu, follow these instructions: -![](../static/docker.png) +![](../static/flask.png) +```` + +````{tab-item} Command-line +__Try an example__ + +To download and deploy an example Flask application start by installing Ploomber Cloud and setting your API key: + +```sh +pip install ploomber-cloud +ploomber-cloud key YOUR-KEY +``` + +```{tip} +If you don't have an API key yet, follow the [instructions here.](../quickstart/apikey.md) +``` + +Now, download an example. It will prompt you for a location to download the app. To download in the current directory, just press enter. + +```sh +ploomber-cloud examples flask/basic-app +``` + +```{note} +A full list of Flask example apps is available [here.](https://github.com/ploomber/doc/tree/main/examples/flask) +``` + +You should see a confirmation with instructions on deploying your app. Now, navigate to your application: + +```sh +cd location-you-entered/basic-app +``` + +__Deploy from the CLI__ + +Initialize and deploy your app with: + +```sh +ploomber-cloud init +ploomber-cloud deploy --watch +``` +```` +````` ```{tip} To ensure your app doesn't break on re-deployments, pin your [dependencies.](pin-dependencies) diff --git a/doc/static/flask.png b/doc/static/flask.png new file mode 100644 index 00000000..e5dcc4ea Binary files /dev/null and b/doc/static/flask.png differ diff --git a/examples/flask/basic-app/Dockerfile b/examples/flask/basic-app/Dockerfile deleted file mode 100644 index e53843f7..00000000 --- a/examples/flask/basic-app/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.11 - -COPY app.py app.py -RUN pip install flask gunicorn --no-cache-dir - -ENTRYPOINT ["gunicorn", "app:app", "run", "--bind", "0.0.0.0:80"] diff --git a/examples/flask/basic-app/app.zip b/examples/flask/basic-app/app.zip index af1e13bd..d8fc398c 100644 Binary files a/examples/flask/basic-app/app.zip and b/examples/flask/basic-app/app.zip differ diff --git a/examples/flask/basic-app/requirements.txt b/examples/flask/basic-app/requirements.txt new file mode 100644 index 00000000..f163f4d2 --- /dev/null +++ b/examples/flask/basic-app/requirements.txt @@ -0,0 +1,2 @@ +flask +gunicorn \ No newline at end of file diff --git a/examples/flask/login/Dockerfile b/examples/flask/login/Dockerfile deleted file mode 100644 index 8a5a9e8e..00000000 --- a/examples/flask/login/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.11 - -COPY . . -RUN pip install -r requirements.txt --no-cache-dir -RUN python models.py - -ENTRYPOINT ["gunicorn", "app:app", "run", "--bind", "0.0.0.0:80"] \ No newline at end of file diff --git a/examples/flask/login/README.md b/examples/flask/login/README.md index 2d2010bf..ba30ba24 100644 --- a/examples/flask/login/README.md +++ b/examples/flask/login/README.md @@ -18,8 +18,9 @@ export FLASK_SECRET_KEY=MYFLASKSECRETKEY ## Deployment -1. [Create an account in Ploomber Cloud](https://platform.ploomber.io/register) -2. [Follow this](https://docs.cloud.ploomber.io/en/latest/apps/flask.html) +1. Create the database models by running `python models.py` +2. [Create an account in Ploomber Cloud](https://platform.ploomber.io/register) +3. [Follow this](https://docs.cloud.ploomber.io/en/latest/apps/flask.html) Remember to add the `FLASK_SECRET_KEY` environment variable. diff --git a/examples/flask/machine-learning/Dockerfile b/examples/flask/machine-learning/Dockerfile deleted file mode 100644 index e960bfb9..00000000 --- a/examples/flask/machine-learning/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM python:3.11 - -COPY app.py app.py -COPY walmart_sales_rf.joblib walmart_sales_rf.joblib -COPY static/ static/ -COPY templates/ templates/ -RUN pip install flask gunicorn numpy pandas scikit-learn --no-cache-dir - -ENTRYPOINT ["gunicorn", "app:app", "run", "--bind", "0.0.0.0:80"] diff --git a/examples/flask/machine-learning/README.md b/examples/flask/machine-learning/README.md index 9bb140d1..9d61117d 100644 --- a/examples/flask/machine-learning/README.md +++ b/examples/flask/machine-learning/README.md @@ -30,7 +30,7 @@ Execute the `walmart_sales.ipynb` notebook. ploomber-engine walmart_sales.ipynb output.ipynb ``` -3. Create a zip file from `Dockerfile`, `app.py`, `walmart_sales_rf.joblib`, `static/` and `templates/`. +3. Create a zip file from `app.py`, `walmart_sales_rf.joblib`, `static/` and `templates/`. 4. Login to your [Ploomber Cloud](https://ploomber.io/) account. diff --git a/examples/flask/machine-learning/requirements.txt b/examples/flask/machine-learning/requirements.txt index fd8e3397..8c305e51 100644 --- a/examples/flask/machine-learning/requirements.txt +++ b/examples/flask/machine-learning/requirements.txt @@ -4,3 +4,4 @@ joblib numpy pandas scikit-learn +gunicorn