Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Build harness #1

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d1ed405
Initial commit
goruha Jan 17, 2017
c96fd4e
Travis docker harness
goruha Jan 17, 2017
8dba888
Travis docker harness
goruha Jan 17, 2017
5d7360f
Travis docker harness
goruha Jan 17, 2017
c737f92
Add github download release
goruha Jan 17, 2017
5345e38
WIP: Initial harness (#1)
goruha Jan 17, 2017
9593e85
Implement harness support
goruha Jan 17, 2017
9e5b8d2
Implement harness support
goruha Jan 17, 2017
9408ce4
Added new harness
goruha Jan 18, 2017
ce20d95
Added new harness
goruha Jan 18, 2017
f77a933
Added new harness
goruha Jan 18, 2017
279dd1d
Added new harness
goruha Jan 18, 2017
8bf3e4f
WIP - fix
goruha Jan 19, 2017
ef03ce5
WIP - fix
goruha Jan 19, 2017
790e5d3
Added initial make files
goruha Jan 19, 2017
4838dfb
Added build-harness right way
goruha Jan 19, 2017
f3bedeb
Added build-harness right way
goruha Jan 19, 2017
4a60895
Added build-harness right way
goruha Jan 19, 2017
13a68bb
Added build-harness right way
goruha Jan 19, 2017
1d11620
Move complex bash scripts to separete files
goruha Jan 19, 2017
822b055
Move complex bash scripts to separete files
goruha Jan 19, 2017
edef32f
Move complex bash scripts to separete files
goruha Jan 19, 2017
6d63ec8
Added build-harness right way
goruha Jan 19, 2017
b051ff1
Added build-harness right way
goruha Jan 19, 2017
9ab029b
Added build-harness right way
goruha Jan 19, 2017
30d1199
Added build-harness right way
goruha Jan 19, 2017
723c774
Added build-harness right way
goruha Jan 19, 2017
f469ad7
Added build-harness right way
goruha Jan 19, 2017
748f4e6
Added build-harness right way
goruha Jan 19, 2017
fa53452
Added build-harness right way
goruha Jan 19, 2017
58168ca
Added build-harness right way
goruha Jan 19, 2017
22870d5
Added build-harness right way
goruha Jan 19, 2017
206b76a
Added build-harness right way
goruha Jan 19, 2017
abe45c0
Merge for PR
goruha Jan 19, 2017
1f327ca
Merge branch 'initial'
goruha Jan 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Override for Makefile
[{Makefile, makefile, GNUmakefile}]
indent_style = tab
indent_size = 4

[Makefile.*]
indent_style = tab
indent_size = 4
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include $(BUILD_HARNESS_PATH)/Makefile.*

include $(BUILD_HARNESS_PATH)/modules/*/*
41 changes: 41 additions & 0 deletions Makefile.helpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Helpers - stuff that's shared between make files
#

EDITOR ?= vim

SHELL = /bin/bash

green = $(shell echo -e '\x1b[32;01m$1\x1b[0m')
yellow = $(shell echo -e '\x1b[33;01m$1\x1b[0m')
red = $(shell echo -e '\x1b[33;31m$1\x1b[0m')


# Ensures that a variable is defined
define assert-set
@[ -n "$$$1" ] || (echo "$(1) not defined in $(@)"; exit 1)
endef

# Ensures that a variable is undefined
define assert-unset
@[ -z "$$$1" ] || (echo "$(1) should not be defined in $(@)"; exit 1)
endef

default: help

.PHONY : help
## This help screen
help:
@printf "Available targets:\n\n"
@awk '/^[a-zA-Z\-\_0-9%:\\]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
gsub("\\\\", "", helpCommand); \
gsub(":+$$", "", helpCommand); \
printf " \x1b[32;01m%-35s\x1b[0m %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST) | sort -u
@printf "\n"
56 changes: 56 additions & 0 deletions bin/github_download_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
#
# gh-dl-release! It works!
#
# Source https://gist.github.com/maxim/6e15aa45ba010ab030c4
#
# This script downloads an asset from latest or specific Github release of a
# private repo. Feel free to extract more of the variables into command line
# parameters.
#
# PREREQUISITES
#
# curl, wget, jq
#
# USAGE
#
# Set all the variables inside the script, make sure you chmod +x it, then
# to download specific version to my_app.tar.gz:
#
# gh-dl-release 2.1.1 my_app.tar.gz
#
# to download latest version:
#
# gh-dl-release latest latest.tar.gz
#
# If your version/tag doesn't match, the script will exit with error.

#GITHUB_TOKEN="<github_access_token>"
#REPO="<user_or_org>/<repo_name>"
#FILE="<name_of_asset_file>" # the name of your release asset file, e.g. build.tar.gz
VERSION=$1 # tag name or the word "latest"
GITHUB="https://api.github.com"

alias errcho='>&2 echo'

function gh_curl() {
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3.raw" \
$@
}

if [ "$VERSION" = "latest" ]; then
# Github should return the latest release first.
parser=".[0].assets | map(select(.name == \"$FILE\"))[0].id"
else
parser=". | map(select(.tag_name == \"$VERSION\"))[0].assets | map(select(.name == \"$FILE\"))[0].id"
fi;

asset_id=`gh_curl -s $GITHUB/repos/$REPO/releases | jq "$parser"`
if [ "$asset_id" = "null" ]; then
echo "ERROR: version not found $VERSION"
exit 1
fi;

curl -H 'Accept:application/octet-stream' -o $2 -L \
https://$GITHUB_TOKEN:@api.github.com/repos/$REPO/releases/assets/$asset_id
11 changes: 11 additions & 0 deletions bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
export BUILD_HARNESS_PROJECT=${2:-build-harness}
export BUILD_HARNESS_BRANCH=${3:-master}
export GITHUB_REPO="https://github.com/cloudposse/${BUILD_HARNESS_PROJECT}.git"

if [ "$BUILD_HARNESS_PROJECT" ] && [ -d "$BUILD_HARNESS_PROJECT" ]; then
echo "Removing existing $BUILD_HARNESS_PROJECT"
rm -rf "$BUILD_HARNESS_PROJECT"
fi

git clone -b $BUILD_HARNESS_BRANCH $GITHUB_REPO
30 changes: 30 additions & 0 deletions bin/travis_docker_tag_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

DOCKER_TAGS=($TRAVIS_COMMIT)

if [ ! -z "$TRAVIS_TAG" ]; then
DOCKER_TAGS+=($TRAVIS_TAG)
fi

if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then
DOCKER_TAGS+=(pr-$TRAVIS_PULL_REQUEST_BRANCH)
DOCKER_TAGS+=(pr-$TRAVIS_PULL_REQUEST_BRANCH-$TRAVIS_BUILD_NUMBER)
fi

if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" && ! -z "$TRAVIS_BRANCH" ]]; then
DOCKER_TAGS+=($TRAVIS_BRANCH)
DOCKER_TAGS+=($TRAVIS_BRANCH-$TRAVIS_BUILD_NUMBER)
fi

if [[ -z "$TRAVIS_TAG" && -z "$TRAVIS_PULL_REQUEST_BRANCH" && -z "$TRAVIS_BRANCH" ]]; then
DOCKER_TAGS+=(latest)
fi

if [[ -z "$TRAVIS_PULL_REQUEST_BRANCH" ]] && [[ "$TRAVIS_BRANCH" == "master" ]]; then
DOCKER_TAGS+=(latest)
fi


for TAG in "${DOCKER_TAGS[@]}"; do
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$TAG && docker push $DOCKER_IMAGE_NAME:$TAG;
done
1 change: 1 addition & 0 deletions modules/docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCKER:= $(shell which docker)
12 changes: 12 additions & 0 deletions modules/docker/Makefile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: docker\:build
## Use DOCKER_IMAGE_NAME envvar to specify docker image with tags
## Build docker image
docker\:build: $(DOCKER)
$(DOCKER) build --no-cache -t $(DOCKER_IMAGE_NAME) .

.PHONY: docker\:build-with-args
## Use DOCKER_IMAGE_NAME envvar to specify docker image with tags
## User ARGS to pass arguments
## Build docker image with args
docker\:build-with-args: $(DOCKER)
@$(DOCKER) build --no-cache --build-arg $(ARGS) -t $(DOCKER_IMAGE_NAME) .
5 changes: 5 additions & 0 deletions modules/docker/Makefile.hub
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: docker\:login
## Use DOCKER_HUB_USERNAME and DOCKER_HUB_PASSWORD env variables to pass credentials
## Login into docker hub
docker\:login: $(DOCKER)
@$(DOCKER) login --username="$(DOCKER_HUB_USERNAME)" --password="$(DOCKER_HUB_PASSWORD)"
22 changes: 22 additions & 0 deletions modules/docs/Makefile.copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
COPYRIGHT_CMD ?= docker run --rm --volume `pwd`:$(COPYRIGHT_OUTPUT_DIR) osterman/copyright-header:latest
COPYRIGHT_LICENSE ?= ASL2
COPYRIGHT_HOLDER ?= Cloud Posse, LLC <hello@cloudposse.com>
COPYRIGHT_YEAR ?= $(shell date +%Y)
COPYRIGHT_SOFTWARE ?= Example App
COPYRIGHT_SOFTWARE_DESCRIPTION ?= Example Software Description
COPYRIGHT_OUTPUT_DIR ?= /usr/src
COPYRIGHT_WORD_WRAP ?= 100

.PHONY : docs\:copyright-add
## Add copyright to source code
docs\:copyright-add:
$(COPYRIGHT_CMD) \
--license $(COPYRIGHT_LICENSE) \
--add-path cmd:main.go \
--guess-extension \
--copyright-holder '$(COPYRIGHT_HOLDER)' \
--copyright-software '$(COPYRIGHT_SOFTWARE)' \
--copyright-software-description '$(COPYRIGHT_SOFTWARE_DESCRIPTION)' \
--copyright-year $(COPYRIGHT_YEAR) \
--word-wrap $(COPYRIGHT_WORD_WRAP) \
--output-dir $(COPYRIGHT_OUTPUT_DIR)
4 changes: 4 additions & 0 deletions modules/docs/Makefile.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY : docs\:toc-update
## Update table of contents in README.md
docs\:toc-update:
@doctoc --notitle --github README.md
7 changes: 7 additions & 0 deletions modules/github/Makefile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: github\:download-release
## GITHUB_TOKEN="<github_access_token>"
## REPO="<user_or_org>/<repo_name>"
## FILE="<name_of_asset_file>" # the name of your release asset file, e.g. build.tar.gz
## Download release from github
github\:download-release:
$(BUILD_HARNESS_PATH)/bin/github_download_release.sh $(VERSION) $(OUTPUT)
1 change: 1 addition & 0 deletions modules/go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GO:= $(shell which go)
48 changes: 48 additions & 0 deletions modules/go/Makefile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
GLIDE := $(shell which glide)
INSTALL_DIR ?= /usr/local/sbin
RELEASE_DIR ?= release
APP?=Example App

.PHONY: go\:build
## Build binary
go\:build: $(GO)
$(GO) build -o $(RELEASE_DIR)/$(APP)

.PHONY: go\:build-all
## Build binary for all platforms
go\:build-all: $(GO)
gox -output "${RELEASE_DIR}/${APP}_{{.OS}}_{{.Arch}}"

.PHONY: go\:deps
## Install dependencies
go\:deps: $(GLIDE)
$(GLIDE) install --strip-vendor
$(GLIDE) update --strip-vendor

.PHONY: go\:deps-build
## Install dependencies for build
go\:deps-build:
mkdir -p $(GOPATH)/bin
which $(GLIDE) || (curl https://glide.sh/get | sh)

.PHONY: deps-dev
## Install development dependencies
go\:deps-dev: $(GO)
$(GO) get -d -v "github.com/golang/lint"
$(GO) install -v "github.com/golang/lint/golint"
$(GO) get -d -v github.com/mitchellh/gox
$(GO) install -v github.com/mitchellh/gox

## Clean compiled binary
go\:clean:
rm -rf $(RELEASE_DIR)

## Clean compiled binary and dependency
go\:clean-all: go\:clean
rm -rf vendor
rm -rf glide.lock

## Install cli
go\:install: $(APP) go\:build
cp $(RELEASE_DIR)/$(APP) $(INSTALL_DIR)
chmod 555 $(INSTALL_DIR)/$(APP)
14 changes: 14 additions & 0 deletions modules/go/Makefile.style
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: go\:lint
## Lint code
go\:lint: $(GO) go\:vet
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 golint

.PHONY: go\:vet
## Vet code
go\:vet: $(GO)
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 $(GO) vet -v

.PHONY: go\:fmt
## Format code according to Golang convention
go\:fmt: $(GO)
find . ! -path "*/vendor/*" ! -path "*/.glide/*" -type f -name '*.go' | xargs -n 1 gofmt -w -l -s
4 changes: 4 additions & 0 deletions modules/go/Makefile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: go\:test
## Run tests
go\:test: $(GO)
$(GO) test $(shell $(GO) list . | grep -v /vendor/)
4 changes: 4 additions & 0 deletions modules/travis/Makefile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: travis\:docker-tag-and-push
## Tag according travis envvars and push
travis\:docker-tag-and-push:
$(BUILD_HARNESS_PATH)/bin/travis_docker_tag_and_push.sh
8 changes: 8 additions & 0 deletions templates/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Override for Makefile
[{Makefile, makefile, GNUmakefile}]
indent_style = tab
indent_size = 4

[Makefile.*]
indent_style = tab
indent_size = 4
17 changes: 17 additions & 0 deletions templates/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SHELL = /bin/bash
export BUILD_HARNESS_PATH ?= $(shell until [ -d "build-harness" ] || [ "`pwd`" == '/' ]; do cd ..; done; pwd)/build-harness
-include $(BUILD_HARNESS_PATH)/Makefile

####################### If go app ####################################################
override APP:=Example App
######################################################################################

.PHONY : init
## Init build-harness
init:
@curl --retry 5 --retry-delay 1 https://raw.githubusercontent.com/cloudposse/build-harness/master/bin/install.sh | bash

.PHONY : clean
## Clean build-harness
clean:
rm -rf $(BUILD_HARNESS_PATH)
20 changes: 20 additions & 0 deletions templates/docker.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sudo: required
addons:
apt:
packages:
- git
- make
- curl
env:
- DOCKER_IMAGE_NAME=cloudposse/#####################
services:
- docker
install:
- make init
- make docker:login

script:
- make docker:build

after_success:
- make travis:docker-tag-and-push
47 changes: 47 additions & 0 deletions templates/go.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
sudo: required
language: go
go:
- 1.7.x
addons:
apt:
packages:
- git
- make
- curl

env:
- APP=##################

install:
- make init
- make go:deps-build
- make go:deps-dev

script:
- make go:deps
- make go:test
- make go:lint
- make go:build-all

deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file:
- release/$APP_darwin_386
- release/$APP_darwin_amd64
- release/$APP_freebsd_386
- release/$APP_freebsd_amd64
- release/$APP_freebsd_arm
- release/$APP_linux_386
- release/$APP_linux_amd64
- release/$APP_linux_arm
- release/$APP_netbsd_386
- release/$APP_netbsd_amd64
- release/$APP_netbsd_arm
- release/$APP_openbsd_386
- release/$APP_openbsd_amd64
- release/$APP_windows_386.exe
- release/$APP_windows_amd64.exe
skip_cleanup: true
on:
tags: true