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

doc: edit README.md for reproducible choice interactive change #265

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions .github/workflows/crontab_new_template_renewal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
let record = http get "https://hub.docker.com/v2/namespaces/sourcescan/repositories/cargo-near/tags" | get results | first;

let mod_content = (
open cargo-near/src/commands/new/new-project-template/Cargo.toml.template --raw | lines
open cargo-near/src/commands/new/new-project-template/Cargo.template.toml --raw | lines
| each {
|line| if ($line | str starts-with "image = ") {
$'image = "sourcescan/cargo-near:($record.name)"'
Expand All @@ -44,7 +44,7 @@ jobs:
| to text
);

$mod_content | save -f cargo-near/src/commands/new/new-project-template/Cargo.toml.template
$mod_content | save -f cargo-near/src/commands/new/new-project-template/Cargo.template.toml

git diff

Expand Down
71 changes: 49 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,53 @@ cargo near build

Builds a NEAR smart contract along with its [ABI](https://github.com/near/abi) (while in the directory containing contract's Cargo.toml).

By default, this runs a reproducible build in a [Docker](https://docs.docker.com/) container, which:
Running the above command opens a menu with following variants:

### `non-reproducible-wasm`

This is a regular build, which behaves much like and is a thin wrapper around a regular `cargo build --target wasm32-unknown-unknown --release`.

Additional flags for build configuration can be looked up by

```bash
cargo near build non-reproducible-wasm --help
```
if needed.

### `reproducible-wasm`

This variant runs a reproducible build in a [Docker](https://docs.docker.com/) container, which:

1. runs against source code version, committed to git, ignoring any uncommitted changes
2. requires that `Cargo.lock` of project is created (e.g. via `cargo update`) and added to git.
- this enables `--locked` build by downstream `cargo` command.
3. will use configuration in [`[package.metadata.near.reproducible_build]`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.toml.template#L14-L25)
section of contract's `Cargo.toml` and [`package.repository`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.toml.template#L9) field
3. will use configuration in [`[package.metadata.near.reproducible_build]`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L14-L25)
Copy link
Collaborator Author

@dj8yfo dj8yfo Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to rename, all of the links in README are currently broken, but point to target location in main

section of contract's `Cargo.toml` and [`package.repository`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L9) field
- default values for this section can also be found in `Cargo.toml` of
template project, generated by `cargo near new`

Important flags:

1. `--no-docker`
- flag can be used to perform a regular build with rust toolchain installed onto host, running the `cargo-near` cli.
- *NO*-Docker builds run against actual state of code in filesystem and not against a version, committed to source control.
**What's a reproducible build in context of NEAR?**
Why is it needed? Explanation of these points and a step-by-step tutorial is present at [SourceScan/verification-guide](https://github.com/SourceScan/verification-guide).

2. `--no-locked`
- flag is allowed in *NO*-Docker builds, e.g. to generate a `Cargo.lock` *and* simultaneously build the contract.
- flag is allowed in Docker builds, but
- such builds are not reproducible due to potential update of dependencies and compiled `wasm` mismatch as the result.
<details>
<summary>Additional (optional) details on possible <code>[package.metadata.near.reproducible_build]</code> configuration</summary><p>

1. available images can be found by this link https://hub.docker.com/r/sourcescan/cargo-near/tags
- [`image`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L18) and [`image_digest`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L19) are straightforward to configure:
![image_and_digest_pinpoint](./docs/image_and_digest_pinpoint.png)
2. flags of build command, run inside of docker container, can be configured, if needed, by changing [`container_build_command`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L29) field
- base `container_build_command` for images prior to **sourcescan/cargo-near:0.13.0-rust-1.83.0** is `["cargo", "near", "build"]`
- base `container_build_command` for images starting with **sourcescan/cargo-near:0.13.0-rust-1.83.0** and after it is `["cargo", "near", "build", "non-reproducible-wasm", "--locked"]`, where the `--locked` flag is required
- additional flags, if needed, can be looked up on
- `cargo near build non-reproducible-wasm --help` for newer/latest images
- `cargo near build --help` for older ones
- running `docker run -it sourcescan/cargo-near:0.11.0-rust-1.82.0` (or another specific image) and checking the `--help` message of exact `cargo-near` in container may be helpful when in doubt
3. `cargo near` allows parameterizing build with values of environment variables, present at the time of the build and not present in a contract's source code,
by specifying their names in [`passed_env`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L24) array
- supported by `sourcescan/cargo-near:0.10.1-rust-1.82.0` image or later images
- SourceScan/Nearblocks does not support verifying such contracts yet.

</p></details>

---

Expand Down Expand Up @@ -146,22 +173,22 @@ cargo near deploy

Builds the smart contract (equivalent to `cargo near build`) and guides you to deploy it to the blockchain.

By default, this runs a reproducible build in a Docker container.
Similar to `build`, running the above command opens a menu with following variants:

### `build-non-reproducible-wasm`

This forwards to [non-reproducible-wasm](#non-reproducible-wasm) variant of `build` command.

### `build-reproducible-wasm`

This forwards to [reproducible-wasm](#reproducible-wasm) variant of `build` command.

`deploy` command from Docker build requires that contract's source code:

1. doesn't have any modified tracked files, any staged changes or any untracked content.
2. has been pushed to remote repository, identified by
[`package.repository`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.toml.template#L9).

Important flags:

1. `--no-docker`
- flag can be used to perform a regular *NO*-Docker build *and* deploy.
- Similar to `build` command, in this case none of the git-related concerns and restrictions apply.
[`package.repository`](https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L9).

2. `--no-locked`
- flag is declined for deploy, due to its effects on `build` result

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion cargo-near-build/src/types/near/docker_build/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl ReproducibleBuild {
"to your contract's Cargo.toml:".cyan()
);
println!("{}{}", "- default values for the section can be found at ".cyan(),
"https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.toml.template#L14-L29".magenta());
"https://github.com/near/cargo-near/blob/main/cargo-near/src/commands/new/new-project-template/Cargo.template.toml#L14-L29".magenta());
println!(
"{}{}",
"- the same can also be found in Cargo.toml of template project, generated by "
Expand Down
2 changes: 1 addition & 1 deletion cargo-near/src/commands/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const NEW_PROJECT_FILES: &[NewProjectFile] = &[
},
NewProjectFile {
file_path: "Cargo.toml",
content: include_str!("new-project-template/Cargo.toml.template"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content: include_str!("new-project-template/Cargo.template.toml"),
},
NewProjectFile {
file_path: "README.md",
Expand Down
Binary file added docs/image_and_digest_pinpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading