Skip to content

feat(containers): python container example #57

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

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

.terraform.lock.hcl

# Serverless framework
node_modules/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Table of Contents:
| **[Function Handler Java](containers/function-handler-java/README.md)** <br/> A Java function handler deployed on CaaS. | Java | [Serverless Framework] |
| **[NGINX CORS Private](containers/nginx-cors-private-python/README.md)** <br/> An NGINX proxy to allow CORS requests to a private container. | Python Flask | [Terraform] |
| **[NGINX hello world](containers/nginx-hello-world/README.md)** <br/> A minimal example running the base NGINX image in a serverless container. | N/A | [Serverless Framework] |
| **[Python hello world](containers/python-hello-world/README.md)** <br/> A minimal example running a Flask HTTP server in a serverless container. | N/A | [Serverless Framework] |
| **[Terraform NGINX hello world](containers/terraform-nginx-hello-world/README.md)** <br/> A minimal example running the base NGINX image in a serverless container deployed with Terraform. | N/A | [Terraform] |
| **[Triggers with Terraform](containers/terraform-triggers/README.md)** <br/> Configuring two SQS triggers, used to trigger two containers, one public, one private. | N/A | [Terraform] |

Expand Down
22 changes: 22 additions & 0 deletions containers/python-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Python Hello World

This demonstrates a simple example of running a [Flask](https://flask.palletsprojects.com/en/2.0.x/quickstart/) HTTP server in a [Scaleway Serverless Container](https://www.scaleway.com/en/serverless-containers/).

## Requirements

This example assumes you are familiar with how Serverless Containers work. If needed, you can
check the [Scaleway official documentation](https://www.scaleway.com/en/docs/serverless/containers/quickstart/).

This example uses the Scaleway Serverless Framework Plugin. Please set up your environment with the requirements stated in the [Scaleway Serverless Framework Plugin](https://github.com/scaleway/serverless-scaleway-functions) before trying out the example.

## Deployment

Once your environment is set up, you can deploy your container with:

```sh
npm i

serverless deploy
```

When the deployment is complete, you should be able to `curl` the container's endpoint or hit it from a browser and see the message returned by the Flask server.
10 changes: 10 additions & 0 deletions containers/python-hello-world/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.10
WORKDIR /app

RUN pip3 install --upgrade pip
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target .

COPY handler.py .

CMD [ "python3", "./handler.py" ]
15 changes: 15 additions & 0 deletions containers/python-hello-world/container/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask
import os

app = Flask(__name__)


@app.route("/")
def hello():
return "Hello world from the Python container!"


if __name__ == "__main__":
port_env = os.getenv("PORT", 8080)
port = int(port_env)
app.run(debug=True, host="0.0.0.0", port=port)
1 change: 1 addition & 0 deletions containers/python-hello-world/container/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==3.0.0
Loading