Allow passing env vars to verifiable build container (#2325)

This commit is contained in:
riordanp 2022-12-21 11:22:34 +00:00 committed by GitHub
parent 4bef8c40ef
commit 8856aee7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 1 deletions

View File

@ -10,6 +10,10 @@ The minor version will be incremented upon a breaking change and the patch versi
## [Unreleased]
### Features
- cli: Add `env` option to verifiable builds ([#2325](https://github.com/coral-xyz/anchor/pull/2325)).
## [0.26.0] - 2022-12-15
### Features

View File

@ -101,6 +101,9 @@ pub enum Command {
/// verifiable builds. Only works for debian-based images.
#[clap(value_enum, short, long, default_value = "none")]
bootstrap: BootstrapMode,
/// Environment variables to pass into the docker container
#[clap(short, long, required = false)]
env: Vec<String>,
/// Arguments to pass to the underlying `cargo build-bpf` command
#[clap(required = false, last = true)]
cargo_args: Vec<String>,
@ -141,6 +144,9 @@ pub enum Command {
/// verifiable builds. Only works for debian-based images.
#[clap(value_enum, short, long, default_value = "none")]
bootstrap: BootstrapMode,
/// Environment variables to pass into the docker container
#[clap(short, long, required = false)]
env: Vec<String>,
/// Arguments to pass to the underlying `cargo build-bpf` command.
#[clap(required = false, last = true)]
cargo_args: Vec<String>,
@ -172,6 +178,9 @@ pub enum Command {
#[clap(long)]
run: Vec<String>,
args: Vec<String>,
/// Environment variables to pass into the docker container
#[clap(short, long, required = false)]
env: Vec<String>,
/// Arguments to pass to the underlying `cargo build-bpf` command.
#[clap(required = false, last = true)]
cargo_args: Vec<String>,
@ -237,6 +246,9 @@ pub enum Command {
Publish {
/// The name of the program to publish.
program: String,
/// Environment variables to pass into the docker container
#[clap(short, long, required = false)]
env: Vec<String>,
/// Arguments to pass to the underlying `cargo build-bpf` command.
#[clap(required = false, last = true)]
cargo_args: Vec<String>,
@ -264,6 +276,9 @@ pub enum Command {
/// no "CHECK" comments where normally required
#[clap(long)]
skip_lint: bool,
/// Environment variables to pass into the docker container
#[clap(short, long, required = false)]
env: Vec<String>,
/// Arguments to pass to the underlying `cargo build-bpf` command.
#[clap(required = false, last = true)]
cargo_args: Vec<String>,
@ -387,6 +402,7 @@ pub fn entry(opts: Opts) -> Result<()> {
docker_image,
bootstrap,
cargo_args,
env,
skip_lint,
no_docs,
} => build(
@ -401,6 +417,7 @@ pub fn entry(opts: Opts) -> Result<()> {
bootstrap,
None,
None,
env,
cargo_args,
no_docs,
),
@ -410,6 +427,7 @@ pub fn entry(opts: Opts) -> Result<()> {
solana_version,
docker_image,
bootstrap,
env,
cargo_args,
} => verify(
&opts.cfg_override,
@ -418,6 +436,7 @@ pub fn entry(opts: Opts) -> Result<()> {
solana_version,
docker_image,
bootstrap,
env,
cargo_args,
),
Command::Clean => clean(&opts.cfg_override),
@ -442,6 +461,7 @@ pub fn entry(opts: Opts) -> Result<()> {
detach,
run,
args,
env,
cargo_args,
skip_lint,
} => test(
@ -453,6 +473,7 @@ pub fn entry(opts: Opts) -> Result<()> {
detach,
run,
args,
env,
cargo_args,
),
#[cfg(feature = "dev")]
@ -466,20 +487,23 @@ pub fn entry(opts: Opts) -> Result<()> {
Command::Login { token } => login(&opts.cfg_override, token),
Command::Publish {
program,
env,
cargo_args,
skip_build,
} => publish(&opts.cfg_override, program, cargo_args, skip_build),
} => publish(&opts.cfg_override, program, env, cargo_args, skip_build),
Command::Keys { subcmd } => keys(&opts.cfg_override, subcmd),
Command::Localnet {
skip_build,
skip_deploy,
skip_lint,
env,
cargo_args,
} => localnet(
&opts.cfg_override,
skip_build,
skip_deploy,
skip_lint,
env,
cargo_args,
),
Command::Account {
@ -790,6 +814,7 @@ pub fn build(
bootstrap: BootstrapMode,
stdout: Option<File>, // Used for the package registry server.
stderr: Option<File>, // Used for the package registry server.
env_vars: Vec<String>,
cargo_args: Vec<String>,
no_docs: bool,
) -> Result<()> {
@ -835,6 +860,7 @@ pub fn build(
&build_config,
stdout,
stderr,
env_vars,
cargo_args,
skip_lint,
no_docs,
@ -848,6 +874,7 @@ pub fn build(
&build_config,
stdout,
stderr,
env_vars,
cargo_args,
skip_lint,
no_docs,
@ -861,6 +888,7 @@ pub fn build(
&build_config,
stdout,
stderr,
env_vars,
cargo_args,
skip_lint,
no_docs,
@ -881,6 +909,7 @@ fn build_all(
build_config: &BuildConfig,
stdout: Option<File>, // Used for the package registry server.
stderr: Option<File>, // Used for the package registry server.
env_vars: Vec<String>,
cargo_args: Vec<String>,
skip_lint: bool,
no_docs: bool,
@ -898,6 +927,7 @@ fn build_all(
build_config,
stdout.as_ref().map(|f| f.try_clone()).transpose()?,
stderr.as_ref().map(|f| f.try_clone()).transpose()?,
env_vars.clone(),
cargo_args.clone(),
skip_lint,
no_docs,
@ -920,6 +950,7 @@ fn build_cwd(
build_config: &BuildConfig,
stdout: Option<File>,
stderr: Option<File>,
env_vars: Vec<String>,
cargo_args: Vec<String>,
skip_lint: bool,
no_docs: bool,
@ -937,6 +968,7 @@ fn build_cwd(
stdout,
stderr,
skip_lint,
env_vars,
cargo_args,
no_docs,
),
@ -953,6 +985,7 @@ fn build_cwd_verifiable(
stdout: Option<File>,
stderr: Option<File>,
skip_lint: bool,
env_vars: Vec<String>,
cargo_args: Vec<String>,
no_docs: bool,
) -> Result<()> {
@ -975,6 +1008,7 @@ fn build_cwd_verifiable(
build_config,
stdout,
stderr,
env_vars,
cargo_args,
);
@ -1014,6 +1048,7 @@ fn build_cwd_verifiable(
result
}
#[allow(clippy::too_many_arguments)]
fn docker_build(
cfg: &WithPath<Config>,
container_name: &str,
@ -1021,6 +1056,7 @@ fn docker_build(
build_config: &BuildConfig,
stdout: Option<File>,
stderr: Option<File>,
env_vars: Vec<String>,
cargo_args: Vec<String>,
) -> Result<()> {
let binary_name = Manifest::from_path(&cargo_toml)?.lib_name()?;
@ -1074,6 +1110,7 @@ fn docker_build(
binary_name,
stdout,
stderr,
env_vars,
cargo_args,
)
});
@ -1137,6 +1174,7 @@ fn docker_build_bpf(
binary_name: String,
stdout: Option<File>,
stderr: Option<File>,
env_vars: Vec<String>,
cargo_args: Vec<String>,
) -> Result<()> {
let manifest_path =
@ -1154,6 +1192,13 @@ fn docker_build_bpf(
"exec",
"--env",
"PATH=/root/.local/share/solana/install/active_release/bin:/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
])
.args(env_vars
.iter()
.map(|x| ["--env", x.as_str()])
.collect::<Vec<[&str; 2]>>()
.concat())
.args([
container_name,
"cargo",
"build-bpf",
@ -1292,6 +1337,7 @@ fn _build_cwd(
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn verify(
cfg_override: &ConfigOverride,
program_id: Pubkey,
@ -1299,6 +1345,7 @@ fn verify(
solana_version: Option<String>,
docker_image: Option<String>,
bootstrap: BootstrapMode,
env_vars: Vec<String>,
cargo_args: Vec<String>,
) -> Result<()> {
// Change to the workspace member directory, if needed.
@ -1324,6 +1371,7 @@ fn verify(
bootstrap, // bootstrap docker image
None, // stdout
None, // stderr
env_vars,
cargo_args,
false,
)?;
@ -2116,6 +2164,7 @@ fn test(
detach: bool,
tests_to_run: Vec<String>,
extra_args: Vec<String>,
env_vars: Vec<String>,
cargo_args: Vec<String>,
) -> Result<()> {
let test_paths = tests_to_run
@ -2142,6 +2191,7 @@ fn test(
BootstrapMode::None,
None,
None,
env_vars,
cargo_args,
false,
)?;
@ -3120,6 +3170,7 @@ fn login(_cfg_override: &ConfigOverride, token: String) -> Result<()> {
fn publish(
cfg_override: &ConfigOverride,
program_name: String,
env_vars: Vec<String>,
cargo_args: Vec<String>,
skip_build: bool,
) -> Result<()> {
@ -3250,6 +3301,7 @@ fn publish(
BootstrapMode::None,
None,
None,
env_vars,
cargo_args,
true,
)?;
@ -3332,6 +3384,7 @@ fn localnet(
skip_build: bool,
skip_deploy: bool,
skip_lint: bool,
env_vars: Vec<String>,
cargo_args: Vec<String>,
) -> Result<()> {
with_workspace(cfg_override, |cfg| {
@ -3349,6 +3402,7 @@ fn localnet(
BootstrapMode::None,
None,
None,
env_vars,
cargo_args,
false,
)?;