Skip to content
Merged
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
39 changes: 2 additions & 37 deletions .github/workflows/gnd-binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,17 @@ jobs:
if: startsWith(matrix.runner, 'ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev protobuf-compiler musl-tools libssl-dev
sudo apt-get install -y protobuf-compiler musl-tools

- name: Install dependencies (macOS)
if: startsWith(matrix.runner, 'macos')
run: |
brew install postgresql protobuf
brew install protobuf

- name: Install protobuf (Windows)
if: startsWith(matrix.runner, 'windows')
run: choco install protoc

- name: Cache vcpkg
uses: actions/cache@v4
if: startsWith(matrix.runner, 'windows')
id: vcpkg-cache
with:
path: |
${{ github.workspace }}/vcpkg
C:/vcpkg/installed
C:/vcpkg/packages
key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-vcpkg-

- name: Install vcpkg and dependencies (Windows)
if: startsWith(matrix.runner, 'windows') && steps.vcpkg-cache.outputs.cache-hit != 'true'
run: |
# Install vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat

# Install libpq using vcpkg
.\vcpkg.exe install libpq:x64-windows
shell: pwsh

- name: Set Windows environment variables
if: startsWith(matrix.runner, 'windows')
run: |
echo "VCPKG_ROOT=${{ github.workspace }}/vcpkg" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "LIBPQ_DIR=${{ github.workspace }}/vcpkg/installed/x64-windows" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "RUSTFLAGS=-L ${{ github.workspace }}/vcpkg/installed/x64-windows/lib" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh

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

- name: Sign macOS binary
if: startsWith(matrix.runner, 'macos')
Expand Down
46 changes: 39 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"chain/ethereum",
"chain/near",
"chain/substreams",
"gnd",
"graphql",
"node",
"runtime/derive",
Expand Down
32 changes: 32 additions & 0 deletions gnd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "gnd"
version.workspace = true
edition.workspace = true

[[bin]]
name = "gnd"
path = "src/main.rs"

[dependencies]
# Core graph dependencies
graph = { path = "../graph" }
graph-core = { path = "../core" }
graph-node = { path = "../node" }

# Direct dependencies from current dev.rs
anyhow = { workspace = true }
clap = { workspace = true }
env_logger = "0.11.8"
git-testament = "0.2"
lazy_static = "1.5.0"
tokio = { workspace = true }
serde = { workspace = true }

# File watching
notify = "8.2.0"
globset = "0.4.16"
pq-sys = { version = "0.7.2", features = ["bundled"] }
openssl-sys = { version = "0.9.100", features = ["vendored"] }

[target.'cfg(unix)'.dependencies]
pgtemp = { git = "https://github.com/graphprotocol/pgtemp", branch = "initdb-args" }
1 change: 0 additions & 1 deletion node/src/dev/mod.rs → gnd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod helpers;
pub mod watcher;
16 changes: 6 additions & 10 deletions node/src/bin/dev.rs → gnd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ use graph::{
tokio::{self, sync::mpsc},
};
use graph_core::polling_monitor::ipfs_service;
use graph_node::{
dev::watcher,
dev::watcher::{parse_manifest_args, watch_subgraphs},
launcher,
opt::Opt,
};
use graph_node::{launcher, opt::Opt};
use lazy_static::lazy_static;

use gnd::watcher::{deploy_all_subgraphs, parse_manifest_args, watch_subgraphs};

#[cfg(unix)]
use pgtemp::{PgTempDB, PgTempDBBuilder};

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

if let Err(e) =
watcher::deploy_all_subgraphs(&logger, &manifests_paths, &source_subgraph_aliases, &tx)
.await
deploy_all_subgraphs(&logger, &manifests_paths, &source_subgraph_aliases, &tx).await
{
error!(logger, "Error deploying subgraphs"; "error" => e.to_string());
std::process::exit(1);
Expand Down
36 changes: 34 additions & 2 deletions node/src/dev/watcher.rs → gnd/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,43 @@ use std::path::{Path, PathBuf};
use std::sync::mpsc;
use std::time::Duration;

use super::helpers::{parse_alias, parse_manifest_arg};

const WATCH_DELAY: Duration = Duration::from_secs(5);
const DEFAULT_BUILD_DIR: &str = "build";

/// Parse an alias string into a tuple of (alias_name, manifest, Option<build_dir>)
pub fn parse_alias(alias: &str) -> anyhow::Result<(String, String, Option<String>)> {
let mut split = alias.split(':');
let alias_name = split.next();
let alias_value = split.next();

if alias_name.is_none() || alias_value.is_none() || split.next().is_some() {
return Err(anyhow::anyhow!(
"Invalid alias format: expected 'alias=[BUILD_DIR:]manifest', got '{}'",
alias
));
}

let alias_name = alias_name.unwrap().to_owned();
let (manifest, build_dir) = parse_manifest_arg(alias_value.unwrap())
.with_context(|| format!("While parsing alias '{}'", alias))?;

Ok((alias_name, manifest, build_dir))
}

/// Parse a manifest string into a tuple of (manifest, Option<build_dir>)
pub fn parse_manifest_arg(value: &str) -> anyhow::Result<(String, Option<String>)> {
match value.split_once(':') {
Some((manifest, build_dir)) if !manifest.is_empty() => {
Ok((manifest.to_owned(), Some(build_dir.to_owned())))
}
Some(_) => Err(anyhow::anyhow!(
"Invalid manifest arg: missing manifest in '{}'",
value
)),
None => Ok((value.to_owned(), None)),
}
}

// Parses manifest arguments and returns a vector of paths to the manifest files
pub fn parse_manifest_args(
manifests: Vec<String>,
Expand Down
7 changes: 0 additions & 7 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ path = "src/main.rs"
name = "graphman"
path = "src/bin/manager.rs"

[[bin]]
name = "gnd"
path = "src/bin/dev.rs"

[dependencies]
anyhow = { workspace = true }
env_logger = "0.11.8"
Expand Down Expand Up @@ -45,6 +41,3 @@ prometheus = { version = "0.14.0", features = ["push"] }
json-structural-diff = { version = "0.2", features = ["colorize"] }
globset = "0.4.16"
notify = "8.2.0"

[target.'cfg(unix)'.dependencies]
pgtemp = { git = "https://github.com/graphprotocol/pgtemp", branch = "initdb-args" }
43 changes: 2 additions & 41 deletions node/src/dev/helpers.rs → node/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use anyhow::Result;
use graph::prelude::{
BlockPtr, DeploymentHash, NodeId, SubgraphRegistrarError, SubgraphStore as SubgraphStoreTrait,
};
Expand All @@ -12,11 +12,6 @@ use graph::{
};
use graph_store_postgres::SubgraphStore;

pub struct DevModeContext {
pub watch: bool,
pub updates_rx: Receiver<(DeploymentHash, SubgraphName)>,
}

/// Cleanup a subgraph
/// This is used to remove a subgraph before redeploying it when using the watch flag
fn cleanup_dev_subgraph(
Expand Down Expand Up @@ -62,7 +57,7 @@ async fn deploy_subgraph(
})
}

pub async fn drop_and_recreate_subgraph(
async fn drop_and_recreate_subgraph(
logger: &Logger,
subgraph_store: Arc<SubgraphStore>,
subgraph_registrar: Arc<impl SubgraphRegistrar>,
Expand Down Expand Up @@ -124,37 +119,3 @@ pub async fn watch_subgraph_updates(
error!(logger, "Subgraph watcher terminated unexpectedly"; "action" => "exiting");
std::process::exit(1);
}

/// Parse an alias string into a tuple of (alias_name, manifest, Option<build_dir>)
pub fn parse_alias(alias: &str) -> anyhow::Result<(String, String, Option<String>)> {
let mut split = alias.split(':');
let alias_name = split.next();
let alias_value = split.next();

if alias_name.is_none() || alias_value.is_none() || split.next().is_some() {
return Err(anyhow::anyhow!(
"Invalid alias format: expected 'alias=[BUILD_DIR:]manifest', got '{}'",
alias
));
}

let alias_name = alias_name.unwrap().to_owned();
let (manifest, build_dir) = parse_manifest_arg(alias_value.unwrap())
.with_context(|| format!("While parsing alias '{}'", alias))?;

Ok((alias_name, manifest, build_dir))
}

/// Parse a manifest string into a tuple of (manifest, Option<build_dir>)
pub fn parse_manifest_arg(value: &str) -> anyhow::Result<(String, Option<String>)> {
match value.split_once(':') {
Some((manifest, build_dir)) if !manifest.is_empty() => {
Ok((manifest.to_owned(), Some(build_dir.to_owned())))
}
Some(_) => Err(anyhow::anyhow!(
"Invalid manifest arg: missing manifest in '{}'",
value
)),
None => Ok((value.to_owned(), None)),
}
}
2 changes: 1 addition & 1 deletion node/src/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use graph::futures03::compat::Future01CompatExt;
use graph::futures03::future::TryFutureExt;

use crate::config::Config;
use crate::dev::helpers::watch_subgraph_updates;
use crate::helpers::watch_subgraph_updates;
use crate::network_setup::Networks;
use crate::opt::Opt;
use crate::store_builder::StoreBuilder;
Expand Down
2 changes: 1 addition & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate diesel;

pub mod chain;
pub mod config;
pub mod dev;
mod helpers;
pub mod launcher;
pub mod manager;
pub mod network_setup;
Expand Down
Loading