|
| 1 | +# Copyright Materialize, Inc. and contributors. All rights reserved. |
| 2 | +# |
| 3 | +# Use of this software is governed by the Business Source License |
| 4 | +# included in the LICENSE file at the root of this repository. |
| 5 | +# |
| 6 | +# As of the Change Date specified in that file, in accordance with |
| 7 | +# the Business Source License, use of this software will be governed |
| 8 | +# by the Apache License, Version 2.0. |
| 9 | + |
| 10 | +import os |
| 11 | +from textwrap import dedent |
| 12 | + |
| 13 | +from materialize import MZ_ROOT |
| 14 | +from materialize.mzcompose import loader |
| 15 | +from materialize.mzcompose.service import ( |
| 16 | + Service, |
| 17 | + ServiceConfig, |
| 18 | +) |
| 19 | +from materialize.mzcompose.services.cockroach import Cockroach |
| 20 | + |
| 21 | + |
| 22 | +class FoundationDB(Service): |
| 23 | + def __init__( |
| 24 | + self, |
| 25 | + name: str = "foundationdb", |
| 26 | + image: str | None = None, |
| 27 | + ports: list[str] = ["4500"], |
| 28 | + environment: list[str] = [ |
| 29 | + "FDB_NETWORKING_MODE=container", |
| 30 | + ], |
| 31 | + volumes: list[str] = [], |
| 32 | + restart: str = "no", |
| 33 | + version: str = "7.3.71", |
| 34 | + ) -> None: |
| 35 | + # command: list[str] = [ |
| 36 | + # "postgres", |
| 37 | + # "-c", |
| 38 | + # "wal_level=logical", |
| 39 | + # "-c", |
| 40 | + # f"max_wal_senders={max_wal_senders}", |
| 41 | + # "-c", |
| 42 | + # f"max_replication_slots={max_replication_slots}", |
| 43 | + # "-c", |
| 44 | + # "max_connections=5000", |
| 45 | + # ] + extra_command |
| 46 | + |
| 47 | + # if setup_materialize: |
| 48 | + # path = os.path.relpath( |
| 49 | + # MZ_ROOT / "misc" / "postgres" / "setup_materialize.sql", |
| 50 | + # loader.composition_path, |
| 51 | + # ) |
| 52 | + # volumes = volumes + [ |
| 53 | + # f"{path}:/docker-entrypoint-initdb.d/z_setup_materialize.sql" |
| 54 | + # ] |
| 55 | + # |
| 56 | + # environment = environment + ["PGPORT=26257"] |
| 57 | + |
| 58 | + env_extra = [ |
| 59 | + f"FDB_COORDINATOR_PORT={ports[0]}", |
| 60 | + f"FDB_PORT={ports[0]}", |
| 61 | + ] |
| 62 | + |
| 63 | + # command = dedent( |
| 64 | + # """ |
| 65 | + # /usr/bin/tini -g -- /var/fdb/scripts/fdb.bash & |
| 66 | + # sleep 5 |
| 67 | + # fdbcli -C /etc/foundationdb/fdb.cluster --exec "configure new single memory" |
| 68 | + # fdbcli -C /etc/foundationdb/fdb.cluster --exec "status" |
| 69 | + # wait |
| 70 | + # """ |
| 71 | + # ) |
| 72 | + |
| 73 | + if image is None: |
| 74 | + image = f"foundationdb/foundationdb:{version}" |
| 75 | + |
| 76 | + config: ServiceConfig = {"image": image} |
| 77 | + |
| 78 | + volumes += [f"{MZ_ROOT}/misc/foundationdb/:/etc/foundationdb/"] |
| 79 | + |
| 80 | + config.update( |
| 81 | + { |
| 82 | + "image": image, |
| 83 | + # "allow_host_ports": True, |
| 84 | + # "command": ["bash", "-c", command], |
| 85 | + "ports": ports, |
| 86 | + "environment": env_extra + environment, |
| 87 | + # "healthcheck": { |
| 88 | + # "test": [ |
| 89 | + # "CMD", |
| 90 | + # "fdbcli", |
| 91 | + # "--exec", |
| 92 | + # "configure single memory ; status", |
| 93 | + # ], |
| 94 | + # "interval": "1s", |
| 95 | + # "start_period": "30s", |
| 96 | + # }, |
| 97 | + "restart": restart, |
| 98 | + "volumes": volumes, |
| 99 | + } |
| 100 | + ) |
| 101 | + super().__init__(name=name, config=config) |
| 102 | + |
| 103 | + |
| 104 | +# class PostgresMetadata(Postgres): |
| 105 | +# def __init__(self, restart: str = "no") -> None: |
| 106 | +# super().__init__( |
| 107 | +# name="postgres-metadata", |
| 108 | +# setup_materialize=True, |
| 109 | +# ports=["26257"], |
| 110 | +# restart=restart, |
| 111 | +# ) |
| 112 | + |
| 113 | + |
| 114 | +# CockroachOrPostgresMetadata = ( |
| 115 | +# Cockroach if os.getenv("BUILDKITE_TAG", "") != "" else PostgresMetadata |
| 116 | +# ) |
| 117 | +# |
| 118 | +# METADATA_STORE: str = ( |
| 119 | +# "cockroach" if CockroachOrPostgresMetadata == Cockroach else "postgres-metadata" |
| 120 | +# ) |
0 commit comments