Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: don't override the manifest file #1509

Closed
wants to merge 3 commits into from
Closed
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
158 changes: 80 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions packages/fuel-indexer-benchmarks/src/bin/qa.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use chrono::Utc;
use clap::Parser;
use duct::cmd;
use fuel_indexer_lib::{
config::IndexerConfig, defaults, manifest::Manifest, utils::init_logging,
};
use fuel_indexer_lib::{config::IndexerConfig, defaults, utils::init_logging};
use reqwest::{
header::{HeaderMap, CONTENT_TYPE},
Client,
Expand Down Expand Up @@ -583,8 +581,6 @@ async fn main() {
let explorer_root =
canonicalize(examples_root.join("fuel-explorer").join("fuel-explorer")).unwrap();

let mani_path = explorer_root.join("fuel_explorer.manifest.yaml");

let _proc = Command::new("forc-index")
.arg("start")
.arg("--run-migrations")
Expand Down Expand Up @@ -615,7 +611,6 @@ async fn main() {
"Performing {num_runs} runs, indexing {blocks_per_run} blocks per run."
);
tracing::info!("Start blocks: {start_blocks:?}");
let manifest = Manifest::from_file(&mani_path).unwrap();
let mut stats = StatManager::new();

// Deploy some number of additional hello-world indexers.
Expand All @@ -624,20 +619,18 @@ async fn main() {
// performance when multiple indexers are running at the same time - if the user so specifies.
if let Some(num_additional_indexers) = opts.num_additional_indexers {
let hello_world_root = examples_root.join("hello-world").join("hello-world");
let mani_path = hello_world_root.join("hello_world.manifest.yaml");
let mut manifest = Manifest::from_file(&mani_path).unwrap();

for i in 0..num_additional_indexers {
tracing::info!("Deploying additional indexer #{}", i + 1);
manifest.set_identifier(format!("hello_world_{}", i));
let _ = manifest.write(&mani_path).unwrap();

sleep(Duration::from_secs(1)).await;

let mut proc = Command::new("forc-index")
.arg("deploy")
.arg("--path")
.arg(&hello_world_root.to_str().unwrap())
.arg("--override-identifier")
.arg::<String>(format!("hello_world_{}", i))
.spawn()
.unwrap();

Expand All @@ -658,13 +651,7 @@ async fn main() {
let end_block = start_block + blocks_per_run;
let mut run_stats = RunStat::new(run, *start_block, end_block);

let mut manifest = manifest.clone();

tracing::info!("Run {run} will index block #{start_block} - #{end_block}",);
manifest.set_start_block(*start_block);

manifest.set_end_block(end_block);
let _ = manifest.write(&mani_path).unwrap();

sleep(Duration::from_secs(1)).await;

Expand All @@ -673,6 +660,10 @@ async fn main() {
.arg("--path")
.arg(&explorer_root.to_str().unwrap())
.arg("--replace-indexer")
.arg("--override-start-block")
.arg(start_block.to_string())
.arg("--override-end-block")
.arg(end_block.to_string())
.spawn()
.unwrap();

Expand Down
14 changes: 1 addition & 13 deletions packages/fuel-indexer-lib/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Write},
io::Read,
path::{Path, PathBuf},
str::FromStr,
};
Expand Down Expand Up @@ -147,18 +147,6 @@ impl Manifest {
}
}

/// Write this manifest to a given path.
pub fn write(&self, path: &PathBuf) -> ManifestResult<()> {
let mut file = File::create(path).map_err(|err| {
ManifestError::FileError(path.to_str().unwrap_or_default().to_string(), err)
})?;
let content: Vec<u8> = Self::into(self.clone());
file.write_all(&content).map_err(|err| {
ManifestError::FileError(path.to_str().unwrap_or_default().to_string(), err)
})?;
Ok(())
}

/// Set the start block for this indexer.
pub fn set_start_block(&mut self, block: u32) {
self.start_block = Some(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,29 @@ USAGE:
forc-index build [OPTIONS]

OPTIONS:
-d, --debug Build artifacts with the debug profile.
-h, --help Print help information
--locked Ensure that the Cargo.lock file is up-to-date.
-m, --manifest <MANIFEST> Manifest file name of indexer being built.
-p, --path <PATH> Path to the indexer project.
-v, --verbose Enable verbose output.
-d, --debug
Build artifacts with the debug profile.

-h, --help
Print help information

--locked
Ensure that the Cargo.lock file is up-to-date.

-m, --manifest <MANIFEST>
Manifest file name of indexer being built.

--override-end-block <OVERRIDE_END_BLOCK>
Override the end blockt.

--override-identifier <OVERRIDE_IDENTIFIER>
Override the identifier.

--override-start-block <OVERRIDE_START_BLOCK>
Override the start block.

-p, --path <PATH>
Path to the indexer project.

-v, --verbose
Enable verbose output.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,44 @@ USAGE:
forc-index deploy [OPTIONS]

OPTIONS:
--auth <AUTH> Authentication header value.
-d, --debug Build optimized artifacts with the debug profile.
-h, --help Print help information
--locked Ensure that the Cargo.lock file is up-to-date.
-m, --manifest <MANIFEST> Path to the manifest of indexer project being deployed.
-p, --path <PATH> Path to the indexer project.
--remove-data Remove all indexed data when replacing an existing indexer.
--replace-indexer If an indexer with the same UID exists, remove it.
--skip-build Do not build before deploying.
--url <URL> URL at which to deploy indexer assets. [default:
http://127.0.0.1:29987]
-v, --verbose Enable verbose logging.
--auth <AUTH>
Authentication header value.

-d, --debug
Build optimized artifacts with the debug profile.

-h, --help
Print help information

--locked
Ensure that the Cargo.lock file is up-to-date.

-m, --manifest <MANIFEST>
Path to the manifest of indexer project being deployed.

--override-end-block <OVERRIDE_END_BLOCK>
Override the end blockt.

--override-identifier <OVERRIDE_IDENTIFIER>
Override the identifier.

--override-start-block <OVERRIDE_START_BLOCK>
Override the start block.

-p, --path <PATH>
Path to the indexer project.

--remove-data
Remove all indexed data when replacing an existing indexer.

--replace-indexer
If an indexer with the same UID exists, remove it.

--skip-build
Do not build before deploying.

--url <URL>
URL at which to deploy indexer assets. [default: http://127.0.0.1:29987]

-v, --verbose
Enable verbose logging.
12 changes: 12 additions & 0 deletions plugins/forc-index/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ pub struct Command {
/// Enable verbose output.
#[clap(short, long, help = "Enable verbose output.")]
pub verbose: bool,

/// Override the start block
#[clap(long, help = "Override the start block.")]
pub override_start_block: Option<u32>,

/// Override the end block
#[clap(long, help = "Override the end blockt.")]
pub override_end_block: Option<u32>,

/// Override the identifier
#[clap(long, help = "Override the identifier.")]
pub override_identifier: Option<String>,
}

pub fn exec(command: Command) -> Result<()> {
Expand Down
12 changes: 12 additions & 0 deletions plugins/forc-index/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ pub struct Command {
help = "Remove all indexed data when replacing an existing indexer."
)]
pub remove_data: bool,

/// Override the start block
#[clap(long, help = "Override the start block.")]
pub override_start_block: Option<u32>,

/// Override the end block
#[clap(long, help = "Override the end blockt.")]
pub override_end_block: Option<u32>,

/// Override the identifier
#[clap(long, help = "Override the identifier.")]
pub override_identifier: Option<String>,
}

pub async fn exec(command: Command) -> Result<()> {
Expand Down
30 changes: 14 additions & 16 deletions plugins/forc-index/src/ops/forc_index_build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{cli::BuildCommand, defaults, utils::project_dir_info};
use fuel_indexer_lib::{
manifest::{Manifest, Module},
utils::Config,
};
use fuel_indexer_lib::{manifest::Manifest, utils::Config};
use indicatif::{ProgressBar, ProgressStyle};
use std::collections::HashSet;
use std::{
Expand All @@ -22,6 +19,9 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
locked,
manifest,
verbose,
override_start_block,
override_end_block,
override_identifier,
..
} = command;

Expand Down Expand Up @@ -56,6 +56,15 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
let indexer_manifest_path = root_dir.join(manifest);
let mut manifest = Manifest::from_file(&indexer_manifest_path)?;

if let Some(start_block) = override_start_block {
manifest.set_start_block(start_block)
}
if let Some(end_block) = override_end_block {
manifest.set_end_block(end_block)
}
if let Some(identifier) = override_identifier {
manifest.set_identifier(identifier)
}
let manifest_schema_file = {
let workspace_root: std::path::PathBuf =
crate::utils::cargo_workspace_root_dir(path.as_path()).unwrap();
Expand Down Expand Up @@ -170,17 +179,9 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
let abs_artifact_path = target_dir
.join(defaults::WASM_TARGET)
.join(profile)
.join(&binary);

let rel_artifact_path = Path::new("target")
.join(defaults::WASM_TARGET)
.join(profile)
.join(&binary);
.join(binary);

let abs_wasm = abs_artifact_path.as_path().display().to_string();
let relative_wasm = rel_artifact_path.as_path().display().to_string();

manifest.set_module(Module::Wasm(relative_wasm));

let status = Command::new("wasm-snip")
.arg(&abs_wasm)
Expand All @@ -198,9 +199,6 @@ pub fn init(command: BuildCommand) -> anyhow::Result<()> {
anyhow::bail!("❌ Failed to execute wasm-snip: (Code: {code:?})",)
}

// FIXME: This should include whatever comments were in the original doc
manifest.write(&indexer_manifest_path)?;

Ok(())
}

Expand Down
6 changes: 6 additions & 0 deletions plugins/forc-index/src/ops/forc_index_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub async fn init(command: DeployCommand) -> anyhow::Result<()> {
replace_indexer,
remove_data,
skip_build,
override_start_block,
override_end_block,
override_identifier,
} = command;

if !skip_build {
Expand All @@ -38,6 +41,9 @@ pub async fn init(command: DeployCommand) -> anyhow::Result<()> {
debug,
verbose,
locked,
override_start_block,
override_end_block,
override_identifier,
})?;
}

Expand Down
Loading