Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deployment): cdk8s refactor #2468

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/sequencer/presets/config-batcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"strk_fee_token_address": "0x7",
"batcher_config.storage.db_config.path_prefix": "/data",
"batcher_config.storage.db_config.enforce_file_exists": false,
"validator_id" : "0x1"
}
1 change: 0 additions & 1 deletion deployments/images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# More info on Cargo Chef: https://github.com/LukeMathWalker/cargo-chef

FROM ubuntu:22.04 AS base
# WORKDIR /app

COPY scripts/install_build_tools.sh .
COPY scripts/dependencies.sh .
Expand Down
11 changes: 6 additions & 5 deletions deployments/images/sequencer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# syntax = devthefuture/dockerfile-x
#syntax = devthefuture/dockerfile-x

INCLUDE deployments/images/base/Dockerfile


# Compile the sequencer_node crate in release mode, ensuring dependencies are locked.
FROM base AS builder
WORKDIR /app
COPY . .
RUN cargo build --release --package starknet_sequencer_node
RUN cargo build --bin starknet_sequencer_node

FROM base AS sequencer

ENV ID=1000
WORKDIR /app
COPY --from=builder /target/release/starknet_sequencer_node /app/target/release/starknet_sequencer_node
COPY --from=builder /app/target/debug/starknet_sequencer_node ./target/debug/starknet_sequencer_node

# Copy sequencer config
COPY config/sequencer config/sequencer
COPY config/sequencer/default_config.json /config/sequencer/

# Create a new user "sequencer".
RUN set -ex; \
Expand All @@ -30,4 +31,4 @@ EXPOSE 8080 8081 8082
USER ${ID}

# Set the entrypoint to use tini to manage the process.
ENTRYPOINT ["tini", "--", "/app/target/release/starknet_sequencer_node"]
ENTRYPOINT ["tini", "--", "/app/target/debug/starknet_sequencer_node"]
3 changes: 3 additions & 0 deletions deployments/sequencer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
.idea/
services/test.py
341 changes: 148 additions & 193 deletions deployments/sequencer/app/service.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions deployments/sequencer/config/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class SequencerDevConfig(Config):
def __init__(self, mount_path: str, config_file_path: str = ""):
def __init__(self, config_file_path: str = ""):
super().__init__(
global_config=json.loads(
open(os.path.join(CONFIG_DIR, "default_config.json"), "r").read()
Expand All @@ -19,8 +19,7 @@ def __init__(self, mount_path: str, config_file_path: str = ""):
json.loads(open(os.path.join(CONFIG_DIR, "presets", "config.json"), "r").read())
if not config_file_path
else json.loads(open(os.path.abspath(config_file_path)).read())
),
mount_path=mount_path,
)
)

def validate(self):
Expand Down
Binary file not shown.
Binary file modified deployments/sequencer/imports/k8s/_jsii/k8s@0.0.0.jsii.tgz
Binary file not shown.
6 changes: 3 additions & 3 deletions deployments/sequencer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def __post_init__(self):

class SequencerNode(Chart):
def __init__(
self, scope: Construct, name: str, namespace: str, topology: topology.ServiceTopology
self, scope: Construct, name: str, namespace: str, service_topology: topology.ServiceTopology
):
super().__init__(scope, name, disable_resource_name_hashes=True, namespace=namespace)
self.service = ServiceApp(self, name, namespace=namespace, topology=topology)
self.service = ServiceApp(self, name, namespace=namespace, service_topology=service_topology)


def main():
Expand All @@ -45,7 +45,7 @@ def main():
scope=app,
name="sequencer-node",
namespace=args.namespace,
topology=system_preset,
service_topology=system_preset,
)

app.synth()
Expand Down
10 changes: 8 additions & 2 deletions deployments/sequencer/services/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum

# k8s service types
class ServiceType(Enum):
class ServiceType(str, Enum):
CLUSTER_IP = "ClusterIP"
LOAD_BALANCER = "LoadBalancer"
NODE_PORT = "NodePort"
Expand All @@ -14,5 +14,11 @@ class ServiceType(Enum):

