Skip to content

Commit

Permalink
build refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
John H committed Mar 30, 2016
1 parent 27563a8 commit deaf98d
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 13 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
debian/
dhcpd.conf
Dockerfile
extra/
gruntfile.js
HWIMO-*
LICENSE
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ node_modules
# IDE
.idea

# Vagrant
.vagrant/

# Gyp Build
build

Expand Down
15 changes: 2 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,10 @@ addons:
- git

after_success:
- ./node_modules/.bin/istanbul cover -x "**/spec/**" ./node_modules/.bin/_mocha --report lcovonly -- $(find spec -name '*-spec.js') -R spec --require spec/helper.js
- cat ./coverage/lcov.info | node_modules/.bin/coveralls
- ./extra/make-testcoveralls.sh

before_deploy:
- npm prune --production
- mkdir -p packagebuild deb
- cp -ar !(packagebuild) packagebuild/
- pushd packagebuild
- git log -n 1 --pretty=format:%h.%ai.%s > commitstring.txt
- export DEBFULLNAME=`git log -n 1 --pretty=format:%an`
- export DEBEMAIL=`git log -n 1 --pretty=format:%ae`
- dch -l `echo "${TRAVIS_BRANCH}" | sed 's/[\/\_]/-/g'` -u low `git log -n 1 --pretty=oneline --abbrev-commit`
- debuild --no-lintian --no-tgz-check -us -uc
- popd
- cp -a *.deb deb/
- ./extra/make-deb.sh

deploy:
provider: bintray
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ The unit tests can be run with standard node tools:
npm test

`./HWIMO-TEST` will run local tests, and was built for running on a jenkins build slave, and will run the tests, jshint, and code coverage all together.

## Building

Unversioned packages are built automatically from travis-ci and uploaded to bintray.com. Using
this repository is detailed in [the docs](http://rackhd.readthedocs.org/en/latest/rackhd/ubuntu_package_installation.html).

Build scripts are placed in the `extra/` directory.

* `.travis.yml` will call the appropriate scripts in `extra/` to build an unversioned package.
* `extra/make-sysdeps.sh` can be used to install system level packages in a Ubuntu system.
* `extra/make-cicd.sh` will perform all the necessary build steps to generate a version package.

If you want to build your own versioned packages, you can use the Vagrantfile provided in `extra/`. Simply perform `vagrant up` and it will run all the necessary steps.
73 changes: 73 additions & 0 deletions extra/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.synced_folder "../", "/vagrant"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true

# Customize the amount of memory on the VM:
vb.memory = "1024"
end
#
# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
cd /vagrant
sudo ./extra/make-sysdeps.sh
./extra/make-cicd.sh
SHELL
end
28 changes: 28 additions & 0 deletions extra/make-cicd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# This creates a package in a manner similar to
# HWIMO-BUILD: datestring package version, apidoc
# no coveralls. But it also utilizes build-package.bash
# similar to how travis-ci does.

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

export DEBEMAIL="hwimo robots <[email protected]>"
export DEBFULLNAME="The HWIMO Robots"

GITCOMMITDATE=$(git show -s --pretty="format:%ci")
DATESTRING=$(date -d "$GITCOMMITDATE" -u +"%Y-%m-%d-%H%M%SZ")

export DEBPKGVER="$DATESTRING"
if [ -n "$BUILD_NUMBER" ]
then
export DEBPKGVER="${DEBPKGVER}-${BUILD_NUMBER}"
fi

export DCHOPTS="-v ${DEBPKGVER} autobuild"

./extra/make-npmdeps.sh
./extra/make-deb.sh

15 changes: 15 additions & 0 deletions extra/make-clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

rm -rf *.deb deb/
rm -rf node_modules/
rm -rf test/
rm commitstring.txt
rm -rf on-*.tar.gz*
rm -rf on-*.build
rm -rf on-*.dsc
rm -rf *.build
rm -rf packagebuild/
53 changes: 53 additions & 0 deletions extra/make-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

BRANCH=$(git symbolic-ref --short -q HEAD)

if [ -z "$DEBFULLNAME" ]; then
export DEBFULLNAME=`git log -n 1 --pretty=format:%an`
fi

if [ -z "$DEBEMAIL" ]; then
export DEBEMAIL=`git log -n 1 --pretty=format:%ae`
fi

if [ -z "$DEBBRANCH" ]; then
export DEBBRANCH=`echo "${BRANCH}" | sed 's/[\/\_]/-/g'`
fi

if [ -z "$DEBPKGVER" ]; then
export DEBPKGVER=`git log -n 1 --pretty=oneline --abbrev-commit`
fi

if [ -z "$DCHOPTS" ]; then
export DCHOPTS="-l ${DEBBRANCH} -u low ${DEBPKGVER}"
fi

echo "DEBDIR: $DEBDIR"
echo "DEBFULLNAME: $DEBFULLNAME"
echo "DEBEMAIL: $DEBEMAIL"
echo "DEBBRANCH: $DEBBRANCH"
echo "DEBPKGVER: $DEBPKGVER"
echo "DCHOPTS: $DCHOPTS"


if [ -d packagebuild ]; then
rm -rf packagebuild
fi

git clone . packagebuild
pushd packagebuild
rm -rf node_modules
npm install --production
git log -n 1 --pretty=format:%h.%ai.%s > commitstring.txt
dch ${DCHOPTS}
debuild --no-lintian --no-tgz-check -us -uc
popd
if [ ! -d deb ]; then
mkdir deb
fi

cp -a *.deb deb/
7 changes: 7 additions & 0 deletions extra/make-npmdeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

npm install
7 changes: 7 additions & 0 deletions extra/make-npmtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

npm test
19 changes: 19 additions & 0 deletions extra/make-sysdeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# This has to be kept in sync with .travis.yml packages to
# be effective.

echo "Installing system dependencies"
sudo apt-get update
sudo apt-get install -y \
debhelper \
default-jdk \
devscripts \
dh-make \
git \
libkrb5-dev \
nodejs \
nodejs-legacy \
npm \
pbuilder \
ubuntu-dev-tools
9 changes: 9 additions & 0 deletions extra/make-testcoveralls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Ensure we're always in the right directory.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $SCRIPT_DIR/..

./node_modules/.bin/istanbul cover -x "**/spec/**" ./node_modules/.bin/_mocha --report lcovonly -- $(find spec -name '*-spec.js') -R spec --require spec/helper.js
cat ./coverage/lcov.info | node_modules/.bin/coveralls

0 comments on commit deaf98d

Please sign in to comment.