Skip to content

Commit 57cd7c7

Browse files
committed
node: separate gnd out to a crate
1 parent 68ff0d0 commit 57cd7c7

File tree

11 files changed

+118
-107
lines changed

11 files changed

+118
-107
lines changed

.github/workflows/gnd-binary-build.yml

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,17 @@ jobs:
4646
if: startsWith(matrix.runner, 'ubuntu')
4747
run: |
4848
sudo apt-get update
49-
sudo apt-get install -y libpq-dev protobuf-compiler musl-tools libssl-dev
49+
sudo apt-get install -y protobuf-compiler musl-tools
5050
5151
- name: Install dependencies (macOS)
5252
if: startsWith(matrix.runner, 'macos')
5353
run: |
54-
brew install postgresql protobuf
54+
brew install protobuf
5555
5656
- name: Install protobuf (Windows)
5757
if: startsWith(matrix.runner, 'windows')
5858
run: choco install protoc
5959

60-
- name: Cache vcpkg
61-
uses: actions/cache@v4
62-
if: startsWith(matrix.runner, 'windows')
63-
id: vcpkg-cache
64-
with:
65-
path: |
66-
${{ github.workspace }}/vcpkg
67-
C:/vcpkg/installed
68-
C:/vcpkg/packages
69-
key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/Cargo.lock') }}
70-
restore-keys: |
71-
${{ runner.os }}-vcpkg-
72-
73-
- name: Install vcpkg and dependencies (Windows)
74-
if: startsWith(matrix.runner, 'windows') && steps.vcpkg-cache.outputs.cache-hit != 'true'
75-
run: |
76-
# Install vcpkg
77-
git clone https://github.com/microsoft/vcpkg.git
78-
cd vcpkg
79-
.\bootstrap-vcpkg.bat
80-
81-
# Install libpq using vcpkg
82-
.\vcpkg.exe install libpq:x64-windows
83-
shell: pwsh
84-
85-
- name: Set Windows environment variables
86-
if: startsWith(matrix.runner, 'windows')
87-
run: |
88-
echo "VCPKG_ROOT=${{ github.workspace }}/vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Append
89-
echo "LIBPQ_DIR=${{ github.workspace }}/vcpkg/installed/x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append
90-
echo "RUSTFLAGS=-L ${{ github.workspace }}/vcpkg/installed/x64-windows/lib" | Out-File -FilePath $env:GITHUB_ENV -Append
91-
shell: pwsh
9260

9361
- name: Build gnd binary (Unix/Mac)
9462
if: ${{ !startsWith(matrix.runner, 'windows') }}
@@ -97,9 +65,6 @@ jobs:
9765
- name: Build gnd binary (Windows)
9866
if: startsWith(matrix.runner, 'windows')
9967
run: cargo build --bin gnd --release --target ${{ matrix.target }}
100-
env:
101-
LIBPQ_DIR: ${{ format('{0}/vcpkg/installed/x64-windows', github.workspace) }}
102-
VCPKGRS_DYNAMIC: 1
10368

10469
- name: Sign macOS binary
10570
if: startsWith(matrix.runner, 'macos')

Cargo.lock

Lines changed: 39 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"chain/ethereum",
99
"chain/near",
1010
"chain/substreams",
11+
"gnd",
1112
"graphql",
1213
"node",
1314
"runtime/derive",

gnd/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "gnd"
3+
version.workspace = true
4+
edition.workspace = true
5+
6+
[[bin]]
7+
name = "gnd"
8+
path = "src/main.rs"
9+
10+
[dependencies]
11+
# Core graph dependencies
12+
graph = { path = "../graph" }
13+
graph-core = { path = "../core" }
14+
graph-node = { path = "../node" }
15+
16+
# Direct dependencies from current dev.rs
17+
anyhow = { workspace = true }
18+
clap = { workspace = true }
19+
env_logger = "0.11.8"
20+
git-testament = "0.2"
21+
lazy_static = "1.5.0"
22+
tokio = { workspace = true }
23+
serde = { workspace = true }
24+
25+
# File watching
26+
notify = "8.2.0"
27+
globset = "0.4.16"
28+
pq-sys = { version = "0.7.2", features = ["bundled"] }
29+
openssl-sys = { version = "0.9.100", features = ["vendored"] }
30+
31+
[target.'cfg(unix)'.dependencies]
32+
pgtemp = { git = "https://github.com/graphprotocol/pgtemp", branch = "initdb-args" }
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
pub mod helpers;
21
pub mod watcher;

