Ivan
07/04/2024, 4:29 PMMarvin
07/04/2024, 4:30 PMyaml
   version: "3.9"
   services:
     operational_db:
       image: postgres:15.2-alpine
       restart: always
       environment:
         - POSTGRES_USER=postgres
         - POSTGRES_PASSWORD=postgres
         - POSTGRES_DB=prefect
       expose:
         - 5432
       volumes: 
         - db:/var/lib/postgresql/data
       profiles: ["server"]
     server:
       image: prefecthq/prefect:2.10.16-python3.11
       restart: always
       volumes:
         - prefect:/root/.prefect
       entrypoint: ["/opt/prefect/entrypoint.sh", "prefect", "server", "start"]
       environment:
         - PREFECT_UI_URL=<http://127.0.0.1:4200/api>
         - PREFECT_API_URL=<http://127.0.0.1:4200/api>
         - PREFECT_SERVER_API_HOST=0.0.0.0
         - PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@operational_db:5432/prefect>
       ports:
         - 4200:4200
       depends_on:
         - operational_db
       profiles: ["server"]
     agent:
       image: prefecthq/prefect:2.10.16-python3.11
       restart: always
       volumes:
         - temp:/root/temp
       entrypoint: ["prefect", "agent", "start", "-q", "default"]
       environment:
         - PREFECT_API_URL=<http://server:4200/api>
         - KEEPASS_DB=/root/keepass/prefect-keys.kdbx
         - DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@database:5433/reporting_automations>
       profiles: ["agent"]
   volumes:
     db:
     prefect:
     temp:
   networks:
     default:
       name: prefect-networkdocker-compose up<http://localhost:4200>Ivan
07/04/2024, 4:37 PMMarvin
07/04/2024, 4:38 PMdockerfile
# Use the official Prefect image as the base image
FROM prefecthq/prefect:2-python3.11
# Update and install system dependencies
RUN apt-get update && apt-get install -y gnupg2 curl apt-transport-https
# Set the working directory inside the container
WORKDIR /prefect-docker
# Copy the requirements.txt file to the working directory
COPY requirements.txt requirements.txt
# Install Python dependencies
RUN pip3 install -r requirements.txt
# Expose necessary ports (adjust as needed)
EXPOSE 4200
# Start the Prefect server
ENTRYPOINT ["prefect", "server", "start"]docker-compose.ymlyaml
version: "3.9"
services:
  database:
    image: postgres:14.1-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=prefectDatabase
    ports:
      - "5432:5432"
    volumes:
      - db:/var/lib/postgresql/data
  orion:
    build: .
    container_name: prefect_ui
    restart: always
    volumes:
      - prefect:/root/.prefect
    environment:
      - DB_HOST=database
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PREFECT_ORION_API_HOST=0.0.0.0
      - PREFECT_API_URL=<http://0.0.0.0:4200/api>
      - PREFECT_ORION_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@database:5432/prefectDatabase>
    ports:
      - "4200:4200"
volumes:
  db:
  prefect:Dockerfiledocker-compose.ymldocker-compose up --build<http://localhost:4200>Ivan
07/04/2024, 4:44 PMdockerfile
# Use the official Prefect image as the base image
FROM prefecthq/prefect:2-python3.11
# Update and install system dependencies
RUN apt-get update && apt-get install -y gnupg2 curl apt-transport-https
# Set the working directory inside the container
WORKDIR /prefect-docker
# Copy the requirements.txt file to the working directory
COPY requirements.txt requirements.txt
# Install Python dependencies
RUN pip3 install -r requirements.txt
# Expose necessary ports (adjust as needed)
EXPOSE 4200
# Start the Prefect server
ENTRYPOINT ["prefect", "server", "start"]version: "3.9"
services:
  database:
    image: postgres:14.1-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=prefectDatabase
    ports:
      - "5432:5432"
    volumes:
      - db:/var/lib/postgresql/data
  orion:
    build: .
    container_name: prefect_ui
    restart: always
    volumes:
      - prefect:/root/.prefect
    environment:
      - DB_HOST=database
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PREFECT_ORION_API_HOST=0.0.0.0
      - PREFECT_API_URL=<http://0.0.0.0:4200/api>
      - PREFECT_ORION_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@database:5432/prefectDatabase>
    ports:
      - "4200:4200"
volumes:
  db:
  prefect:Marvin
07/04/2024, 4:44 PMthis is my dockerfile:
dockerfile
# Use the official Prefect image as the base image
FROM prefecthq/prefect:2-python3.11
# Update and install system dependencies
RUN apt-get update && apt-get install -y gnupg2 curl apt-transport-https
# Set the working directory inside the container
WORKDIR /prefect-docker
# Copy the requirements.txt file to the working directory
COPY requirements.txt requirements.txt
# Install Python dependencies
RUN pip3 install -r requirements.txt
# Expose necessary ports (adjust as needed)
EXPOSE 4200
# Start the Prefect server
ENTRYPOINT ["prefect", "server", "start"]Ivan
07/04/2024, 4:45 PMMarvin
07/04/2024, 4:45 PMsh
   docker-compose pssh
   docker-compose logs -f oriondocker-compose.ymlyaml
   version: "3.9"
   services:
     database:
       image: postgres:14.1-alpine
       restart: always
       environment:
         - POSTGRES_USER=postgres
         - POSTGRES_PASSWORD=postgres
         - POSTGRES_DB=prefectDatabase
       ports:
         - "5432:5432"
       volumes:
         - db:/var/lib/postgresql/data
     orion:
       build: .
       container_name: prefect_ui
       restart: always
       environment:
         - DB_HOST=database
         - POSTGRES_USER=postgres
         - POSTGRES_PASSWORD=postgres
         - PREFECT_ORION_API_HOST=0.0.0.0
         - PREFECT_API_URL=<http://0.0.0.0:4200/api>
         - PREFECT_ORION_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@database:5432/prefectDatabase>
       ports:
         - "4200:4200"
       depends_on:
         - database
   volumes:
     db:
     prefect:sh
   docker exec -it prefect_ui curl <http://0.0.0.0:4200/api>Ivan
