• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    Python
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple guide to understand Prefect and make it work with your own docker-compose configuration.

Prefect - Docker Compose

A simple guide to understand and make Prefect 2.x work with your own docker-compose configuration.

Interested in examples for Prefect 1.x ? Switch to the last 1.x branch of this repo.

This allows you to package your Prefect instance for fully-containerized environments (e.g: docker-compose, Kubernetes) or offline use.

Operating principle of Prefect

Run the server

  1. Optionally open and edit the server/.env file

    ℹī¸ All PREFECT_* env variables can be found in the Prefect settings.py file.

  2. Start the server :

    cd server && docker-compose up --build -d && cd -
  3. Access the Orion UI at localhost:4200

Run one or multiple agents

Agents are services that run your scheduled flows.

  1. Optionally open and edit the agent/docker-compose.yml file.

    ℹī¸ In each docker-compose.yml, you will find the PREFECT_API_URL env variable including the 172.17.0.1 IP address. This is the IP of the Docker daemon on which are exposed all exposed ports of your containers. This allows containers launched from different docker-compose networks to communicate. Change it if yours is different (check your daemon IP by typing ip a | grep docker0).

    Docker interface IP

    Here, mine is 192.168.254.1 but the default is generally to 172.17.0.1.

  2. Start the agent :

    docker-compose -f agent/docker-compose.yml up -d

    ℹī¸ You can run the agent on another machine than the one with the Prefect server. Edit the PREFECT_API_URL env variable for that.

    Maybe you want to instanciate multiple agents ?

    docker-compose -f agent/docker-compose.yml up -d --scale agent=3 agent
  3. Our agents are now starting listening the Orion server on the flows-example-queue queue (see the --work-queue option).

Run your first flow via the Prefect API

Principles to understand

đŸ’Ŧ Execution in your cloud; orchestration in ours

This means the Prefect server never stores your code. It just orchestrates the running (optionally the scheduling) of it.

  1. After developing your flow, Prefect will register it to the Orion server through a Deployment. In that script, you may ask the server to run your flow 3 times a day, for example.

  2. Your code never lies on the Prefect server : this means the code has to be stored somewhere accessible to the agents in order to be executed.

    Prefect has a lot of storage options but the most famous are : Local, S3, Docker and git.

    • Local : saves the flows to be run on disk. So the volume where you save the flows must be shared among your client and your agent(s). Requires your agent to have the same environment than your client (Python modules, packages installed etc... (the same Dockerfile if your agent and client are containers))
    • S3 : similar to local, but saves the flows to be run in S3 objects.
    • Docker : saves the flows to be run as Docker images to your Docker Registry so your agents can easily run the code.

Flow with Local storage (easiest)

ℹī¸ If your agents are installed among multiple machines, I recommend you to mount a shared directory with SSHFS.

  1. Run the following command to register your deployment and run the flow :

    docker-compose -f client/docker-compose.yml up # Executes weather.py
  2. Access the UI to see your flow correctly run

Flow with S3 Storage (recommended)

Tutorial for S3 Storage

We will use MinIO as our S3 server.

  1. Optionally open and edit the client_s3/.env file and start MinIO

    docker-compose -f client_s3/docker-compose.yml up -d minio # Starts MinIO
  2. Register the flow :

    docker-compose -f client_s3/docker-compose.yml up weather # Executes weather.py

Now your flow is registered. You can access the UI to run it.

Flow with Docker storage

This method requires our client AND agent containers to have access to Docker so they can package or load the image in which the flow will be executed. We use Docker in Docker for that.

Tutorial for (secure) Docker Storage

Preparing the Registry

A Docker Registry is needed in order to save images that are going to be used by our agents.

  1. Generate the authentication credentials for our registry

    sudo apt install apache2-utils # required to generate basic_auth credentials
    cd client_docker/registry/auth && htpasswd -B -c .htpasswd myusername && cd -

    To add more users, re-run the previous command without the -c option

  2. Start the registry

    docker-compose -f client_docker/docker-compose.yml up -d registry
  3. Login to the registry

    You need to allow your Docker daemon to push to this registry. Insert this in your /etc/docker/daemon.json (create if needed) :

    {
      "insecure-registries": ["172.17.0.1:5000"]
    }
  4. Start the registry

    docker login http://172.17.0.1:5000 # with myusername and the password you typed

    You should see : Login Succeeded

