Skip to content

Commit

Permalink
fix: yeet openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-eiger committed May 19, 2024
1 parent 60d00be commit a944d51
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 1,050 deletions.
1,345 changes: 325 additions & 1,020 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ panic = 'unwind'
opt-level = 3

[workspace.dependencies]
graphcast-sdk = "0.7.1"
graphcast-sdk = { git="https://github.com/graphops/graphcast-sdk", branch = "petko/yeet-openssl"}
clap = { version = "4.4", features = [
"cargo",
"unstable-doc",
Expand Down
36 changes: 24 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Build Stage
FROM rust:1-bullseye AS build-image

# Update and install necessary packages, including libc6-dev for libresolv
# Update and install necessary packages, including profiling tools
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
wget \
curl \
libpq-dev \
pkg-config \
libssl-dev \
clang \
build-essential \
libc6-dev \
heaptrack \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -31,19 +32,30 @@ ENV RUSTFLAGS="-C link-arg=-lresolv"
# Build the Rust project
RUN cargo build --release -p subgraph-radio

# Setup the runtime environment
FROM alpine:3.17.3 as alpine
RUN set -x \
&& apk update \
&& apk add --no-cache upx dumb-init
COPY --from=build-image /subgraph-radio/target/release/subgraph-radio /subgraph-radio/target/release/subgraph-radio
RUN upx --overlay=strip --best /subgraph-radio/target/release/subgraph-radio
# Check if the binary is successfully built
RUN ls -lh /subgraph-radio/target/release/

# Runtime Stage
FROM debian:bullseye-slim as runtime

# Update and install necessary packages, including heaptrack dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libc6-dev \
heaptrack \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy necessary files from the build stage
COPY --from=build-image /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=build-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build-image /etc/passwd /etc/passwd
COPY --from=build-image /etc/group /etc/group
COPY --from=alpine /usr/bin/dumb-init /usr/bin/dumb-init
COPY --from=alpine "/subgraph-radio/target/release/subgraph-radio" "/usr/local/bin/subgraph-radio"
ENTRYPOINT [ "/usr/bin/dumb-init", "--", "/usr/local/bin/subgraph-radio" ]
COPY --from=build-image /usr/bin/heaptrack /usr/bin/heaptrack
COPY --from=build-image /subgraph-radio/target/release/subgraph-radio /usr/local/bin/subgraph-radio

# Ensure the binary exists in the correct path
RUN ls -lh /usr/local/bin/subgraph-radio

# Set the entry point to run the application
ENTRYPOINT [ "/usr/local/bin/subgraph-radio" ]
2 changes: 1 addition & 1 deletion subgraph-radio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tokio = { version = "1.28.1", features = ["full", "rt"] }
anyhow = "1.0"
graphql_client = "0.12.0"
serde_derive = "1.0"
reqwest = { version = "0.11.17", features = ["json"] }
reqwest = { version = "0.11.24", default-features = false, features = ["json", "rustls-tls"] }
thiserror = "1.0.40"
ethers = "2.0.4"
ethers-contract = "2.0.4"
Expand Down
27 changes: 26 additions & 1 deletion subgraph-radio/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use graphcast_sdk::{
init_tracing, wallet_address, GraphcastNetworkName, LogFormat,
};
use graphcast_sdk::{cf_nameserver, Account};
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::net::UdpSocket;
use tracing::info;

use crate::metrics::NUM_TOPICS;
Expand Down Expand Up @@ -142,6 +144,29 @@ impl Config {
}
}

pub fn find_random_udp_port() -> u16 {
let mut rng = rand::thread_rng();
let mut port = 0;

for _ in 0..10 {
// Generate a random port number within the range 49152 to 65535
let test_port = rng.gen_range(49152..=65535);
match UdpSocket::bind(("0.0.0.0", test_port)) {
Ok(_) => {
port = test_port;
break;
}
Err(_) => continue,
}
}

if port == 0 {
panic!("Could not find a free port");
}

port
}

pub async fn to_graphcast_agent_config(
&self,
) -> Result<GraphcastAgentConfig, GraphcastAgentError> {
Expand All @@ -165,7 +190,7 @@ impl Config {
self.waku().waku_addr.clone(),
self.waku().filter_protocol,
self.waku().discv5_enrs.clone(),
self.waku().discv5_port,
Some(Self::find_random_udp_port()),
self.waku().discv5_enrs.clone().unwrap_or_default(),
Some(cf_nameserver().to_string()),
)
Expand Down
2 changes: 1 addition & 1 deletion subgraph-radio/src/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl RadioOperator {
debug!("Set global static instance of graphcast_agent");
_ = GRAPHCAST_AGENT.set(graphcast_agent.clone());

config.validate_indexer_address().await;
// config.validate_indexer_address().await;

//TODO: Refactor indexer management server validation to SDK, similar to graph node status endpoint
if let Some(url) = &config.graph_stack.indexer_management_server_endpoint {
Expand Down
26 changes: 13 additions & 13 deletions subgraph-radio/src/operator/notifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use derive_getters::Getters;
use graphcast_sdk::bots::{DiscordBot, SlackBot, TelegramBot};
use graphcast_sdk::bots::{DiscordBot, SlackBot};

use serde_derive::{Deserialize, Serialize};
use sqlx::FromRow;
Expand Down Expand Up @@ -88,18 +88,18 @@ impl Notifier {
}
}

if let (Some(token), Some(chat_id)) = (self.telegram_token.clone(), self.telegram_chat_id) {
let telegram_bot = TelegramBot::new(token);
if let Err(e) = telegram_bot
.send_message(chat_id, &self.radio_name, &content)
.await
{
warn!(
err = tracing::field::debug(e),
"Failed to send notification to Telegram"
);
}
}
// if let (Some(token), Some(chat_id)) = (self.telegram_token.clone(), self.telegram_chat_id) {
// let telegram_bot = TelegramBot::new(token);
// if let Err(e) = telegram_bot
// .send_message(chat_id, &self.radio_name, &content)
// .await
// {
// warn!(
// err = tracing::field::debug(e),
// "Failed to send notification to Telegram"
// );
// }
// }
}
}

Expand Down
2 changes: 1 addition & 1 deletion test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub async fn setup(
test_file_name: &str,
test_sender_config: &mut TestSenderConfig,
) -> ProcessManager {
let id = uuid::Uuid::new_v4().to_string();
let id = uuid::Uuid::default();
let radio_name = format!("{}-{}", test_file_name, id);
test_sender_config.radio_name = radio_name.clone();

Expand Down

0 comments on commit a944d51

Please sign in to comment.