Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: quick start for using gunicorn with python #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions getting-started/quickstarts/gunicorn.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: 'Gunicorn'
description: 'How to deploy a python application with Gunicorn'
---

Using [Gunicorn](https://gunicorn.org/) is a great way to deploy a python application. Using it on Hop is very easy and can be done in a few steps.

## Demo

<Note>
We have already made a repository for you to use. You can find it{' '}
[here](https://github.com/hop-examples/python_gunicorn)
</Note>

### Preparing your application for Hop

1. Gunicorn needs a config file to run. We will create a file called `gunicorn.conf.py` and add the following code to it. If you already have a config file, make sure to have this appended to it.

<div style={{"paddingLeft": "35px"}}>

```python
bind = "0.0.0.0"
```

If you are going to expose this service through a gateway, the application needs to be bound to `0.0.0.0` instead of `localhost` or `127.0.0.1`.

</div>

2. If you are using a dockerfile (if not skip to #3), make sure to add the following line to it.

<div style={{"paddingLeft": "35px"}}>

```dockerfile
CMD ["gunicorn", "[WSGI_APP]"]
```

Where `WSGI_APP` is of the pattern `$(MODULE_NAME):$(VARIABLE_NAME)`.
For example for:

```python
# main.py
def app(environ, start_response):
# your code here
```

The command is `CMD ["gunicorn", "main:app"]`

</div>

3. If you are not using a dockerfile, upon deploying your project to Hop, make sure to add the following under "Advanced Options" -> "CMD"

<div style={{"paddingLeft": "35px"}}>

```bash
gunicorn [WSGI_APP]
```

Like so,

<Frame>![](/images/hop-cmd-option.webp)</Frame>
</div>

4. All set! Enjoy your python application on Hop!
Binary file added images/hop-cmd-option.webp
Binary file not shown.
5 changes: 4 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"ignite/deploying",
{
"group": "Quickstarts",
"pages": ["getting-started/quickstarts/elixir-cluster"]
"pages": [
"getting-started/quickstarts/elixir-cluster",
"getting-started/quickstarts/gunicorn"
]
}
]
},
Expand Down