node/src/bin/dev.rs renamed to gnd/src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ use graph::{
1212
tokio::{self, sync::mpsc},
1313
};
1414
use graph_core::polling_monitor::ipfs_service;
15-
use graph_node::{
16-
dev::watcher,
17-
dev::watcher::{parse_manifest_args, watch_subgraphs},
18-
launcher,
19-
opt::Opt,
20-
};
15+
use graph_node::{launcher, opt::Opt};
2116
use lazy_static::lazy_static;
2217

18+
use gnd::watcher::{deploy_all_subgraphs, parse_manifest_args, watch_subgraphs};
19+
2320
#[cfg(unix)]
2421
use pgtemp::{PgTempDB, PgTempDBBuilder};
2522

2623
// Add an alias for the temporary Postgres DB handle. On non unix
27-
// targets we dont have pgtemp, but we still need the type to satisfy the
24+
// targets we don't have pgtemp, but we still need the type to satisfy the
2825
// function signatures.
2926
#[cfg(unix)]
3027
type TempPgDB = PgTempDB;
@@ -39,7 +36,7 @@ lazy_static! {
3936
#[derive(Clone, Debug, Parser)]
4037
#[clap(
4138
name = "gnd",
42-
about = "Graph Node Dev",
39+
about = "Graph Node Dev",
4340
author = "Graph Protocol, Inc.",
4441
version = RENDERED_TESTAMENT.as_str()
4542
)]
@@ -259,8 +256,7 @@ async fn main() -> Result<()> {
259256
});
260257

