From ce4e71f52aee43daa641f22be037bf1de6444678 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 25 Dec 2024 09:34:14 +0800 Subject: [PATCH] Release `v0.1.7` --- .github/workflows/release.yml | 1 - .github/workflows/staging.yml | 1 - Cargo.lock | 15 +++++++++++++-- Cargo.toml | 3 ++- Dockerfile | 28 ---------------------------- action/build/action.yml | 2 +- cli/Cargo.toml | 1 + cli/src/cli/build.rs | 12 ++++++------ docker/Dockerfile | 34 ++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 20 ++++++++++++++++++++ lib/src/docker.rs | 7 ++++++- 11 files changed, 83 insertions(+), 41 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker/Dockerfile create mode 100644 docker/entrypoint.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 88e6c0d..3137402 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,6 @@ jobs: [ { name: aarch64-apple-darwin, os: macos-latest }, { name: x86_64-unknown-linux-gnu, os: ubuntu-latest }, - { name: x86_64-pc-windows-msvc, os: windows-latest }, ] steps: - name: Fetch latest code diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 1735f3e..d350920 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -19,7 +19,6 @@ jobs: [ { name: aarch64-apple-darwin, os: macos-latest }, { name: x86_64-unknown-linux-gnu, os: ubuntu-latest }, - { name: x86_64-pc-windows-msvc, os: windows-latest }, ] steps: - name: Fetch latest code diff --git a/Cargo.lock b/Cargo.lock index 1dce991..dc0dc61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2809,7 +2809,7 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polkadot-runtime-releaser-cli" -version = "0.1.6" +version = "0.1.7" dependencies = [ "anyhow", "array-bytes 8.0.0", @@ -2822,12 +2822,13 @@ dependencies = [ "serde_json", "tracing", "tracing-subscriber", + "users", "vergen-gitcl", ] [[package]] name = "polkadot-runtime-releaser-lib" -version = "0.1.6" +version = "0.1.7" dependencies = [ "atty", "blake2", @@ -4777,6 +4778,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "users" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +dependencies = [ + "libc", + "log", +] + [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index 6b096bc..ef5ed48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" homepage = "https://hack.ink/polkadot-runtime-releaser" license = "GPL-3.0" repository = "https://github.com/hack-ink/polkadot-runtime-releaser" -version = "0.1.6" +version = "0.1.7" [workspace.dependencies] # crates.io @@ -40,6 +40,7 @@ tokio = { version = "1.42" } toml = { version = "0.8" } tracing = { version = "0.1" } tracing-subscriber = { version = "0.3" } +users = { version = "0.11" } vergen-gitcl = { version = "1.0" } # self prr-lib = { version = "0.1", package = "polkadot-runtime-releaser-lib", path = "lib" } diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index dfd4054..0000000 --- a/Dockerfile +++ /dev/null @@ -1,28 +0,0 @@ -FROM ubuntu:25.04 - -LABEL maintainer="x@acg.box" -LABEL description="An environment for constructing a deterministic polkadot-sdk-based runtime." -LABEL version="0.1.6" - -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - clang \ - cmake \ - curl \ - git \ - libssl-dev \ - pkg-config \ - protobuf-compiler \ - rustup \ - && rm -rf /var/lib/apt/lists/* - -ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse -ENV CARGO_TERM_COLOR=always -ENV RUST_BACKTRACE=full -ENV WASM_BUILD_WORKSPACE_HINT=/workdir - -WORKDIR /workdir - -CMD ["/bin/bash"] diff --git a/action/build/action.yml b/action/build/action.yml index 6d3f65d..bea2292 100644 --- a/action/build/action.yml +++ b/action/build/action.yml @@ -27,7 +27,7 @@ runs: - name: Setup Polkadot Runtime Releaser shell: bash run: curl - -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.6/prr-x86_64-unknown-linux-gnu.tar.gz | + -L https://github.com/hack-ink/polkadot-runtime-releaser/releases/download/v0.1.7/prr-x86_64-unknown-linux-gnu.tar.gz | tar xz && chmod u+x prr && mv prr /usr/local/bin/prr diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 73ea128..2b6cc66 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -30,5 +30,6 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } +users = { workspace = true } # self prr-lib = { workspace = true } diff --git a/cli/src/cli/build.rs b/cli/src/cli/build.rs index 2650ded..d6529ec 100644 --- a/cli/src/cli/build.rs +++ b/cli/src/cli/build.rs @@ -28,7 +28,7 @@ pub struct BuildCmd { #[arg(long, short, value_name = "VER", verbatim_doc_comment)] toolchain_version: Option, /// Image version of the . - #[arg(long, short = 'v', value_name = "VER", default_value_t = String::from("0.1.6"), conflicts_with = "override_docker_image")] + #[arg(long, short = 'v', value_name = "VER", default_value_t = String::from("0.1.7"), conflicts_with = "override_docker_image")] image_version: String, /// Overwrite the default docker image with the specified one. /// Use `docker images` to list the available images on your system. @@ -92,7 +92,9 @@ impl Run for BuildCmd { format!("/{}", output_dir.file_name().expect("dir must exist").to_string_lossy()); let mut run_args = RunArgs::new(image_version, override_docker_image); - run_args.with_env("CARGO_TARGET_DIR", &format!("{container_output_dir}/target")); + run_args.with_env("HOST_UID", users::get_current_uid()); + run_args.with_env("HOST_GID", users::get_current_gid()); + run_args.with_env("CARGO_TARGET_DIR", format!("{container_output_dir}/target")); run_args.with_volume(&workdir.to_string_lossy(), "/workdir"); run_args.with_volume(&output_dir.to_string_lossy(), &container_output_dir); @@ -125,7 +127,7 @@ impl Run for BuildCmd { let snake_case_rt = runtime.replace("-runtime", "_runtime"); let output_rt = - output_dir.join("target/release/wbuild").join(&runtime).join(&snake_case_rt); + output_target_dir.join("release/wbuild").join(&runtime).join(&snake_case_rt); let compressed_wasm = output_rt.with_extension(WASM_EXT_COMPRESSED); let ver = Wasmer::load(&compressed_wasm)?.runtime_version(true)?.spec_version; let rt_name = format!("{snake_case_rt}-{ver}"); @@ -148,9 +150,7 @@ impl Run for BuildCmd { output_target_dir.display() ); - if let Err(e) = fs::remove_dir_all(&output_target_dir) { - tracing::error!("failed to clean up the output target directory, due to {e}"); - } + fs::remove_dir_all(&output_target_dir)?; } Ok(()) diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..0758375 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:25.04 + +LABEL maintainer="x@acg.box" +LABEL description="An environment for constructing a deterministic polkadot-sdk-based runtime." +LABEL version="0.1.7" + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + clang \ + cmake \ + curl \ + git \ + libssl-dev \ + pkg-config \ + protobuf-compiler \ + rustup \ + gosu \ + && rm -rf /var/lib/apt/lists/* + +ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse +ENV CARGO_TERM_COLOR=always +ENV RUST_BACKTRACE=full +ENV WASM_BUILD_WORKSPACE_HINT=/workdir + +WORKDIR /workdir + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["/bin/bash"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..19e9717 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +DEFAULT_UID=1000 +DEFAULT_GID=1000 + +HOST_UID="${HOST_UID:-}" +HOST_GID="${HOST_GID:-}" + +if [ -z "$HOST_UID" ] || [ -z "$HOST_GID" ]; then + echo "HOST_UID/HOST_GID are not set. Running as root." + exec "$@" +else + echo "Running as UID=${HOST_UID}, GID=${HOST_GID}." + + groupadd -g "$HOST_GID" builder + useradd -m -u "$HOST_UID" -g "$HOST_GID" builder + + exec gosu builder "$@" +fi diff --git a/lib/src/docker.rs b/lib/src/docker.rs index d46575c..3bf3090 100644 --- a/lib/src/docker.rs +++ b/lib/src/docker.rs @@ -1,5 +1,7 @@ //! Polkadot Runtime Releaser Docker component. +// std +use std::fmt::Display; // crates.io use atty::Stream; // self @@ -29,7 +31,10 @@ impl<'a> RunArgs<'a> { } /// Set the environment variable. - pub fn with_env(&mut self, key: &str, value: &str) { + pub fn with_env(&mut self, key: &str, value: T) + where + T: Display, + { self.envs.push(format!("{key}={value}")); }