Getting started with pebl

Getting started with pebl

How to deploy a python application with a single line of code

·

3 min read

In this quick tutorial, I want to show a super easy way to create a serverless python deployment using pebl. Unlike other infrastructure-as-code tools, pebl doesn't require external configuration yaml or json configuration files.

Instead you simply incorporate pebl like any other python library into your application, then call the methods that give your application cloud capabilities!

TLDR

As an overview (and to serve as a quick reference), here's what we're working towards. A single method to transform your python application into a cloud deployment:

import pebl
from flask import Flask

app = Flask(__name__)

@app.route("/")
def root():
  return "hello, world!"

pebl.service(app, "your-subdomain.pebl.rocks")

Setup

  1. Make sure that you have docker installed locally

  2. Head over to pebl and create a free account

    Make sure to claim your free *.pebl.rocks subdomain, we'll use this for the tutorial! The examples will show hey.pebl.rocks, but make sure to put your subdomain instead.

  3. Follow these steps to install the pebl cli

Project

Now it's time to create your project!

  1. Create a new scratch folder for this tutorial

     mkdir scratch-folder
    
  2. Inside the scratch folder, create a Dockerfile with this content:

     FROM peblcloud/python:0.0.8
     COPY main.py .
     RUN pip install Flask
     ENTRYPOINT python -u main.py
    
  3. Finally, create a main.py that will contain your Flask application. Make sure you place the correct *.pebl.rocks subdomain that you claimed!

     import pebl
     from flask import Flask
    
     app = Flask(__name__)
    
     @app.route("/")
     def root():
       return "Hello!"
    
     pebl.service(app, "your-subdomain.pebl.rocks")
    

Running Locally

You can try running this project locally using the pebl cli.

  1. Start a local cluster with pebl up

    Make sure to have docker running!

  2. Navigate to the project folder then execute pebl run

  3. Once running, check the state of the cluster with pebl info

    (You can exit the info pane by pressing q or with ctrl-c)

  4. Send a request to the running application with curl, taking note of the port that your endpoint is bound to. In my example we are bound to :32771, so the curl request would be:

     curl localhost:32771
    

Running in the cloud

Now running this project in the cloud is just two steps:

  1. Make sure you are authed with pebl auth

  2. Run pebl deploy within your project

Once deployed, you can curl your endpoint. Make sure to use https!

And with that you have successfully created a serverless deployment, complete with DNS updates, HTTPS, autoscaling, and more.

Next steps

  1. You can see the logs and more information about your deployment by heading over to the pebl console.

  2. To make changes, simply update the main.py and re-run pebl deploy!

  3. You can also check out some more methods available for you to unlock cloud capabilities, like redis and scheduled tasks. https://docs.pebl.io/reference/SDK