Skip to content

Commit a4a8634

Browse files
authored
Add Docker samples (slackapi#52)
* Add Docker samples * Add a missing file * Update Google Cloud Run samples to be more optimal * Tweak Dockerfile and add more samples * Update fastapi sample
1 parent a57da8c commit a4a8634

27 files changed

Lines changed: 412 additions & 2 deletions

samples/docker/aiohttp/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# docker build . -t your-repo/hello-bolt
3+
#
4+
FROM python:3.8.5-slim-buster as builder
5+
RUN apt-get update && apt-get clean
6+
COPY requirements.txt /build/
7+
WORKDIR /build/
8+
RUN pip install -U pip && pip install -r requirements.txt
9+
10+
FROM python:3.8.5-slim-buster as app
11+
COPY --from=builder /src/ /app/
12+
COPY --from=builder /usr/local/lib/ /usr/local/lib/
13+
WORKDIR /app/
14+
COPY *.py /app/
15+
ENTRYPOINT python main.py
16+
17+
#
18+
# docker run -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN -e PORT=3000 -p 3000:3000 -it your-repo/hello-bolt
19+
#

samples/docker/aiohttp/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import logging
3+
4+
from slack_bolt.async_app import AsyncApp
5+
6+
logging.basicConfig(level=logging.DEBUG)
7+
app = AsyncApp()
8+
9+
10+
@app.command("/hello-bolt-python")
11+
async def hello(payload, ack):
12+
user_id = payload["user_id"]
13+
await ack(f"Hi <@{user_id}>!")
14+
15+
16+
if __name__ == "__main__":
17+
app.start(port=int(os.environ.get("PORT", int(os.environ.get("PORT", 3000)))))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
slack_bolt
2+
aiohttp>=3,<4
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# docker build . -t your-repo/hello-bolt
3+
#
4+
FROM tiangolo/uvicorn-gunicorn:python3.8-slim
5+
WORKDIR /app/
6+
COPY *.py /app/
7+
COPY requirements.txt /app/
8+
RUN pip install -U pip && pip install -r requirements.txt
9+
10+
#
11+
# docker run -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN -e VARIABLE_NAME="api" -p 80:80 -it your-repo/hello-bolt
12+
#
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import logging
2+
3+
from slack_bolt.async_app import AsyncApp
4+
5+
logging.basicConfig(level=logging.DEBUG)
6+
app = AsyncApp()
7+
8+
9+
@app.command("/hello-bolt-python")
10+
async def hello(payload, ack):
11+
user_id = payload["user_id"]
12+
await ack(f"Hi <@{user_id}>!")
13+
14+
15+
from fastapi import FastAPI, Request
16+
17+
api = FastAPI()
18+
19+
from slack_bolt.adapter.fastapi.async_handler import AsyncSlackRequestHandler
20+
21+
app_handler = AsyncSlackRequestHandler(app)
22+
23+
24+
@api.post("/slack/events")
25+
async def endpoint(req: Request):
26+
return await app_handler.handle(req)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
slack_bolt
2+
fastapi<1
3+
aiohttp>=3,<4
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# docker build . -t your-repo/hello-bolt
3+
#
4+
FROM python:3.8.5-slim-buster as builder
5+
COPY requirements.txt /build/
6+
WORKDIR /build/
7+
RUN pip install -U pip && pip install -r requirements.txt
8+
9+
FROM python:3.8.5-slim-buster as app
10+
WORKDIR /app/
11+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
12+
COPY --from=builder /usr/local/lib/ /usr/local/lib/
13+
COPY *.py /app/
14+
ENTRYPOINT gunicorn --bind :$PORT --workers 1 --threads 2 --timeout 0 main:flask_app
15+
16+
#
17+
# docker run -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN -e PORT=3000 -p 3000:3000 -it your-repo/hello-bolt
18+
#
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
3+
from slack_bolt import App
4+
5+
logging.basicConfig(level=logging.DEBUG)
6+
app = App()
7+
8+
9+
@app.command("/hello-bolt-python")
10+
def hello(payload, ack):
11+
user_id = payload["user_id"]
12+
ack(f"Hi <@{user_id}>!")
13+
14+
15+
from flask import Flask, request
16+
from slack_bolt.adapter.flask import SlackRequestHandler
17+
18+
flask_app = Flask(__name__)
19+
handler = SlackRequestHandler(app)
20+
21+
22+
@flask_app.route("/slack/events", methods=["POST"])
23+
def slack_events():
24+
return handler.handle(request)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
slack_bolt
2+
Flask>=1.1
3+
gunicorn>=20
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# docker build . -t your-repo/hello-bolt
3+
#
4+
FROM python:3.8.5-slim-buster as builder
5+
RUN apt-get update \
6+
&& apt-get -y install build-essential libpcre3-dev \
7+
&& apt-get clean
8+
COPY requirements.txt /build/
9+
WORKDIR /build/
10+
RUN pip install -U pip && pip install -r requirements.txt
11+
12+
FROM python:3.8.5-slim-buster as app
13+
WORKDIR /app/
14+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
15+
COPY --from=builder /usr/local/lib/ /usr/local/lib/
16+
COPY *.py /app/
17+
COPY uwsgi.ini /app/
18+
ENTRYPOINT uwsgi --ini uwsgi.ini --http :$PORT
19+
20+
#
21+
# docker run -e SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET -e SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN -e PORT=3000 -p 3000:3000 -it your-repo/hello-bolt
22+
#

0 commit comments

Comments
 (0)