Start the Docker in Docker agent

Optionally edit registry credentials in ./agent_docker/docker-compose.yml and run :

docker-compose -f agent_docker/docker-compose.yml up --build -d

Registering the flow

We're going to push our Docker image with Python dependencies and register our flow.

  1. Build, tag and push the image

    docker build . -f ./client_docker/execution.Dockerfile -t 172.17.0.1:5000/weather/base_image:latest

    You must prefix your image with the registry URI 172.17.0.1:5000 to push it

    docker push 172.17.0.1:5000/weather/base_image:latest
  2. Register the flow

    Optionally edit registry credentials in ./client_docker/docker-compose.yml and run :

    docker-compose -f ./client_docker/docker-compose.yml up --build weather

Now your flow is registered. You can access the UI to run it.

More Repositories

1

opensearch-docker-compose

Dockerized cluster architecture for OpenSearch with compose.
Shell
140
star
2

apt-mirror-docker

Up to date apt-mirror script, containerized for mirroring + serving.
Perl
42
star
3

awesome-llm-devops

A list of DevOps features enabled by awesome LLM software.
40
star
4

book-devops

The "Scaling Institutions With Devops" book.
HTML
37
star
5

blockchain-php

An object-oriented PHP library for creating a blockchain easily.
PHP
34
star
6

gRPC-Python-Docker-Example

A simple guide to use gRPC with python and docker
Python
24
star
7

Pandemic-Knowledge

A fully-featured multi-source data pipeline for continuously extracting knowledge from COVID-19 data.
Python
21
star
8

nginx-keycloak

Set NGINX as a reverse proxy with Keycloak SSO in front of your web applications.
Shell
18
star
9

deb-package-tutorial

A simple tutorial to create and install your very own deb package.
Shell
17
star
10

reactjs-flask-ldap-boilerplate

ReactJS + Flask + Docker (+K8S) boilerplate using an LDAP and token-based authentication.
JavaScript
14
star
11

flbw

Dynamic & lightweight C++ encryption algorithm using a password or not, changing the encrypted string each time it is submitted even if the original string hasn't changed.
C++
13
star
12

Neo4j-Example-Spotifylike

Based on the idea of Spotify : a concrete example to understand how graph databases work with Neo4j. The challenge is to create a music recommendation algorithm using a very large database of songs (Million Song Challenge Dataset) with an API to interact with (Symfony).
PHP
9
star
13

pascal-voc-image-augmentor

Script for image augmentation writing new Pascal VOC annotations for your deep learning experiments.
Python
8
star
14

eclipse-che-kubernetes

Cloud-based development platform on Kubernetes.
Shell
6
star
15

directframework

A very simple, lightweight and powerful PHP framework built to save you time by deploying quickly your ideas with a clean code.
PHP
6
star
16

debmirror

Download & serve an Ubuntu or Debian mirror. An alternative to apt-mirror.
Shell
5
star
17

gRPC-multiprocessing-streaming

Python implementation of a multi-processed gRPC client/server with streaming capabilities.
Python
4
star
18

Regex101-Offline

Offline dockerized version of Regex101.
Dockerfile
4
star
19

Secure-Docker-Elastic-Cluster

An end-to-end fully secure Elasticsearch cluster with Kibana and run with Docker. Using official images.
4
star
20

crontab.guru-Docker

A dockerized version of crontab.guru that can be used offline.
Dockerfile
4
star
21

ppa-mirror-docker

Dockerized PPA downloader for apt installs.
Shell
4
star
22

pgvector-opensearch-benchmark

A comparative benchmark of pgvector and OpenSearch clusters for vector comparisons.
Python
4
star
23

icons-visualizer

A quick and simple UI and API to search and display icons or images. Can be used in an offline environment thanks to Docker.
JavaScript
4
star
24

trivy-docker-compose

Deployment-ready docker configuration and instructions to use Trivy on your infrastructure and CIs.
Dockerfile
3
star
25

ceph-kubernetes

A repo-tutorial to learn how to easily install and use Rook Ceph on a Kubernetes cluster.
3
star
26

npm-offline-registry-docker

Dockerized NPM / Yarn / PNPM offline registry and tools to host your dependencies.
Python
3
star
27

