Skip to content

Commit

Permalink
feat: run formicaio and node containers on host network instead of br…
Browse files Browse the repository at this point in the history
…idge
  • Loading branch information
bochaco committed Jan 10, 2025
1 parent 230aeac commit 25efbcd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ COPY --from=builder /app/Cargo.toml /app/

# Set any required env variables and
ENV RUST_LOG="info"
ENV LEPTOS_SITE_ADDR="0.0.0.0:8080"
ENV LEPTOS_SITE_ADDR="0.0.0.0:52100"
ENV LEPTOS_SITE_ROOT="site"

EXPOSE 8080
EXPOSE 52100

# Run the server
CMD ["/app/formicaio"]
4 changes: 1 addition & 3 deletions deploy/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ services:
privileged: true
depends_on:
- docker
network_mode: bridge
network_mode: host
stop_grace_period: 5s
ports:
- "52100:8080"
environment:
NODE_CONTAINER_IMAGE_TAG: latest
DOCKER_SOCKET_PATH: /var/run/docker.sock
Expand Down
2 changes: 1 addition & 1 deletion deploy/local/k8s/formicaio-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
image: docker.io/library/docker@sha256:b0c1179ea32ad77bdb7b852b037e54b11022304c2f2662af1954ef53869314b2
name: docker
ports:
- containerPort: 8080
- containerPort: 52100
hostPort: 52100
resources: {}
securityContext:
Expand Down
12 changes: 4 additions & 8 deletions formica.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ FROM debian:bookworm-slim AS runtime
WORKDIR /app

RUN apt-get update -y \
# Temporary fix to use nginx since the node metrics server is exposed only at ip 127.0.0.1
&& apt-get install -y nginx \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -44,18 +42,16 @@ ENV REWARDS_ADDR_ARG=''
# If this not enabled and the node is behind a NAT, the node is terminated.
ENV HOME_NETWORK_ARG='--home-network'

EXPOSE $NODE_PORT
EXPOSE $METRICS_PORT
#EXPOSE $NODE_PORT/udp
#EXPOSE $METRICS_PORT/tcp

# Run the node
CMD ["sh", "-c", \
"echo \"server { listen ${METRICS_PORT}; server_name localhost; location /metrics { proxy_pass http://127.0.0.1:9090/metrics; include /etc/nginx/proxy_params; } }\" > /etc/nginx/sites-available/default \
&& nginx \
&& if [ -e '/app/node_data/secret-key-recycle' ]; then rm -f /app/node_data/secret-key*; fi \
"if [ -e '/app/node_data/secret-key-recycle' ]; then rm -f /app/node_data/secret-key*; fi \
&& /app/antnode \
${HOME_NETWORK_ARG} \
--port ${NODE_PORT} \
--metrics-server-port 9090 \
--metrics-server-port ${METRICS_PORT} \
--root-dir /app/node_data \
--log-output-dest /app/node_data/logs \
--bootstrap-cache-dir /app/node_data \
Expand Down
2 changes: 1 addition & 1 deletion src/bg_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ async fn update_nodes_info(
)];
if num_active_nodes > 0 {
let weighted_avg = if weights > 0 { net_size / weights } else { 0 };
let bin_versions = bin_version.into_iter().collect::<Vec<_>>().join(",");
let bin_versions = bin_version.into_iter().collect::<Vec<_>>().join(", ");

updated_vals.extend([
(LCD_LABEL_NET_SIZE, weighted_avg.to_string()),
Expand Down
15 changes: 8 additions & 7 deletions src/docker_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl DockerClient {
let url = format!("{DOCKER_CONTAINERS_API}/create");
// we don't expose/map the metrics_port from here since we had to expose it
// with nginx from within the dockerfile.
let mapped_ports = [port];
let mapped_ports = [(port, "udp"), (metrics_port, "tcp")];

let mut labels = vec![
(LABEL_KEY_VERSION.to_string(), self.node_image_tag.clone()),
Expand Down Expand Up @@ -336,22 +336,23 @@ impl DockerClient {
ExposedPorts: Some(
mapped_ports
.iter()
.map(|p| (format!("{p}/tcp"), HashMap::default()))
.map(|(port, proto)| (format!("{port}/{proto}"), HashMap::default()))
.collect::<ExposedPorts>(),
),
StopSignal: Some("SIGINT".to_string()),
StopTimeout: Some(5),
HostConfig: Some(HostConfigCreate {
NetworkMode: None,
NetworkMode: Some("host".to_string()),
PublishAllPorts: Some(false),
PortBindings: Some(
mapped_ports
.iter()
.map(|p| {
.map(|(port, proto)| {
(
format!("{p}/tcp"),
format!("{port}/{proto}"),
vec![PortBinding {
HostIp: None,
HostPort: p.to_string(),
HostIp: Some("0.0.0.0".to_string()),
HostPort: port.to_string(),
}],
)
})
Expand Down
1 change: 1 addition & 0 deletions src/docker_msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub struct ContainerCreate {
pub Labels: Option<HashMap<String, String>>,
pub Env: Option<Vec<String>>,
pub ExposedPorts: Option<ExposedPorts>,
pub StopSignal: Option<String>,
pub StopTimeout: Option<i64>,
pub HostConfig: Option<HostConfigCreate>,
}
Expand Down

0 comments on commit 25efbcd

Please sign in to comment.