diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1111c4e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,60 @@ +language: rust +cache: cargo + +env: + global: + - PROJECT_NAME=iptoasn-webservice + - MAKE_DEB=yes + - DEB_MAINTAINER="Frank Denis " + - DEB_DESCRIPTION="Webservice for the iptoasn.com database" + +matrix: + include: + - os: linux + rust: nightly + env: TARGET=x86_64-unknown-linux-gnu + + allow_failures: + # TODO You might need to allow failures for some target on some channel for some reason. Below + # there's one (commented out) example of how to do that. Just change the OS, channel and TARGET + # as needed. + # - os: linux + # rust: nightly + # env: TARGET=x86_64-unknown-linux-gnu + +before_install: + - export PATH="$PATH:$HOME/.cargo/bin" + +install: + - bash ci/install.sh + +script: + - bash ci/script.sh + +before_deploy: + - bash ci/before_deploy.sh + +deploy: + provider: releases + api_key: + secure: 0Y8ZXOJaNJJ5/0IRcXyNIOJK4EICQDRtaB/E+pboNUchJn9fThGMQc2QtZaGddBNrnuHsftBFM7mWXJvZ2H9YGgbBl1N6Z2y33vawSPgzTnfz0CZRJfX1Gl6IdtDH9zvlblHI1aE4eJ6lAu0q8VQ874CBPxoIlzU9jArOTdvyPT+8t64Y0K240trfqrm0NHloUbZtm+HeRJqoK1RKE4kdrpESIVMyyq67fM9T0VqLg+x3OHeQ/itFnZpjqtVtj9WhZeKM6iTNLQT+vLpRAvq8w6sv1WeCMYAqdXUL7jQnVaI+MiepC9z8OoF0ZAYes0I+3aaNsgMHiuwkW+nDUcQp5XLDW3oCq/uST4pN2ki/AJPy4UUUx++xb8SgtKE4wzBGbT0u5yO9JkIPxJZRLy+E0IvTlqVEZL/tvnI09JQQmzgDdP1hCcxpxBBm4xLi/2qSHIJIMUbb92DRwOrTii34+C0oa1UZKh2P/ceCtLNOlOCmFAcWE9uAxjEGP903mmgbixj8xBbyuROedHIMxag0Jr9Tdoi0hsVdhOEss4JjNKf7ayjepRIw5lNFjxk+jgB+Om0J3vQ+i83LxX1a0b9YV+KJUtWz/CV43mwYhF+jh2GAMe0/cvNCbFT4au0SW2FKDvV/00AJ5tPGimVXNe0e+AUqjbJ2sRpylIQw1Mfl6Y= + file_glob: true + file: ${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.* + # don't delete the artifacts from previous phases + skip_cleanup: true + # deploy when a new tag is pushed + on: + condition: $TRAVIS_RUST_VERSION = nightly + tags: true + +branches: + only: + # Pushes and PR to the master branch + - master + # IMPORTANT Ruby regex to match tags. Required, or travis won't trigger deploys when a new tag + # is pushed. This regex matches semantic versions like v1.2.3-rc4+2016.02.22 + - /^\d+\.\d+\.\d+.*$/ + +notifications: + email: + on_success: change diff --git a/Cargo.lock b/Cargo.lock index 9fcd96c..f69df25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,5 @@ [root] -name = "ip2asn-api" +name = "iptoasn-webservice" version = "0.1.0" dependencies = [ "clap 2.16.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 86ea9f1..55c790c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "ip2asn-api" +name = "iptoasn-webservice" version = "0.1.0" authors = ["Frank Denis "] diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh new file mode 100644 index 0000000..46124da --- /dev/null +++ b/ci/before_deploy.sh @@ -0,0 +1,69 @@ +# `before_deploy` phase: here we package the build artifacts + +set -ex + +. $(dirname $0)/utils.sh + +# Generate artifacts for release +mk_artifacts() { + cargo build --target $TARGET --release +} + +mk_tarball() { + # create a "staging" directory + local td=$(mktempd) + local out_dir=$(pwd) + + # TODO update this part to copy the artifacts that make sense for your project + # NOTE All Cargo build artifacts will be under the 'target/$TARGET/{debug,release}' + cp target/$TARGET/release/iptoasn_webservice $td + dostrip $td/iptoasn_webservice + + pushd $td + + # release tarball will look like 'rust-everywhere-v1.2.3-x86_64-unknown-linux-gnu.tar.gz' + tar czf $out_dir/${PROJECT_NAME}-${TRAVIS_TAG}-${TARGET}.tar.gz * + + popd + rm -r $td +} + +# Package your artifacts in a .deb file +# NOTE right now you can only package binaries using the `dobin` command. Simply call +# `dobin [file..]` to include one or more binaries in your .deb package. I'll add more commands to +# install other things like manpages (`doman`) as the needs arise. +# XXX This .deb packaging is minimal -- just to make your app installable via `dpkg` -- and doesn't +# fully conform to Debian packaging guideliens (`lintian` raises a few warnings/errors) +mk_deb() { + # TODO update this part to package the artifacts that make sense for your project + dobin target/$TARGET/release/iptoasn_webservice +} + +main() { + mk_artifacts + mk_tarball + + if [ $TRAVIS_OS_NAME = linux ]; then + if [ ! -z $MAKE_DEB ]; then + dtd=$(mktempd) + mkdir -p $dtd/debian/usr/bin + + mk_deb + + mkdir -p $dtd/debian/DEBIAN + cat >$dtd/debian/DEBIAN/control <>.cargo/config </dev/null || mktemp -d -t tmp) +} + +host() { + case "$TRAVIS_OS_NAME" in + linux) + echo x86_64-unknown-linux-gnu + ;; + osx) + echo x86_64-apple-darwin + ;; + esac +} + +gcc_prefix() { + case "$TARGET" in + aarch64-unknown-linux-gnu) + echo aarch64-linux-gnu- + ;; + arm*-gnueabihf) + echo arm-linux-gnueabihf- + ;; + *-musl) + echo musl- + ;; + *) + return + ;; + esac +} + +dostrip() { + local stu=strip prefix=$(gcc_prefix) + if which ${prefix}strip > /dev/null; then + stu=${prefix}strip + fi + if strip --version 2>/dev/null | fgrep GNU >/dev/null ; then + $stu -s $1 + else + $stu $1 + fi +} + +dobin() { + [ -z $MAKE_DEB ] && die 'dobin: $MAKE_DEB not set' + [ $# -lt 1 ] && die "dobin: at least one argument needed" + + local f prefix=$(gcc_prefix) + for f in "$@"; do + install -m0755 $f $dtd/debian/usr/bin/ + dostrip $dtd/debian/usr/bin/$(basename $f) + done +} + +architecture() { + case $1 in + x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl) + echo amd64 + ;; + i686-unknown-linux-gnu|i686-unknown-linux-musl) + echo i386 + ;; + arm*-unknown-linux-gnueabihf) + echo armhf + ;; + *) + die "architecture: unexpected target $TARGET" + ;; + esac +}