Skip to content

Commit

Permalink
Add support for travis ci releases and local build without using vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
benhylau authored Dec 14, 2018
1 parent 33297ab commit 334ae8f
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 107 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
dist: xenial
sudo: required

install:
- ./bootstrap.sh
before_script:
- source /etc/profile
script:
- cd $HOME
- make
before_deploy:
- cd $HOME
- make package
deploy:
- provider: releases
api_key:
secure: QhoV/L0862+DUInpkcaV8f1g8sWfzA0Md6hg4PX+SFMWntwxRIlrSAmilAGyU300WQn4euWMv2CW5R+hjGKbVBFED8vCJVFu4EZtfH4L+fpx58AjFFQkcQ/kgpjFMf2vSTS9VIvz7JGfUB3XodpSmBJvdH89MHx7q6VQXAVHGBUusw9p9PdXCZG27eT9/aNcVxRoqlWqrf9LmBSh+MBUCHdUCoLOwyZ9YLQ6/nTYsQsJlYEYbD9pseWHtHWQZdxYiNStkLhdEnF82RXYcDM3rOaSEHZt67Ae7O95UgXdfpsnRAqIL2+lmgHIQ7Mva+9l8yjxs9yiomnGqmocn8Y1/Woa5KrtiqlV7QRs4NM1k7cy39h+EL4DQ2TSNKTqQbcIg9mFn+qtyB7024KeAXJ+ejN3blESI5AqnXiHtaMhLmED+HBXAsQZ3Go5eLFyWD2Lx3lcZcTTDjSVqx4qk5Wh8gKyOS6WKpDOPPAoa2zBaaE63fZ/wqKuW57ARACnfZLs75We2deGbv16COaM6rq9rwa29VhBqGvtpB7SPi8H5K8mRqjDNYUJC33/J9+CqLOvYbs4KV3+HUT3tWSi1TpDIcQ0UmzJOAv2W96xN/mTn+t5RYV7kIydzULEKlkdGltEB8PC4G6yUa2FNvJwRVSl1e3ClSAhW22Fy7MzbASU6YI=
file_glob: true
file: /tmp/publish/*
skip_cleanup: true
on:
repo: benhylau/mesh-router-builder
tags: true
79 changes: 56 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ to create mesh routers on ARM devices. The following single-board computers are
supported by mesh-orange:

* raspberrypi2
* raspberrypi3
* raspberrypi3 (for 3b and 3b+)
* sun4i-a10-cubieboard
* sun7i-a20-bananapi
* sun8i-h2-plus-orangepi-zero
Expand All @@ -27,21 +27,32 @@ supported by mesh-orange:

Note that only **raspberrypi2**, **raspberrypi3**, and
**sun8i-h2-plus-orangepi-zero** are enabled by default. Uncomment boards in
`/home/vagrant/mesh-orange-images/Makefile` after ssh-ing to your Vagrant machine
`~/mesh-orange-images/Makefile` after ssh-ing to your Vagrant machine
to enable the other boards you want.

Usage
-----

Ensure you have [Vagrant](https://www.vagrantup.com) installed, then clone
this repository and run:
You can use this builder in three environments:

$ vagrant up
$ vagrant ssh
| OS | Self-managed VM | Vagrant-managed VM | Travis CI |
|:---------|:---------------:|:--------------------------------------------------------------------:|:---------:|
|**Debian**| `stretch` | [debian/stretch64](https://app.vagrantup.com/debian/boxes/stretch64) | |
|**Ubuntu**| `xenial` | [ubuntu/xenial64](https://app.vagrantup.com/ubuntu/boxes/xenial64) | [![Build Status](https://travis-ci.org/benhylau/mesh-router-builder.svg?branch=master)](https://travis-ci.org/benhylau/mesh-router-builder) [![GitHub release](https://img.shields.io/github/release/benhylau/mesh-router-builder.svg)](https://github.com/benhylau/mesh-router-builder/releases) |

In the Vagrant machine, call `make` (optionally, `make PROFILE=custom-profile`).
When the build completes, call `exit` and find the built artifacts in the
**output** directory of your host:
### Self-managed VM

It is highly recommended that you spin up a fresh **Debian Stretch** or **Ubuntu Xenial**
VM to use this builder. Using a non-root user with `sudo`, from its `$HOME` directory,
run the following commands:

$ git clone https://github.com/benhylau/mesh-router-builder.git
$ ./bootstrap.sh
$ source /etc/profile
$ cd $HOME
$ make (optionally, make PROFILE=custom-profile)

You will find built artifacts in the `~/mesh-router-builder/output` directory:

./output/debian-packages/yggdrasil-go_0.1-1_amd64.deb
yggdrasil-go_0.1-1_armhf.deb
Expand All @@ -50,14 +61,46 @@ When the build completes, call `exit` and find the built artifacts in the
sun8i-h2-plus-orangepi-zero.img
...

### Vagrant-managed VM

This is the recommended way to use this builder. Ensure you have
[Vagrant](https://www.vagrantup.com) installed, then clone this repository and run:

$ vagrant up
$ vagrant ssh

In the Vagrant machine, call `make` (optionally, `make PROFILE=custom-profile`).
When the build completes, call `exit` and find the built artifacts in the
**output** directory of your host.

Then you may destroy the Vagrant machine with `vagrant destroy`.

#### macOS High Sierra

There is a known bug in macOS High Sierra that prevents Synced Folders from
working. You will have to get the built artifacts manually before destroying the
Vagrant machine:

$ vagrant ssh-config > vagrant-ssh.conf
$ mkdir output-macos
$ scp -r -F vagrant-ssh.conf mesh-router-builder:/vagrant/output/* output-macos/

### Travis CI

This repository auto-builds in a Ubuntu Xenial environment using Travis CI. See
[.travis.yml](https://github.com/benhylau/mesh-router-builder/blob/travis/.travis.yml)
for details.

Publish to GitHub Releases
--------------------------

If you wish to publish the built artifacts to _GitHub Releases_, create a file
named **.github_publish** in the project root before `vagrant up` with the
following information:
Travis CI is configured to publish official artifacts to
[GitHub Releases](https://github.com/benhylau/mesh-router-builder/releases) on each
release tag.

If you wish to manually publish to GitHub Releases of a forked repository, create a file
named **.github_publish** in the project root before `vagrant up` with the following
information:

GITHUB_USERNAME=<username>
GITHUB_REPOSITORY=<repository-name>
Expand All @@ -75,15 +118,5 @@ images, and used to tag the release. Your file should look something like this:
GITHUB_RELEASE_VERSION=0.1

After `make` completes, you can call `make publish` and all artifacts will be
published to _Github Releases_ in your repository.
published to Github Releases in your repository.

macOS High Sierra
-----------------

There is a known bug in macOS High Sierra that prevents Synced Folders from
working. You will have to get the built artifacts manually before destroying the
Vagrant machine:

$ vagrant ssh-config > vagrant-ssh.conf
$ mkdir output-macos
$ scp -r -F vagrant-ssh.conf mesh-router-builder:/vagrant/output/* output-macos/
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Vagrant.configure("2") do |config|
config.vm.define "mesh-router-builder"
config.vm.box = "debian/stretch64"
config.vm.box_version = "9.3.0"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.provision :shell, path: "bootstrap.sh", privileged: false

config.vm.provider "virtualbox" do |v|
v.memory = 2048
Expand Down
123 changes: 107 additions & 16 deletions bootstrap.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

# Install standard tools
apt install -y \
sudo apt update
sudo apt install -y \
apache2 \
apt-transport-https \
build-essential \
Expand All @@ -14,30 +15,120 @@ apt install -y \
# Install golang
mkdir /tmp/golang
wget --progress=bar:force https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz -P /tmp/golang
tar -C /usr/local -xzf /tmp/golang/go1.11.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf /tmp/golang/go1.11.2.linux-amd64.tar.gz
{
echo ''
echo '# Add golang path'
echo 'export PATH=$PATH:/usr/local/go/bin'
} >> /etc/profile
} | sudo tee --append /etc/profile > /dev/null

# Install nodejs
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
apt-get install -y nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

# Copy build scripts from Synced Folder to Vagrant machine user home
cp -r /vagrant/src/* /home/vagrant/
chown -R vagrant:vagrant /home/vagrant/*
###################################
# Platform specific configurations
###################################

# Copy github release publishing configurations
if [ -f /vagrant/.github_publish ]; then
. /vagrant/.github_publish
# Install keys required for ubuntu xenial
if [ `lsb_release -c -s` == 'xenial' ]; then
# See mesh-orange documentation regarding keys being installed
sudo apt-get -y install debian-archive-keyring
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EF0F382A1A7B6500
fi

###################################
# Build environment configurations
###################################

# Configure for vagrant build environment
if [ "$USER" == 'vagrant' ]; then
echo 'Vagrant environment detected'

# Set source directory to path in synced folder
echo 'Setting source directory to Synced Folder at /vagrant/src'
SOURCE_DIR=/vagrant/src

# Set local directory for build artifacts to synced folder
echo 'Setting local directory for build artifacts at /vagrant/output'
{
echo ''
echo '# Set local directory for build artifacts'
echo 'export BUILD_ARTIFACTS_DIR=/vagrant/output'
} | sudo tee --append /etc/profile > /dev/null

# Copy github release publishing configurations
if [ -f /vagrant/.github_publish ]; then
. /vagrant/.github_publish
echo "Setting GitHub Release version to $GITHUB_RELEASE_VERSION"
{
echo ''
echo '# GitHub Release publishing configurations'
echo "export GITHUB_USERNAME=$GITHUB_USERNAME"
echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
echo "export GITHUB_TOKEN=$GITHUB_TOKEN"
echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION"
} | sudo tee --append /etc/profile > /dev/null
fi

# Configure for travis build environment
elif [ "$USER" == 'travis' ]; then
echo 'Travis environment detected'

# Set source directory to path where travis clones repository
echo "Setting source directory to Travis build directory at $TRAVIS_BUILD_DIR/src"
SOURCE_DIR=$TRAVIS_BUILD_DIR/src

# Set local directory for build artifacts
echo "Setting local directory for build artifacts at $HOME/output"
{
echo ''
echo '# Set local directory for build artifacts'
echo "export BUILD_ARTIFACTS_DIR=$HOME/output"
} | sudo tee --append /etc/profile > /dev/null

# Set github release from travis publishing configurations
echo "Setting GitHub Release version to `$TRAVIS_TAG | sed 's/^v//'`"
{
echo ''
echo '# GitHub Release publishing configurations'
echo "export GITHUB_USERNAME=$GITHUB_USERNAME"
echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
echo "export GITHUB_TOKEN=$GITHUB_TOKEN"
echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION"
} >> /etc/profile
echo "export GITHUB_RELEASE_VERSION=`echo $TRAVIS_TAG | sed 's/^v//'`"
} | sudo tee --append /etc/profile > /dev/null

# Install tools required to cross-compile cjdns in travis environment
sudo apt install -y libc6-dev-armhf-cross

# Configure for local build environment
else
# Set source directory to local path relative to this script
echo "Setting source directory to local directory at `cd "$(dirname "${BASH_SOURCE[0]}")" && pwd`/src"
SOURCE_DIR=`cd "$(dirname "${BASH_SOURCE[0]}")" && pwd`/src

# Set local directory for build artifacts
echo "Setting local directory for build artifacts at `pwd`/output"
{
echo ''
echo '# Set local directory for build artifacts'
echo "export BUILD_ARTIFACTS_DIR=`pwd`/output"
} | sudo tee --append /etc/profile > /dev/null

# Copy github release publishing configurations
if [ -f .github_publish ]; then
. .github_publish
echo "Setting GitHub Release version to $GITHUB_RELEASE_VERSION"
{
echo ''
echo '# GitHub Release publishing configurations'
echo "export GITHUB_USERNAME=$GITHUB_USERNAME"
echo "export GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
echo "export GITHUB_TOKEN=$GITHUB_TOKEN"
echo "export GITHUB_RELEASE_VERSION=$GITHUB_RELEASE_VERSION"
} | sudo tee --append /etc/profile > /dev/null
fi
fi

# Copy build scripts to user home
cp -r $SOURCE_DIR/* /home/$USER/
chown -R $USER:$USER /home/$USER/*

16 changes: 9 additions & 7 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
PACKAGES_DIR = debian-packages
IMAGES_DIR = mesh-orange-images

BUILT_PACKAGES_DIR = /vagrant/output/debian-packages
BUILT_IMAGES_DIR = /vagrant/output/mesh-orange-images
BUILT_PACKAGES_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages
BUILT_IMAGES_DIR = ${BUILD_ARTIFACTS_DIR}/mesh-orange-images
PUBLISH_DIR = /tmp/publish

build_images: build_packages
Expand All @@ -15,14 +15,16 @@ build_images: build_packages
build_packages:
$(MAKE) -C $(PACKAGES_DIR)

publish:
rm -rf $(PUBLISH_DIR)
mkdir $(PUBLISH_DIR)
cp $(BUILT_PACKAGES_DIR)/* $(PUBLISH_DIR)/
cp $(BUILT_IMAGES_DIR)/* $(PUBLISH_DIR)/
publish: package
go get -u github.com/tcnksm/ghr
go/bin/ghr \
-username ${GITHUB_USERNAME} \
-repository ${GITHUB_REPOSITORY} \
-token ${GITHUB_TOKEN} \
"v${GITHUB_RELEASE_VERSION}" $(PUBLISH_DIR)

package:
rm -rf $(PUBLISH_DIR)
mkdir $(PUBLISH_DIR)
cp $(BUILT_PACKAGES_DIR)/* $(PUBLISH_DIR)/
cp $(BUILT_IMAGES_DIR)/* $(PUBLISH_DIR)/
2 changes: 1 addition & 1 deletion src/debian-packages/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SUBDIRS += cjdns/
SUBDIRS += yggdrasil-go/

BUILD_DIR = /tmp/debian-repo
DEB_PACKAGES_DIR = /vagrant/output/debian-packages
DEB_PACKAGES_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages

localhost_deb: package_deb
rm -rf $(BUILD_DIR)
Expand Down
2 changes: 1 addition & 1 deletion src/debian-packages/cjdns/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SOURCE_URL = https://github.com/cjdelisle/cjdns
TAG = cjdns-v20.2
ARCHS = amd64 armhf
BUILD_DIR = /tmp/$(PACKAGE_NAME)
OUTPUT_DIR = /vagrant/output/debian-packages
OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages

# Package deb for a particular architecture
#
Expand Down
2 changes: 1 addition & 1 deletion src/debian-packages/yggdrasil-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SOURCE_URL = https://github.com/yggdrasil-network/yggdrasil-go
TAG = master
ARCHS = amd64 armhf
BUILD_DIR = /tmp/$(PACKAGE_NAME)
OUTPUT_DIR = /vagrant/output/debian-packages
OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/debian-packages

# Package deb for a particular architecture
#
Expand Down
2 changes: 1 addition & 1 deletion src/mesh-orange-images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PROFILE ?= default

TAG = master
BUILD_DIR = /tmp/mesh-orange
OUTPUT_DIR = /vagrant/output/mesh-orange-images
OUTPUT_DIR = ${BUILD_ARTIFACTS_DIR}/mesh-orange-images

# raspberrypi3 is automatically generated when raspberrypi2 is enabled because they share the same image
BOARDS += raspberrypi2
Expand Down
Empty file.
Loading

0 comments on commit 334ae8f

Please sign in to comment.