Python connector with docker compose

This example Dockerfile packages our example Python Fluvio project into a connector image.

 

Dockerfile

FROM python:3.11

# Run as the `fluvio` user instead of root
ENV USER=fluvio
RUN useradd --create-home "$USER"
USER $USER
WORKDIR /home/fluvio

# Copy your Rust project ng Fluvio CLI for creating topics in example
RUN curl -fsS https://hub.infinyon.cloud/install/install.sh | bash

## Add `fluvio` to PATH
ENV PATH="/home/fluvio/.fluvio/bin:${PATH}"

# Install dependencies
RUN pip install --upgrade pip
RUN pip3 install fluvio

# Copy your Python project and run it
COPY --chown=$USER:$USER hello-python.py .
CMD python hello-python.py

This docker-compose.yml used with docker compose CLI starts our previously built connector image as a local connector

 

docker-compose.yml

version: "3"
services:
 example:
   build: .
   network_mode: "host"
   volumes:
     - $HOME/.fluvio/config:/home/fluvio/.fluvio/config:ro
     - $HOME/.kube:/home/fluvio/.kube:ro
 

Run example

$ docker compose build
$ docker compose run example
 

Example output

[...]
Hello World! - Time is: 2022-11-10 02:35:10.143967
[...]