gitlab-runner-docker-compose

Gitlab runners easily explained and dockerized with compose.
Shell
3
star
28

centos-mirror-docker

Download a CentOS Linux mirror for yum downloads
Shell
3
star
29

freshdoc

Keep code and text snippets in sync across your git repos.
Python
3
star
30

purifier

Purifier is a very simple PHP class that allows to purify an HTML or BBcode input, authorize or delete the URLs you want, convert HTML to BBCode, and enable or disable JS scripts.
PHP
3
star
31

OpenDistro-Elasticsearch-Cluster-Docker

A fully functional OpenDistro cluster configuration (of 3 ElasticSearch nodes) with TLS enabled and explained. Run with Docker.
3
star
32

news-crawler

Playwright-powered modulable news crawler.
Python
2
star
33

haproxy-docker

Example of HAProxy implementation with Docker. Serving web servers.
2
star
34

software-privacy

Replace sensitive information and avoid personal data in any piece of software or content with programmable filters.
Python
2
star
35

python-multithread-example

Multi-threaded Python 3 script examples
Python
2
star
36

python-kafka-docker

A simple implementation of a Kafka cluster (3 brokers) with 1 producer and 1 consumer, deployed with Docker.
Python
2
star
37

12-bytes-compression

Algorithm for compressing digital values for SigFox frames of 12 bytes.
C++
2
star
38

deafboard

DeafBoard is a simple UI designed to facilitate the professional integration of deaf and/or dumb people using speech recognition, sign2text and text2sign technologies.
JavaScript
2
star
39

kubernetes-offline

Benefit Kubernetes on your local computer when on vacation ✈ī¸
Shell
2
star
40

json_makefile

A simple utility to convert a JSON file to a well-formatted Makefile.
TypeScript
1
star
41

keycloak-tls

TLS-configured Keycloak instance with Postgres database and Docker
Shell
1
star
42

sonarqube-docker-compose

Docker Compose files and example to easily getting you started with SonarQube
Python
1
star
43

kubernetes.io-docker

Download the whole Kubernetes.io documentation website
Dockerfile
1
star
44

CTF-BWK

A dockerized Capture The Flag challenge for computer science students. Get to know the basics !
PHP
1
star
45

klogger

A simple logger class for PHP, with JSON encoding possible.
PHP
1
star
46

elasticsearch-migration-tutorial

Companion repo to my blog post on migrating an Elasticsearch cluster without service disruption.
1
star
47

mobcamp

ETNA MobCamp pour le sujet "autonomisation des femmes en milieu agricole" pour la start-up LudoSchool.
PHP
1
star
48

etna-rank

Unofficial ranking page for ETNA students
JavaScript
1
star
49

lemonde-crawler

Browse articles from Le Monde's website and store them in a SQLite database.
Python
1
star
50

docker-iptables

Secure your Docker install with additional and understandable IPTables.
1
star
51

offthego

OffTheGo - Personal Offline Dashboard is an open-source json & javascript based interface for your projects.
1
star
52

Gitlab-Reward-System

A web service which implements a reward system with badges based on statistics using your Gitlab instance API.
TSQL
1
star
53

howto

Multi-scenarios CLI tool for tutorials, guides or stories.
Python
1
star
54

ToDevOps

A basic thus state-of-the-art architecture to start your DevOps stack learning.
Shell
1
star
55

clair-docker

Deployment-ready docker configuration and instructions to use Quay Clair on your infrastructure and CIs
Shell
1
star
56

sharepic

An instagram-like mobile app for an ETNA project (TIC-MOB2).
PHP
1
star
57

synapse-element-chat-docker

Start your own self-hosted, privacy-respectful, end-to-end encrypted chat and call application.
Dockerfile
1
star
58

backstage-docker-compose

Dockerized backstage configuration for development and production use.
Dockerfile
1
star
59

opensearch-k8s-certmanager

Add certs autorenewal capabilities to your OpenSearch cluster.
1
star
60

ubuntu-vpn-killswitch

Ubuntu configuration for implementing a killswitch when your VPN connection drops.
Shell
1
star
61

datahub-docker-compose

Getting started with LinkedIn's DataHub project on compose
Shell
1
star
62

rust-registry-offline

Run your own crate registry offline for Rust.
Rust
1
star