Skip to content

Commit

Permalink
Merge pull request nervosnetwork#468 from doitian/require-config-file…
Browse files Browse the repository at this point in the history
…-to-start

feat: ckb must loads config files from file system.
  • Loading branch information
quake committed Apr 14, 2019
2 parents 0db3859 + b0003b6 commit 3b5ceed
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -43,3 +43,6 @@ tags
/ckb-miner.toml
/data
/specs
/ckb-dev
/ckb-testnet
/ckb-mainnet
1 change: 1 addition & 0 deletions docker/hub/Dockerfile
Expand Up @@ -61,6 +61,7 @@ COPY --from=ckb-builder \
/usr/lib/x86_64-linux-gnu/libcrypto.so.* \
/usr/lib/x86_64-linux-gnu/
COPY --from=ckb-builder /ckb/target/release/ckb /bin/ckb
RUN /bin/ckb init --force

USER ckb

Expand Down
2 changes: 1 addition & 1 deletion docs/configure.md
Expand Up @@ -12,7 +12,7 @@ CKB looks for configuration files in `<config-dir>`, which is the current workin

Command line argument `-C <path>` sets the value of `<config-dir>` to `<path>`.

If CKB could not find the config file, it will use the default bundled ones.
Command `ckb init` initializes a directory by exporting the config files.

Some config file may refer to other files, for example, `chain.spec` in
`ckb.toml` and `system_cells` in chain spec file. The file is referred via
Expand Down
14 changes: 12 additions & 2 deletions docs/quick-start.md
Expand Up @@ -3,8 +3,16 @@
Following steps will assume that the shell can find the executable `ckb`, see
how to [get CKB](get-ckb.md).

CKB uses current directory to store data. It is recommended to setup the
directory with default config files:
First creates a directory to run CKB

```shell
mkdir ckb-dev
cd ckb-dev
```

All the following commands will run in this same directory.

Then init the directory with the default config files.

```shell
ckb init
Expand All @@ -14,6 +22,8 @@ See how to [configure CKB](configure.md) if you like to tweak the options.

## Start Node

Start the node from the directory

```shell
ckb run
```
Expand Down
7 changes: 7 additions & 0 deletions resource/src/lib.rs
Expand Up @@ -28,6 +28,13 @@ pub enum Resource {
}

impl Resource {
pub fn is_bundled(&self) -> bool {
match self {
Resource::Bundled(_) => true,
_ => false,
}
}

/// Gets resource content
pub fn get(&self) -> Result<Cow<'static, [u8]>> {
match self {
Expand Down
4 changes: 4 additions & 0 deletions src/setup/app_config.rs
Expand Up @@ -59,6 +59,10 @@ pub struct ChainConfig {
}

impl AppConfig {
pub fn is_bundled(&self) -> bool {
self.resource.is_bundled()
}

pub fn load_for_subcommand(
locator: &ResourceLocator,
subcommand_name: &str,
Expand Down
4 changes: 4 additions & 0 deletions src/setup/mod.rs
Expand Up @@ -40,6 +40,10 @@ impl Setup {

let resource_locator = locator_from_matches(matches)?;
let config = AppConfig::load_for_subcommand(&resource_locator, subcommand_name)?;
if config.is_bundled() {
eprintln!("Not a CKB directory, initialize one with `ckb init`.");
return Err(ExitCode::Config);
}

Ok(Setup {
subcommand_name: subcommand_name.to_string(),
Expand Down

0 comments on commit 3b5ceed

Please sign in to comment.