Skip to content

Commit 3ffa799

Browse files
Arjentix6r1d
authored andcommitted
[feature] #3868: Add iroha_swarm disclaimer header
Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
1 parent 483b6d5 commit 3ffa799

File tree

8 files changed

+40
-11
lines changed

8 files changed

+40
-11
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.dev.local.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file is generated by iroha_swarm.
2+
# Do not edit it manually.
3+
14
version: '3.8'
25
services:
36
iroha0:

docker-compose.dev.single.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file is generated by iroha_swarm.
2+
# Do not edit it manually.
3+
14
version: '3.8'
25
services:
36
iroha0:

docker-compose.dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This file is generated by iroha_swarm.
2+
# Do not edit it manually.
3+
14
version: '3.8'
25
services:
36
iroha0:

scripts/check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ case $1 in
3939

4040
eval "$full_cmd"
4141
diff "$temp_file" "$target" || {
42-
echo "Please re-generate \`$target\` with \`$full_cmd\`"
42+
echo "Please re-generate \`$target\` with \`$cmd_base --outfile $target\`"
4343
exit 1
4444
}
4545
}

tools/swarm/src/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ pub struct Cli {
2020
/// overwrite the file anyway, pass `--force` flag.
2121
#[arg(long, short)]
2222
pub outfile: PathBuf,
23+
/// Disable banner in the file saying that the file is generated.
24+
///
25+
/// It includes all passed arguments in order to help with reproducibility.
26+
#[arg(long)]
27+
pub no_banner: bool,
2328
/// Path to a directory with Iroha configuration. It will be mapped as volume for containers.
2429
///
2530
/// The directory should contain `config.json` and `genesis.json`.

tools/swarm/src/compose.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,26 @@ impl DockerCompose {
3939
}
4040
}
4141

42-
pub fn write_file(&self, path: &PathBuf) -> Result<(), color_eyre::Report> {
42+
pub fn write_file(
43+
&self,
44+
path: &PathBuf,
45+
banner_enabled: bool,
46+
) -> Result<(), color_eyre::Report> {
47+
let mut file = File::create(path)
48+
.wrap_err_with(|| eyre!("Failed to create file {}", path.display()))?;
49+
50+
if banner_enabled {
51+
file.write_all(
52+
b"# This file is generated by iroha_swarm.\n\
53+
# Do not edit it manually.\n\n",
54+
)
55+
.wrap_err_with(|| eyre!("Failed to write banner into {}", path.display()))?;
56+
}
57+
4358
let yaml = serde_yaml::to_string(self).wrap_err("Failed to serialise YAML")?;
44-
File::create(path)
45-
.wrap_err_with(|| eyre!("Failed to create file {}", path.display()))?
46-
.write_all(yaml.as_bytes())
47-
.wrap_err_with(|| eyre!("Failed to write YAML content into {}", path.display()))?;
48-
Ok(())
59+
file.write_all(yaml.as_bytes())
60+
.wrap_err_with(|| eyre!("Failed to write YAML content into {}", path.display()))
61+
.map_err(Into::into)
4962
}
5063
}
5164

@@ -331,12 +344,12 @@ impl DockerComposeBuilder<'_> {
331344
Ok(compose)
332345
}
333346

334-
pub(crate) fn build_and_write(&self) -> color_eyre::Result<()> {
347+
pub(crate) fn build_and_write(&self, banner_enabled: bool) -> color_eyre::Result<()> {
335348
let target_file = self.target_file;
336349
let compose = self
337350
.build()
338351
.wrap_err("Failed to build a docker compose file")?;
339-
compose.write_file(&target_file.path)
352+
compose.write_file(&target_file.path, banner_enabled)
340353
}
341354
}
342355

tools/swarm/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn main() -> Result<()> {
1717
peers,
1818
seed,
1919
force,
20+
no_banner,
2021
source: image_source,
2122
outfile: target_file_raw,
2223
config_dir: config_dir_raw,
@@ -41,14 +42,16 @@ fn main() -> Result<()> {
4142
}
4243
}
4344

45+
let banner_enabled = !no_banner;
46+
4447
compose::DockerComposeBuilder {
4548
target_file: &target_file,
4649
config_dir: &config_dir,
4750
image_source,
4851
peers,
4952
seed,
5053
}
51-
.build_and_write()?;
54+
.build_and_write(banner_enabled)?;
5255

5356
ui::log_file_mode_complete(&target_file, &target_file_raw);
5457

0 commit comments

Comments
 (0)