Skip to content

Commit

Permalink
prepare 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jgtvares committed Dec 29, 2021
1 parent 0fd29b0 commit 956f87c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ Add a `vercel.json` file to the root of your application:
This configuration is doing a few things in the `"builds"` part:

1. `"src": "index.py"`
This tells Now that there is one entrypoint to build for. `index.py` is a
This tells Vercel that there is one entrypoint to build for. `index.py` is a
file we'll create shortly.
2. `"use": "@jgtvares/py-vercel"`
Tell Now to use this builder when deploying your application
Tell Vercel to use this builder when deploying your application
3. `"config": { "maxLambdaSize": "15mb" }`
Bump up the maximum size of the built application to accommodate some larger
python WSGI libraries (like Django or Flask). This may not be necessary for
you.

### 2. Add a Now entrypoint
### 2. Add a Vercel entrypoint

Add `index.py` to the root of your application. This entrypoint should make
available an object named `application` that is an instance of your WSGI
Expand All @@ -45,6 +45,21 @@ from django_app.wsgi import application
# Replace `django_app` with the appropriate name to point towards your project's
# wsgi.py file
```
- If you're using any database lib, like `pymysql`, you'll need to install it as a MySql module before any Django code in your `wsgi.py` file. Like this:
```python
# wsgi.py
import os
import sys
import pymysql # import pymysql

pymysql.install_as_MySQLdb() # call this method before any Django import

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<folder_name>.settings')

application = get_wsgi_application()
```

Look at your framework documentation for help getting access to the WSGI
application.
Expand All @@ -68,14 +83,16 @@ $ vercel

### Linux requirements

Your project may optionally include a `apt-requirements.txt` file to declare any
dependencies, e.g.:
If you need any Linux dependencies you can add a `install.sh` file at the root of your project containing the commands you want to execute inside the Lambda instance. This script is executed before Python requirements (section below). For example:

```text
# apt-requirements.txt
mysql
```bash
#!/bin/bash
yum install -y gcc musl-dev mysql-devel
```

You can also add a `post-install.sh` file at the root of your project to run commands after all dependencies are installed.
This script is executed after Python requirements (section below).

### Python requirements

Your project may optionally include a `requirements.txt` file to declare any
Expand Down Expand Up @@ -122,7 +139,7 @@ Select the WSGI application to run from your entrypoint. Defaults to
### Routing

You'll likely want all requests arriving at your deployment url to be routed to
your application. You can do this by adding a route rewrite to the Now
your application. You can do this by adding a route rewrite to the Vercel
configuration:

```json
Expand All @@ -140,7 +157,7 @@ configuration:
### Avoiding the `index.py` file

If having an extra file in your project is troublesome or seems unecessary, it's
also possible to configure Now to use your application directly, without passing
also possible to configure Vercel to use your application directly, without passing
it through `index.py`.

If your WSGI application lives in `vercel_app/wsgi.py` and is named `application`,
Expand Down Expand Up @@ -173,3 +190,4 @@ This implementation draws upon work from:

- [vercel-python-wsgi](https://github.com/jayhale/vercel-python-wsgi) by
[@jayhale](https://github.com/jayhale)
- [py-vercel](https://github.com/PotatoHD404/py-vercel) by [@PotatoHD404](https://github.com/PotatoHD404)
3 changes: 1 addition & 2 deletions example/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"src": "app/wsgi.py",
"use": "git+https://github.com/jgtvares/py-vercel.git#main",
"config": {
"maxLambdaSize": "30mb",
"runtime": "python3.6"
"maxLambdaSize": "30mb"
}
}],
"routes": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jgtvares/py-vercel",
"version": "1.0.0",
"version": "2.0.0",
"description": "Linux package installer on Vercel",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 956f87c

Please sign in to comment.