Skip to content

Commit

Permalink
add rustup version
Browse files Browse the repository at this point in the history
env default /etc/profile
  • Loading branch information
General-Beck committed Oct 17, 2019
1 parent 78aabdd commit feb6d92
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 27 deletions.
27 changes: 27 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -42,23 +42,27 @@ remote = "builds@myserver"

### Flags and options
```
cargo-remote
USAGE:
cargo remote [FLAGS] [OPTIONS] <command>
cargo remote [FLAGS] [OPTIONS] <command> [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 <manifest_path> Path to the manifest to execute
-r, --remote <remote> remote ssh build server
-b, --build-env <build_env> Set remote environment variables. RUST_BACKTRACE, CC, LIB, etc. [default:
RUST_BACKTRACE=1]
-e, --env <env> Environment profile. default_value = /etc/profile [default: /etc/profile]
--manifest-path <manifest_path> Path to the manifest to execute [default: Cargo.toml]
-r, --remote <remote> Remote ssh build server
-d, --rustup-default <rustup_default> Rustup default (stable|beta|nightly) [default: stable]
ARGS:
<command> cargo command that will be executed remotely
<command> cargo command that will be executed remotely
<remote options>... cargo options and flags that will be applied remotely
```


Expand Down
37 changes: 37 additions & 0 deletions REMOTE_SETUP.MD
Original file line number Diff line number Diff line change
@@ -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
74 changes: 56 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};
use std::process::{exit, Command, Stdio};

use structopt::StructOpt;
use toml::Value;

Expand All @@ -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<String>,

#[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,

Expand All @@ -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,

Expand Down Expand Up @@ -79,6 +102,9 @@ fn main() {

let Opts::Remote {
remote,
build_env,
rustup_default,
env,
copy_back,
manifest_path,
hidden,
Expand All @@ -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")
Expand All @@ -121,14 +153,15 @@ 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
let mut rsync_to = Command::new("rsync");
rsync_to
.arg("-a".to_owned())
.arg("--delete")
.arg("--compress")
.arg("--info=progress2")
.arg("--exclude")
.arg("target");
Expand All @@ -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())
Expand Down

0 comments on commit feb6d92

Please sign in to comment.