Skip to content

Commit 8fa0640

Browse files
committed
services: write config data to sidecar containers using scp
1 parent 726050f commit 8fa0640

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

src/backends/compose/compose_backend.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,14 @@ def get_service_container_name(self, service_name: str):
454454
def service_from_json(self, service_name: str) -> object:
455455
obj = services[service_name]
456456
volumes = obj.get("volumes", [])
457-
volumes += [f"{self.config_dir}" + filepath for filepath in obj.get("config_files", [])]
457+
for bind_mount in obj.get("config_files", []):
458+
volume_name, mount_path = bind_mount.split(":")
459+
hostpath = self.config_dir / volume_name
460+
# If it's starting off as an empty directory, create it now so
461+
# it has python-user permissions instead of docker-root
462+
if volume_name[-1] == "/":
463+
hostpath.mkdir(parents=True, exist_ok=True)
464+
volumes += [f"{hostpath}:{mount_path}"]
458465

459466
ports = []
460467
if "container_port" and "warnet_port" in obj:

src/backends/kubernetes/kubernetes_backend.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import logging
33
import re
4+
import subprocess
45
import time
56
from pathlib import Path
67
from typing import cast
@@ -779,3 +780,30 @@ def service_from_json(self, obj):
779780
self.client.create_namespaced_pod(namespace=self.namespace, body=service_pod)
780781
self.client.create_namespaced_service(namespace=self.namespace, body=service_service)
781782

783+
def write_service_config(self, source_path: str, service_name: str, destination_path: str):
784+
obj = services[service_name]
785+
name = obj["container_name_suffix"]
786+
container_name = "sidecar"
787+
# Copy the archive from our local drive (Warnet RPC container/pod)
788+
# to the destination service's sidecar container via ssh
789+
self.log.info(f"Copying local {source_path} to remote {destination_path} for {service_name}")
790+
subprocess.run([
791+
"scp",
792+
"-o", "StrictHostKeyChecking=accept-new",
793+
source_path,
794+
f"root@{name}-service.{self.namespace}:/arbitrary_filename.tar"])
795+
self.log.info(f"Finished copying tarball for {service_name}, unpacking...")
796+
# Unpack the archive
797+
stream(
798+
self.client.connect_get_namespaced_pod_exec,
799+
name,
800+
self.namespace,
801+
container=container_name,
802+
command=["/bin/sh", "-c", f"tar -xf /arbitrary_filename.tar -C {destination_path}"],
803+
stderr=True,
804+
stdin=False,
805+
stdout=True,
806+
tty=False,
807+
_preload_content=False
808+
)
809+
self.log.info(f"Finished unpacking config data for {service_name} to {destination_path}")

src/warnet/services.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"container_name_suffix": "fork-observer",
3232
"warnet_port": "23001",
3333
"container_port": "2323",
34-
"config_files": [f"/{FO_CONF_NAME}:/app/config.toml"],
34+
"config_files": [f"{FO_CONF_NAME}:/app/config.toml"],
3535
},
3636
"grafana": {
3737
"backends": ["compose"],
@@ -43,8 +43,8 @@
4343
"grafana-storage:/var/lib/grafana"
4444
],
4545
"config_files": [
46-
f"/{GRAFANA_PROVISIONING}/datasources:/etc/grafana/provisioning/datasources",
47-
f"/{GRAFANA_PROVISIONING}/dashboards:/etc/grafana/provisioning/dashboards",
46+
f"{GRAFANA_PROVISIONING}/datasources:/etc/grafana/provisioning/datasources",
47+
f"{GRAFANA_PROVISIONING}/dashboards:/etc/grafana/provisioning/dashboards",
4848
],
4949
"environment": [
5050
"GF_LOG_LEVEL=debug",
@@ -76,7 +76,17 @@
7676
"container_name_suffix": "prometheus",
7777
"warnet_port": "23004",
7878
"container_port": "9090",
79-
"config_files": [f"/{PROM_CONF_NAME}:/etc/prometheus/prometheus.yml"],
79+
"config_files": [f"{PROM_CONF_NAME}:/etc/prometheus/prometheus.yml"],
8080
"args": ["--config.file=/etc/prometheus/prometheus.yml"]
81-
}
81+
},
82+
"simln": {
83+
"backends": ["compose", "k8s"],
84+
"image": "bitcoindevproject/simln:0.2.0",
85+
"container_name_suffix": "simln",
86+
"environment": [
87+
"LOG_LEVEL=debug",
88+
"SIMFILE_PATH=/simln/sim.json"
89+
],
90+
"config_files": ["simln/:/simln"]
91+
},
8292
}

0 commit comments

Comments
 (0)