瀏覽代碼

Merge branch 'gitlab-ci-artifacts' into 'master'

Static compilation in GitLab CI

See merge request timvisee/ffsend!3
Tim Visée 7 年之前
父節點
當前提交
cd5588e9b6
共有 4 個文件被更改,包括 81 次插入13 次删除
  1. 69 13
      .gitlab-ci.yml
  2. 7 0
      Cargo.lock
  3. 1 0
      Cargo.toml
  4. 4 0
      src/main.rs

+ 69 - 13
.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 </dev/urandom >testfile
-    - cargo run -- upload testfile -n testfile.bin -a -d 10 -p secret -I
+    - head -c1m </dev/urandom >testfile
+    - ./ffsend upload testfile -n testfile.bin -a -d 10 -p secret -I
     # TODO: download this file, compare checksums

+ 7 - 0
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"

+ 1 - 0
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"

+ 4 - 0
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();