Skip to content

Commit 0a481a7

Browse files
committed
add docker/compose for bytewax/hackernews example
1 parent 4d72413 commit 0a481a7

File tree

6 files changed

+97
-7
lines changed

6 files changed

+97
-7
lines changed

example/bytewax/.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
6+
7+
**/.DS_Store
8+
**/__pycache__
9+
**/.venv
10+
**/.classpath
11+
**/.dockerignore
12+
**/.env
13+
**/.git
14+
**/.gitignore
15+
**/.project
16+
**/.settings
17+
**/.toolstarget
18+
**/.vs
19+
**/.vscode
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/bin
24+
**/charts
25+
**/docker-compose*
26+
**/compose*
27+
**/Dockerfile*
28+
**/node_modules
29+
**/npm-debug.log
30+
**/obj
31+
**/secrets.dev.yaml
32+
**/values.dev.yaml
33+
LICENSE
34+
README.md

example/bytewax/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.10 as base
4+
5+
# Prevents Python from writing pyc files.
6+
ENV PYTHONDONTWRITEBYTECODE=1
7+
8+
# Keeps Python from buffering stdout and stderr to avoid situations where
9+
# the application crashes without emitting any logs due to buffering.
10+
ENV PYTHONUNBUFFERED=1
11+
12+
#WORKDIR /app
13+
14+
# Create a non-privileged user that the app will run under.
15+
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
16+
ARG UID=10001
17+
RUN adduser \
18+
--disabled-password \
19+
--gecos "" \
20+
--home "/nonexistent" \
21+
--shell "/sbin/nologin" \
22+
--no-create-home \
23+
--uid "${UID}" \
24+
appuser
25+
26+
# Download dependencies as a separate step to take advantage of Docker's caching.
27+
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
28+
# Leverage a bind mount to requirements.txt to avoid having to copy them into
29+
# into this layer.
30+
RUN --mount=type=cache,target=/root/.cache/pip \
31+
--mount=type=bind,source=requirements.txt,target=requirements.txt \
32+
python -m pip install -r requirements.txt
33+
34+
# Switch to the non-privileged user to run the application.
35+
USER appuser
36+
37+
# Copy the source code into the container.
38+
COPY . .
39+
40+
# Run the application.
41+
CMD python -m bytewax.run "hackernews:run_hn_flow(0)"

example/bytewax/compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
proton:
3+
image: ghcr.io/timeplus-io/proton:latest
4+
hn_datagen:
5+
build:
6+
context: .
7+
image: timeplus/hackernews_bytewax:latest
8+
environment:
9+
- PROTON_HOST=proton
10+
depends_on:
11+
- proton

example/bytewax/hackernews.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22
from datetime import datetime, timedelta
3-
import time, json
3+
import time, json, os
44
from typing import Any, Optional
55

66
from bytewax.connectors.periodic import SimplePollingInput
@@ -76,5 +76,5 @@ def run_hn_flow(init_item):
7676
# traversal function to get the ultimate parent
7777
flow.map(key_on_parent)
7878

79-
flow.output("out", ProtonOutput("hn"))
79+
flow.output("out", ProtonOutput("hn",os.environ["PROTON_HOST"]))
8080
return flow

example/bytewax/proton.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# logger.setLevel(logging.DEBUG)
1111

1212
class _ProtonSink(StatelessSink):
13-
def __init__(self, stream: str):
14-
self.client=client.Client(host='127.0.0.1', port=8463)
13+
def __init__(self, stream: str, host: str):
14+
self.client=client.Client(host=host, port=8463)
1515
self.stream=stream
1616
sql=f"CREATE STREAM IF NOT EXISTS `{stream}` (raw string)"
1717
logger.debug(sql)
@@ -26,8 +26,9 @@ def write_batch(self, items):
2626
self.client.execute(sql,rows)
2727

2828
class ProtonOutput(DynamicOutput):
29-
def __init__(self, stream: str):
30-
self.stream=stream
29+
def __init__(self, stream: str, host: str):
30+
self.stream = stream
31+
self.host = host if host is not None and host != "" else "127.0.0.1"
3132

3233
"""Write each output item to Proton on that worker.
3334
@@ -43,4 +44,4 @@ def __init__(self, stream: str):
4344

4445
def build(self, worker_index, worker_count):
4546
"""See ABC docstring."""
46-
return _ProtonSink(self.stream)
47+
return _ProtonSink(self.stream, self.host)

example/bytewax/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bytewax
2+
requests
3+
proton-driver

0 commit comments

Comments
 (0)