From ca3e704d4e4bbe1c5923db0dea60996c39b7c57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 23 Jun 2018 15:02:02 +0000 Subject: [PATCH] Static compilation in GitLab CI --- .gitlab-ci.yml | 82 ++++++++++++++++++++++++++++++++++++++++++-------- Cargo.lock | 7 +++++ Cargo.toml | 1 + src/main.rs | 4 +++ 4 files changed, 81 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d9182c..aacbc5a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,14 +2,14 @@ image: "rust:slim" stages: - check + - build - test - - integration - release variables: RUST_VERSION: stable -# Cargo artifacts caching per Rust version +# Cargo artifacts caching per Rust version and pipeline cache: key: "$RUST_VERSION" paths: @@ -19,10 +19,14 @@ cache: # Install compiler and OpenSSL dependencies before_script: - - apt-get update -y + - apt-get update - apt-get install -y --no-install-recommends build-essential pkg-config libssl-dev - - rustup install $RUST_VERSION && rustup default $RUST_VERSION - - rustc --version && cargo --version + - | + rustup install $RUST_VERSION + rustup default $RUST_VERSION + - | + rustc --version + cargo --version # Variable defaults variables: @@ -32,31 +36,83 @@ variables: .check-base: &check-base stage: check script: - - cargo check --all --verbose - - cargo check --no-default-features --all --verbose - - cargo check --features no-color --all --verbose + - cargo check --verbose + - cargo check --no-default-features --verbose + - cargo check --features no-color --verbose rust-stable: <<: *check-base rust-beta: <<: *check-base variables: RUST_VERSION: beta + cache: {} rust-nightly: <<: *check-base variables: RUST_VERSION: nightly + cache: {} + +# Build using Rust stable +build: + stage: build + script: + - cargo build --release --verbose + - mv target/release/ffsend ./ffsend + artifacts: + name: build-dynamic + paths: + - ffsend + expire_in: 1 month + +# Build a static version +build-static: + stage: build + script: + # Install the static target + - rustup target add x86_64-unknown-linux-musl + + # Build OpenSSL statically + - apt install -y build-essential wget musl-tools + - wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz + - tar xzvf openssl-1.0.2o.tar.gz + - cd openssl-1.0.2o + - ./config -fPIC --openssldir=/usr/local/ssl --prefix=/usr/local + - make + - make install + - cd .. + + # Statically build ffsend + - export OPENSSL_STATIC=1 + - export OPENSSL_LIB_DIR=/usr/local/lib + - export OPENSSL_INCLUDE_DIR=/usr/local/include + - cargo build --target=x86_64-unknown-linux-musl --release --verbose + + # Prepare the release artifact + - find . -name ffsend -exec ls -lah {} \; + - mv target/x86_64-unknown-linux-musl/release/ffsend ./ffsend + artifacts: + name: build-static + paths: + - ffsend + expire_in: 1 month # Run the unit tests through Cargo cargo-test: stage: test + dependencies: [] script: - - cargo test --all --verbose + - cargo test --verbose # Run integration test with the public Send service public-send-test: - stage: integration + stage: test + dependencies: + - build-static + variables: + GIT_STRATEGY: none + cache: {} + before_script: [] script: - - cargo build - - head -c 1M testfile - - cargo run -- upload testfile -n testfile.bin -a -d 10 -p secret -I + - head -c1m testfile + - ./ffsend upload testfile -n testfile.bin -a -d 10 -p secret -I # TODO: download this file, compare checksums diff --git a/Cargo.lock b/Cargo.lock index 8d2cfe0..717beb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,6 +362,7 @@ dependencies = [ "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "prettytable-rs 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -803,6 +804,11 @@ dependencies = [ "openssl-sys 0.9.33 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "openssl-sys" version = "0.9.33" @@ -1725,6 +1731,7 @@ dependencies = [ "checksum open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c281318d992e4432cfa799969467003d05921582a7489a8325e37f8a450d5113" "checksum openssl 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ed18a0f40ec4e9a8a81f8865033d823b7195d16a0a5721e10963ee1b0c2980ca" "checksum openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "a3605c298474a3aa69de92d21139fb5e2a81688d308262359d85cdd0d12a7985" +"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-sys 0.9.33 (registry+https://github.com/rust-lang/crates.io-index)" = "d8abc04833dcedef24221a91852931df2f63e3369ae003134e70aff3645775cc" "checksum pbr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "deb73390ab68d81992bd994d145f697451bb0b54fd39738e72eef32458ad6907" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" diff --git a/Cargo.toml b/Cargo.toml index 0750467..8b26968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ ffsend-api = "0.0" fs2 = "0.4" lazy_static = "1.0" open = "1" +openssl-probe = "0.1" pbr = "1" prettytable-rs = "0.6" rpassword = "2.0" diff --git a/src/main.rs b/src/main.rs index 75e5b8b..b5ce9e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ extern crate ffsend_api; #[cfg(feature = "history")] #[macro_use] extern crate lazy_static; +extern crate openssl_probe; extern crate prettytable; extern crate rpassword; extern crate serde; @@ -46,6 +47,9 @@ use util::{ErrorHints, exe_name, highlight, quit_error}; /// Application entrypoint. fn main() { + // Probe for OpenSSL certificates + openssl_probe::init_ssl_cert_env_vars(); + // Parse CLI arguments let cmd_handler = Handler::parse();