From 3532c2a24efeba94b73ff7f8ff0ab284baee6fd2 Mon Sep 17 00:00:00 2001 From: alvicsam Date: Wed, 8 Sep 2021 15:13:49 +0200 Subject: [PATCH 1/3] added information about ci to readme --- README.md | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 113 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 960db82e..d6124a29 100644 --- a/README.md +++ b/README.md @@ -51,26 +51,134 @@ More relevant links: * Step 3: `cargo install --force cargo-contract` -### Docker Image +### Installation using Docker Image If you prefer to use Docker instead we have a Docker image [available on the Docker Hub](https://hub.docker.com/r/paritytech/contracts-ci-linux): ```bash -# Pull the latest image. -docker pull paritytech/contracts-ci-linux +# Pull the latest stable image. +docker pull paritytech/contracts-ci-linux:production # Create a new contract in your current directory. -docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ +docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production \ cargo +nightly contract new --target-dir /sources my_contract # Build the contract. This will create the contract file under # `my_contract/target/ink/my_contract.contract`. -docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ +docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production \ cargo +nightly contract build --manifest-path=/sources/my_contract/Cargo.toml ``` + +
If you want to reproduce different steps of CI process you can use the following guide. +

+ +### Preparation + +[Install `podman`](https://podman.io/getting-started/installation) (it's rootless) or rename it to `docker` in the following snippets (if you are OS X user install docker, podman doesn't work correctly with mounted volumes): + + +

.bashrc +

+ +```bash +# "Cargo as a virtual environment in the current dir" +function cargoenvhere { + dirname="$(basename $(pwd))" + user=$(whoami) + echo "Cargo as a virtual environment in" "$dirname" "dir" + mkdir -p /home/"$user"/cache/"$dirname" + podman run --rm -it -w /shellhere/"$dirname" -v "$(pwd)":/shellhere/"$dirname" -v /home/"$user"/cache/"$dirname"/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ "$@" +} + +# example use +# cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' +``` +

+
+ +
cargoenvhere.sh +

+ +```bash +#!/bin/bash + +# "Cargo as a virtual environment in the current dir" +dirname="$(basename $(pwd))" +user=$(whoami) +echo "Cargo as a virtual environment in" "$dirname" "dir" +mkdir -p /home/"$user"/cache/"$dirname" +podman run --rm -it -w /shellhere/"$dirname" -v "$(pwd)":/shellhere/"$dirname" -v /home/"$user"/cache/"$dirname"/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ "$@" + +# example use +# cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' +end +``` +

+
+ +
cargoenvhere.fish +

+ +```bash +function cargoenvhere -d "Cargo as a virtual environment in the current dir" + set dirname (basename (pwd)) + set user (whoami) + echo "Cargo as a virtual environment in" $dirname "dir" + mkdir -p /home/$user/cache/$dirname + podman run --rm -it -w /shellhere/$dirname -v (pwd):/shellhere/$dirname -v /home/$user/cache/$dirname/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ $argv +end +``` +

+
+ +If you use OS X consider using following snippet: +
.zshrc +

+ +```bash +function cargoenvhere { + dirname="$(basename $(pwd))" + echo "Cargo as a virtual environment in" "$dirname" "dir" + docker volume inspect cargo-cache > /dev/null || docker volume create cargo-cache + docker run --rm -it -w /shellhere/"$dirname" \ + -v "$(pwd)":/shellhere/"$dirname" \ + -v cargo-cache:/cache/ \ + -e CARGO_HOME=/cache/cargo/ \ + -e SCCACHE_DIR=/cache/sccache/ "$@" +} +``` +

+
+ +TLDR; the function runs the named container in the current dir with +   - redirecting the current directory into the image +   - keeping your shell history on your host +   - keeping Rust caches on your host, so you build faster the next time + example use: + +```bash +cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 \ +time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' +``` + +### Execution + +1. open the CI config file (`.gitlab-ci.yml`) +2. note `CI_IMAGE:` variable value there (for current repo it is `paritytech/contracts-ci-linux:production`) +3. look for the job you want to reproduce and see if `*docker-env` is mentioned there (then you should use this one) +4. note global and in-job `variables:`, in order to reproduce the job closely you might want to run it with the same `RUSTFLAGS` and `CARGO_INCREMENTAL` +5. `podman pull [CI image name]` / `docker pull [CI image name]` +6. execute your job how it's shown in the example ^ `cargoenvhere [CI image name] /bin/bash -c ‘[cargo build ...]’` +7. find your artifacts in `/home/$USER/cache/[project name or current dir name]/target` for Linux users or `/path/to/the/cloned/repo/target` for OS X users. + +:warning: If you want to execute a binary on OS X pay attention that with docker it is compiled for Linux. So if want to run it you need to use something like: `cargoenvhere paritytech/contracts-ci-linux:production cargo run` + +