07/04/2024, 4:48 PMMarvin
07/04/2024, 4:48 PMsqlitePostgresdockerfile
# Use the official Prefect image as the base image
FROM prefecthq/prefect:2-python3.11
# Set working directory
WORKDIR /prefect
# Expose necessary ports
EXPOSE 4200
# Start the Prefect server
ENTRYPOINT ["prefect", "server", "start"]yaml
version: "3.9"
services:
  database:
    image: postgres:15.2-alpine
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=prefect
    ports:
      - "5432:5432"
    volumes:
      - db:/var/lib/postgresql/data
  prefect:
    build: .
    container_name: prefect_ui
    restart: always
    environment:
      - PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://postgres:postgres@database:5432/prefect>
      - PREFECT_SERVER_API_HOST=0.0.0.0
      - PREFECT_UI_URL=<http://0.0.0.0:4200>
      - PREFECT_API_URL=<http://0.0.0.0:4200/api>
    ports:
      - "4200:4200"
    depends_on:
      - database
    volumes:
      - prefect:/root/.prefect
volumes:
  db:
  prefect:sh
   docker-compose up --buildsh
   docker exec -it prefect_ui prefect database upgrade<http://localhost:4200>Ivan
07/04/2024, 4:56 PM/usr/local/lib/python3.11/contextlib.py:144: SAWarning: Skipped unsupported reflection of expression-based index ix_flow_run__coalesce_start_time_expected_start_time_asc
prefect_ui  |   next(self.gen)Ivan
07/05/2024, 3:38 AMMarvin
07/05/2024, 3:38 AMsh
   sqlite3 prefect.db .dump > prefect.db.sqlpg_restorepsqlsh
   sqlite3 prefect.db .dump > prefect.db.sqlsh
   gcloud sql instances create your-instance-name \
       --database-version=POSTGRES_13 \
       --cpu=1 --memory=4GB --region=your-regionsh
   gcloud sql databases create prefect --instance=your-instance-namesh
   ./cloud_sql_proxy -instances=your-project-id:your-region:your-instance-name=tcp:5432sh
   gsutil cp prefect.db.sql <gs://your-bucket-name>psqlsh
   psql "host=127.0.0.1 port=5432 sslmode=disable dbname=prefect user=your-db-username password=your-db-password" < prefect.db.sqlsh
   gcloud sql import sql your-instance-name <gs://your-bucket-name/prefect.db.sql> --database=prefectdocker-compose.ymlyaml
   version: "3.9"
   services:
     database:
       image: postgres:15.2-alpine
       restart: always
       environment:
         - POSTGRES_USER=your-db-username
         - POSTGRES_PASSWORD=your-db-password
         - POSTGRES_DB=prefect
       ports:
         - "5432:5432"
     prefect:
       build: .
       container_name: prefect_ui
       restart: always
       environment:
         - PREFECT_API_DATABASE_CONNECTION_URL=<postgresql+asyncpg://your-db-username:your-db-password@your-public-ip:5432/prefect>
         - PREFECT_SERVER_API_HOST=0.0.0.0
         - PREFECT_UI_URL=<http://0.0.0.0:4200>
         - PREFECT_API_URL=<http://0.0.0.0:4200/api>
       ports:
         - "4200:4200"
       depends_on:
         - database
       volumes:
         - prefect:/root/.prefect
   volumes:
     db:
     prefect:Ivan
07/05/2024, 4:13 AMMarvin
07/05/2024, 4:13 AMread_dataread_data@taskread_dataread_datatrain_modelpython
from prefect import task, flow
from google.cloud import storage
import pandas as pd
@task
def read_data(bucket_name: str, file_name: str) -> pd.DataFrame:
    client = storage.Client()
    bucket = client.bucket(bucket_name)
    blob = bucket.blob(file_name)
    with blob.open("r") as f:
        df = pd.read_csv(f)
    return df
@task
def train_model(data: pd.DataFrame):
    # Your training logic here
    print("Training model with data:")
    print(data.head())
@flow
def train_model_flow(bucket_name: str, file_name: str):
    data = read_data(bucket_name, file_name)
    train_model(data)
# Example usage:
if __name__ == "__main__":
    train_model_flow("your-gcs-bucket", "your-data-file.csv")read_dataIvan
07/05/2024, 4:34 AMMarvin
07/05/2024, 4:34 AMpython
from prefect import task, flow
@task
def fetch_data():
    return [1, 2, 3, 4, 5]
@task
def process_data(data):
    return [x * 2 for x in data]
@task
def save_data(data):
    print(f"Saved data: {data}")
@flow
def my_etl_flow():
    data = fetch_data()
    processed_data = process_data(data)
    save_data(processed_data)
if __name__ == "__main__":
    my_etl_flow()