# k8s service ports
HTTP_SERVICE_PORT = 80
RPC_SERVICE_PORT = 8081
GRPC_SERVICE_PORT = 8081
MONITORING_SERVICE_PORT = 8082

PROBE_FAILURE_THRESHOLD = 5
PROBE_PERIOD_SECONDS = 10
PROBE_TIMEOUT_SECONDS = 5

CONTAINER_ARGS = ["--config_file", "/config/sequencer/presets/config"]
6 changes: 4 additions & 2 deletions deployments/sequencer/services/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ class PersistentVolumeClaim:
class Config:
global_config: Dict[Any, Any]
config: Dict[Any, Any]
mount_path: str

def _merged_config(self) -> Dict[Any, Any]:
_config = self.global_config.copy()
_config.update(self.config)
return _config

def get_config(self):
def get_merged_config(self):
return self._merged_config()

def get_config(self):
return self.config

def validate(self):
pass

Expand Down
4 changes: 3 additions & 1 deletion deployments/sequencer/services/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

@dataclasses.dataclass
class ServiceTopology:
images: typing.Optional[typing.Mapping] = dataclasses.field(
default_factory=topology_helpers.get_images
)
deployment: typing.Optional[objects.Deployment] = dataclasses.field(
default_factory=topology_helpers.get_deployment
)
Expand All @@ -23,7 +26,6 @@ class ServiceTopology:
default_factory=topology_helpers.get_ingress
)


class SequencerDev(ServiceTopology):
pass

Expand Down
27 changes: 20 additions & 7 deletions deployments/sequencer/services/topology_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
from services import objects, const, helpers
from services import objects, const
from config.sequencer import SequencerDevConfig


# replicas
# types
# config
# validators

cluster_name = "gcp-integration"
replicas = 1

def get_images():
return {
"sequencer": "us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.11"
}

def get_pvc() -> objects.PersistentVolumeClaim:
return objects.PersistentVolumeClaim(
access_modes=["ReadWriteOnce"],
Expand All @@ -15,7 +28,7 @@ def get_pvc() -> objects.PersistentVolumeClaim:

def get_dev_config(config_file_path: str) -> objects.Config:
return SequencerDevConfig(
mount_path="/config/sequencer/presets/", config_file_path=config_file_path
config_file_path=config_file_path
)


Expand All @@ -34,7 +47,7 @@ def get_ingress(url: str = "test.gcp-integration.sw-dev.io") -> objects.Ingress:
host=url,
paths=[
objects.IngressRuleHttpPath(
path="/monitoring/",
path="/monitoring",
path_type="Prefix",
backend_service_name="sequencer-node-service",
backend_service_port_number=const.MONITORING_SERVICE_PORT,
Expand All @@ -58,7 +71,7 @@ def get_service() -> objects.Service:
),
objects.PortMapping(
name="rpc",
port=const.RPC_SERVICE_PORT,
port=const.GRPC_SERVICE_PORT,
container_port=const.RPC_CONTAINER_PORT,
),
objects.PortMapping(
Expand All @@ -77,8 +90,8 @@ def get_deployment() -> objects.Deployment:
containers=[
objects.Container(
name="server",
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.3",
args=["--config_file", "/config/sequencer/presets/config"],
image="us.gcr.io/starkware-dev/sequencer-node-test:0.0.1-dev.8",
args=["--config_file", "/app/config/sequencer/presets/config"],
ports=[
objects.ContainerPort(container_port=const.HTTP_CONTAINER_PORT),
objects.ContainerPort(container_port=const.RPC_CONTAINER_PORT),
Expand Down Expand Up @@ -108,7 +121,7 @@ def get_deployment() -> objects.Deployment:
volume_mounts=[
objects.VolumeMount(
name="config",
mount_path="/config/sequencer/presets/",
mount_path="/app/config/sequencer/presets/",
read_only=True,
),
objects.VolumeMount(name="data", mount_path="/data", read_only=False),
Expand Down
Loading