+
+ ## Usage You can always use `cargo contract help` to print information on available -- GitLab From bd15d18922337e9f7cfaecdc29e34e2a48b015fa Mon Sep 17 00:00:00 2001 From: alvicsam Date: Thu, 9 Sep 2021 15:52:02 +0200 Subject: [PATCH 2/3] added link to local ci docs --- README.md | 109 +----------------------------------------------------- 1 file changed, 1 insertion(+), 108 deletions(-) diff --git a/README.md b/README.md index d6124a29..987b0bed 100644 --- a/README.md +++ b/README.md @@ -70,114 +70,7 @@ docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production cargo +nightly contract build --manifest-path=/sources/my_contract/Cargo.toml ``` - - -
If you want to reproduce different steps of CI process you can use the following guide. -

- -### Preparation - -[Install `podman`](https://podman.io/getting-started/installation) (it's rootless) or rename it to `docker` in the following snippets (if you are OS X user install docker, podman doesn't work correctly with mounted volumes): - - -

.bashrc -

- -```bash -# "Cargo as a virtual environment in the current dir" -function cargoenvhere { - dirname="$(basename $(pwd))" - user=$(whoami) - echo "Cargo as a virtual environment in" "$dirname" "dir" - mkdir -p /home/"$user"/cache/"$dirname" - podman run --rm -it -w /shellhere/"$dirname" -v "$(pwd)":/shellhere/"$dirname" -v /home/"$user"/cache/"$dirname"/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ "$@" -} - -# example use -# cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' -``` -

-
- -
cargoenvhere.sh -

- -```bash -#!/bin/bash - -# "Cargo as a virtual environment in the current dir" -dirname="$(basename $(pwd))" -user=$(whoami) -echo "Cargo as a virtual environment in" "$dirname" "dir" -mkdir -p /home/"$user"/cache/"$dirname" -podman run --rm -it -w /shellhere/"$dirname" -v "$(pwd)":/shellhere/"$dirname" -v /home/"$user"/cache/"$dirname"/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ "$@" - -# example use -# cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' -end -``` -

-
- -
cargoenvhere.fish -

- -```bash -function cargoenvhere -d "Cargo as a virtual environment in the current dir" - set dirname (basename (pwd)) - set user (whoami) - echo "Cargo as a virtual environment in" $dirname "dir" - mkdir -p /home/$user/cache/$dirname - podman run --rm -it -w /shellhere/$dirname -v (pwd):/shellhere/$dirname -v /home/$user/cache/$dirname/:/cache/ -e CARGO_HOME=/cache/cargo/ -e SCCACHE_DIR=/cache/sccache/ -e CARGO_TARGET_DIR=/cache/target/ $argv -end -``` -

-
- -If you use OS X consider using following snippet: -
.zshrc -

- -```bash -function cargoenvhere { - dirname="$(basename $(pwd))" - echo "Cargo as a virtual environment in" "$dirname" "dir" - docker volume inspect cargo-cache > /dev/null || docker volume create cargo-cache - docker run --rm -it -w /shellhere/"$dirname" \ - -v "$(pwd)":/shellhere/"$dirname" \ - -v cargo-cache:/cache/ \ - -e CARGO_HOME=/cache/cargo/ \ - -e SCCACHE_DIR=/cache/sccache/ "$@" -} -``` -

-
- -TLDR; the function runs the named container in the current dir with -   - redirecting the current directory into the image -   - keeping your shell history on your host -   - keeping Rust caches on your host, so you build faster the next time - example use: - -```bash -cargoenvhere paritytech/ci-linux:production /bin/bash -c 'RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" RUST_BACKTRACE=1 \ -time cargo test --workspace --locked --release --verbose --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml' -``` - -### Execution - -1. open the CI config file (`.gitlab-ci.yml`) -2. note `CI_IMAGE:` variable value there (for current repo it is `paritytech/contracts-ci-linux:production`) -3. look for the job you want to reproduce and see if `*docker-env` is mentioned there (then you should use this one) -4. note global and in-job `variables:`, in order to reproduce the job closely you might want to run it with the same `RUSTFLAGS` and `CARGO_INCREMENTAL` -5. `podman pull [CI image name]` / `docker pull [CI image name]` -6. execute your job how it's shown in the example ^ `cargoenvhere [CI image name] /bin/bash -c ‘[cargo build ...]’` -7. find your artifacts in `/home/$USER/cache/[project name or current dir name]/target` for Linux users or `/path/to/the/cloned/repo/target` for OS X users. - -:warning: If you want to execute a binary on OS X pay attention that with docker it is compiled for Linux. So if want to run it you need to use something like: `cargoenvhere paritytech/contracts-ci-linux:production cargo run` - -

-
+If you want to reproduce other steps of CI process you can use the following [guide](https://github.com/paritytech/scripts#reproduce-ci-locally). ## Usage -- GitLab From 95a0a8f9761c746da2d4894ebfcc3e4a2cac3d03 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 9 Sep 2021 14:48:22 -0500 Subject: [PATCH 3/3] Trim long line --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 987b0bed..000dad6a 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux:production cargo +nightly contract build --manifest-path=/sources/my_contract/Cargo.toml ``` -If you want to reproduce other steps of CI process you can use the following [guide](https://github.com/paritytech/scripts#reproduce-ci-locally). +If you want to reproduce other steps of CI process you can use the following +[guide](https://github.com/paritytech/scripts#reproduce-ci-locally). ## Usage -- GitLab