diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..705c500 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,27 @@ +stages: + - audit + - build +image: ${REGISTRY}/parity-ci-linux:latest + +variables: + GIT_STRATEGY: fetch + GIT_SUBMODULE_STRATEGY: recursive + CI_SERVER_NAME: "GitLab CI" + CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}" + CARGO_TARGET: x86_64-unknown-linux-gnu + REGISTRY: registry.parity.io/parity/infrastructure/scripts + +cargo_audit: + stage: audit + script: + - cargo audit + tags: + - linux-docker + allow_failure: true + +cargo_remote_build: + stage: build + script: + - cargo build --release + tags: + - linux-docker diff --git a/README.md b/README.md index 813ecea..46aeaaa 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ the same rust version and have the same processor architecture. On the client `s and `rsync` need to be installed. If you want to pass remote flags you have to end the options/flags section using -`--`. E.g. to build in release mode and copy back the result use: +`--`. E.g. to build in release mode and copy back the result use: ```bash cargo remote -c -- build --release ``` @@ -42,23 +42,27 @@ remote = "builds@myserver" ### Flags and options ``` -cargo-remote - USAGE: - cargo remote [FLAGS] [OPTIONS] + cargo remote [FLAGS] [OPTIONS] [remote options]... FLAGS: - -c, --copy-back transfer the target folder back to the local machine + -c, --copy-back Transfer the target folder back to the local machine --help Prints help information - -h, --transfer-hidden transfer hidden files and directories to the build server + -h, --transfer-hidden Transfer hidden files and directories to the build server -V, --version Prints version information OPTIONS: - --manifest-path Path to the manifest to execute - -r, --remote remote ssh build server + -b, --build-env Set remote environment variables. RUST_BACKTRACE, CC, LIB, etc. [default: + RUST_BACKTRACE=1] + -e, --env Environment profile. default_value = /etc/profile [default: /etc/profile] + --manifest-path Path to the manifest to execute [default: Cargo.toml] + -r, --remote Remote ssh build server + -d, --rustup-default Rustup default (stable|beta|nightly) [default: stable] ARGS: - cargo command that will be executed remotely + cargo command that will be executed remotely + ... cargo options and flags that will be applied remotely + ``` diff --git a/REMOTE_SETUP.MD b/REMOTE_SETUP.MD new file mode 100644 index 0000000..799efba --- /dev/null +++ b/REMOTE_SETUP.MD @@ -0,0 +1,37 @@ +1 step +nano /etc/profile +export PATH=/usr/local/cargo/bin:$PATH +export RUSTUP_HOME=/usr/local/rustup +export CARGO_HOME=/usr/local/cargo +2 install rust +wget https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init +chmod +x rustup-init; \ + ./rustup-init -y --no-modify-path --default-toolchain stable; \ + rm rustup-init; \ + chmod -R a+w+r /usr/local/cargo/; \ + chmod -R a+w+r /usr/local/cargo/; \ + rustup install nightly beta; \ + rustup target add wasm32-unknown-unknown --toolchain nightly; \ + cargo install cargo-audit --force; \ + cargo install sccache --features redis --force; \ + cargo install --git https://github.com/alexcrichton/wasm-gc --force ; +3 redis +protected mode no + +maxmemory 50gb +maxmemory-policy allkeys-lru +service redis restart +3 setup sccache+redis +nano /etc/profile +export PATH=/usr/local/cargo/bin:$PATH +export RUSTUP_HOME=/usr/local/rustup +export CARGO_HOME=/usr/local/cargo +export SCCACHE_IDLE_TIMEOUT=0 +export SCCACHE_REDIS=redis://127.0.0.1/0 +export RUSTC_WRAPPER=sccache +4 user +export PATH="$HOME/.cargo/bin:$PATH" +export RUSTUP_HOME=$HOME/.rustup +export CARGO_HOME=$HOME/.cargo + +rustup install stable diff --git a/src/main.rs b/src/main.rs index 7b121f1..a7d9165 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use std::path::{Path, PathBuf}; use std::process::{exit, Command, Stdio}; - use structopt::StructOpt; use toml::Value; @@ -11,13 +10,37 @@ use log::{error, info, warn}; enum Opts { #[structopt(name = "remote")] Remote { - #[structopt(short = "r", long = "remote", help = "remote ssh build server")] + #[structopt(short = "r", long = "remote", help = "Remote ssh build server")] remote: Option, + #[structopt( + short = "b", + long = "build-env", + help = "Set remote environment variables. RUST_BACKTRACE, CC, LIB, etc. ", + default_value = "RUST_BACKTRACE=1" + )] + build_env: String, + + #[structopt( + short = "d", + long = "rustup-default", + help = "Rustup default (stable|beta|nightly)", + default_value = "stable" + )] + rustup_default: String, + + #[structopt( + short = "e", + long = "env", + help = "Environment profile. default_value = /etc/profile", + default_value = "/etc/profile" + )] + env: String, + #[structopt( short = "c", long = "copy-back", - help = "transfer the target folder back to the local machine" + help = "Transfer the target folder back to the local machine" )] copy_back: bool, @@ -32,7 +55,7 @@ enum Opts { #[structopt( short = "h", long = "transfer-hidden", - help = "transfer hidden files and directories to the build server" + help = "Transfer hidden files and directories to the build server" )] hidden: bool, @@ -79,6 +102,9 @@ fn main() { let Opts::Remote { remote, + build_env, + rustup_default, + env, copy_back, manifest_path, hidden, @@ -90,16 +116,22 @@ fn main() { metadata_cmd.manifest_path(manifest_path).no_deps(); let project_metadata = metadata_cmd.exec().unwrap(); - - // for now, assume that there is only one project and find it's root directory - let (project_dir, project_name) = project_metadata.packages.first().map_or_else( - || { - error!("No project found."); - exit(-2); - }, - |project| (&project_metadata.workspace_root, &project.name), - ); - + let project_dir = project_metadata.workspace_root; + info!("Project dir: {:?}", project_dir); + let mut manifest_path = project_dir.clone(); + manifest_path.push("Cargo.toml"); + let project_name = project_metadata + .packages + .iter() + .find(|p| p.manifest_path == manifest_path) + .map_or_else( + || { + error!("No project found."); + exit(-2); + }, + |p| &p.name, + ); + info!("Project name: {:?}", project_name); let configs = vec![ config_from_file(&project_dir.join(".cargo-remote.toml")), xdg::BaseDirectories::with_prefix("cargo-remote") @@ -121,7 +153,7 @@ fn main() { exit(-3); }); - let build_path = format!("~/remote-builds/{}/", project_name); + let build_path = format!("~/remote-builds/{:?}/", project_name); info!("Transferring sources to build server."); // transfer project to build server @@ -129,6 +161,7 @@ fn main() { rsync_to .arg("-a".to_owned()) .arg("--delete") + .arg("--compress") .arg("--info=progress2") .arg("--exclude") .arg("target"); @@ -150,17 +183,22 @@ fn main() { error!("Failed to transfer project to build server (error: {})", e); exit(-4); }); - + info!("Build ENV: {:?}", build_env); + info!("Environment profile: {:?}", env); + info!("Build path: {:?}", build_path); let build_command = format!( - "source /etc/profile; cd {}; cargo {} {}", + "source {}; rustup default {}; cd {}; {} cargo {} {}", + env, + rustup_default, build_path, + build_env, command, options.join(" ") ); info!("Starting build process."); Command::new("ssh") - .arg("-t") + //.arg("-t") .arg(&build_server) .arg(build_command) .stdout(Stdio::inherit())