261258
if let Err(e) =
262-
watcher::deploy_all_subgraphs(&logger, &manifests_paths, &source_subgraph_aliases, &tx)
263-
.await
259+
deploy_all_subgraphs(&logger, &manifests_paths, &source_subgraph_aliases, &tx).await
264260
{
265261
error!(logger, "Error deploying subgraphs"; "error" => e.to_string());
266262
std::process::exit(1);

node/src/dev/watcher.rs renamed to gnd/src/watcher.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,43 @@ use std::path::{Path, PathBuf};
99
use std::sync::mpsc;
1010
use std::time::Duration;
1111

12-
use super::helpers::{parse_alias, parse_manifest_arg};
13-
1412
const WATCH_DELAY: Duration = Duration::from_secs(5);
1513
const DEFAULT_BUILD_DIR: &str = "build";
1614

15+
/// Parse an alias string into a tuple of (alias_name, manifest, Option<build_dir>)
16+
pub fn parse_alias(alias: &str) -> anyhow::Result<(String, String, Option<String>)> {
17+
let mut split = alias.split(':');
18+
let alias_name = split.next();
19+
let alias_value = split.next();
20+
21+
if alias_name.is_none() || alias_value.is_none() || split.next().is_some() {
22+
return Err(anyhow::anyhow!(
23+
"Invalid alias format: expected 'alias=[BUILD_DIR:]manifest', got '{}'",
24+
alias
25+
));
26+
}
27+
28+
let alias_name = alias_name.unwrap().to_owned();
29+
let (manifest, build_dir) = parse_manifest_arg(alias_value.unwrap())
30+
.with_context(|| format!("While parsing alias '{}'", alias))?;
31+
32+
Ok((alias_name, manifest, build_dir))
33+
}
34+
35+
/// Parse a manifest string into a tuple of (manifest, Option<build_dir>)
36+
pub fn parse_manifest_arg(value: &str) -> anyhow::Result<(String, Option<String>)> {
37+
match value.split_once(':') {
38+
Some((manifest, build_dir)) if !manifest.is_empty() => {
39+
Ok((manifest.to_owned(), Some(build_dir.to_owned())))
40+
}
41+
Some(_) => Err(anyhow::anyhow!(
42+
"Invalid manifest arg: missing manifest in '{}'",
43+
value
44+
)),
45+
None => Ok((value.to_owned(), None)),
46+
}
47+
}
48+
1749
// Parses manifest arguments and returns a vector of paths to the manifest files
1850
pub fn parse_manifest_args(
1951
manifests: Vec<String>,

node/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ path = "src/main.rs"
1212
name = "graphman"
1313
path = "src/bin/manager.rs"
1414

15-
[[bin]]
16-
name = "gnd"
17-
path = "src/bin/dev.rs"
18-
1915
[dependencies]
2016
anyhow = { workspace = true }
2117
env_logger = "0.11.8"
@@ -45,6 +41,3 @@ prometheus = { version = "0.14.0", features = ["push"] }
4541
json-structural-diff = { version = "0.2", features = ["colorize"] }
4642
globset = "0.4.16"
4743
notify = "8.2.0"
48-
49-
[target.'cfg(unix)'.dependencies]
50-
pgtemp = { git = "https://github.com/graphprotocol/pgtemp", branch = "initdb-args" }

node/src/dev/helpers.rs renamed to node/src/helpers.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use anyhow::{Context, Result};
3+
use anyhow::Result;
44
use graph::prelude::{
55
BlockPtr, DeploymentHash, NodeId, SubgraphRegistrarError, SubgraphStore as SubgraphStoreTrait,
66
};
@@ -12,11 +12,6 @@ use graph::{
1212
};
1313
use graph_store_postgres::SubgraphStore;
1414

15-
pub struct DevModeContext {
16-
pub watch: bool,
17-
pub updates_rx: Receiver<(DeploymentHash, SubgraphName)>,
18-
}
19-
2015
/// Cleanup a subgraph
2116
/// This is used to remove a subgraph before redeploying it when using the watch flag
2217
fn cleanup_dev_subgraph(
@@ -62,7 +57,7 @@ async fn deploy_subgraph(
6257
})
6358
}
6459

65-
pub async fn drop_and_recreate_subgraph(
60+
async fn drop_and_recreate_subgraph(
6661
logger: &Logger,
6762
subgraph_store: Arc<SubgraphStore>,
6863
subgraph_registrar: Arc<impl SubgraphRegistrar>,
@@ -124,37 +119,3 @@ pub async fn watch_subgraph_updates(
124119
error!(logger, "Subgraph watcher terminated unexpectedly"; "action" => "exiting");
125120
std::process::exit(1);
126121
}
127-
128-
/// Parse an alias string into a tuple of (alias_name, manifest, Option<build_dir>)
129-
pub fn parse_alias(alias: &str) -> anyhow::Result<(String, String, Option<String>)> {
130-
let mut split = alias.split(':');
131-
let alias_name = split.next();
132-
let alias_value = split.next();
133-
134-
if alias_name.is_none() || alias_value.is_none() || split.next().is_some() {
135-
return Err(anyhow::anyhow!(
136-
"Invalid alias format: expected 'alias=[BUILD_DIR:]manifest', got '{}'",
137-
alias
138-
));
139-
}
140-
141-
let alias_name = alias_name.unwrap().to_owned();
142-
let (manifest, build_dir) = parse_manifest_arg(alias_value.unwrap())
143-
.with_context(|| format!("While parsing alias '{}'", alias))?;
144-
145-
Ok((alias_name, manifest, build_dir))
146-
}
147-
148-
/// Parse a manifest string into a tuple of (manifest, Option<build_dir>)
149-
pub fn parse_manifest_arg(value: &str) -> anyhow::Result<(String, Option<String>)> {
150-
match value.split_once(':') {
151-
Some((manifest, build_dir)) if !manifest.is_empty() => {
152-
Ok((manifest.to_owned(), Some(build_dir.to_owned())))
153-
}
154-
Some(_) => Err(anyhow::anyhow!(
155-
"Invalid manifest arg: missing manifest in '{}'",
156-
value
157-
)),
158-
None => Ok((value.to_owned(), None)),
159-
}
160-
}

node/src/launcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use graph::futures03::compat::Future01CompatExt;
66
use graph::futures03::future::TryFutureExt;
77

88
use crate::config::Config;
9-
use crate::dev::helpers::watch_subgraph_updates;
9+
use crate::helpers::watch_subgraph_updates;
1010
use crate::network_setup::Networks;
1111
use crate::opt::Opt;
1212
use crate::store_builder::StoreBuilder;

0 commit comments

Comments
 (0)