Skip to content

Commit

Permalink
add no-stash option, plus other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Feb 4, 2016
1 parent adc2853 commit 1cf0d34
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 63 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ CMD []
# Get gogo for golang protobuf
RUN go get github.com/gogo/protobuf/protoc-gen-gogo

# Initialize git, needed to stash changes before 'go get ./...'
RUN git config --global user.email "[email protected]"
RUN git config --global user.name "Docker Builder"

ADD ./build.py /usr/local/bin/build

55 changes: 36 additions & 19 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
DESCRIPTION = "Time series data processing engine"

# SCRIPT START
go_vet_command = ["go", "tool", "vet", "-composites=false", "./"]
prereqs = [ 'git', 'go' ]
optional_prereqs = [ 'fpm', 'rpmbuild' ]

Expand Down Expand Up @@ -79,8 +80,8 @@
}

supported_builds = {
'darwin': [ "amd64" ],
'linux': [ "amd64" ]
'darwin': [ "amd64", "i386" ],
'linux': [ "amd64", "i386", "arm"]
}

supported_packages = {
Expand Down Expand Up @@ -324,7 +325,7 @@ def run_tests(race, parallel, timeout, no_vet):
print err
return False
if not no_vet:
p = subprocess.Popen(["go", "tool", "vet", "-composites=true", "./"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(go_vet_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if len(out) > 0 or len(err) > 0:
print "Go vet failed. Please run 'go vet ./...' and fix any errors."
Expand Down Expand Up @@ -394,7 +395,7 @@ def build(version=None,
arch = '386'
elif arch == 'x86_64':
arch = 'amd64'

print "Starting build..."
tmp_build_dir = create_temp_dir()
for b, c in targets.iteritems():
Expand Down Expand Up @@ -447,16 +448,21 @@ def copy_file(fr, to):
except OSError as e:
print e

def go_get(branch, update=False):
def go_get(branch, update=False, no_stash=False):
get_command = None
if update:
get_command = "go get -u -f -d ./..."
else:
get_command = "go get -d ./..."

# 'go get' switches to master, so stash what we currently have
stash = run("git stash create -a").strip()
if len(stash) > 0:
changes = run("git status --porcelain").strip()
if len(changes) > 0:
if no_stash:
print "There are un-committed changes in your local branch, --no-stash was given, cannot continue"
return False

stash = run("git stash create -a").strip()
print "There are un-committed changes in your local branch, stashing them as {}".format(stash)
# reset to ensure we don't have any checkout issues
run("git reset --hard")
Expand All @@ -467,7 +473,7 @@ def go_get(branch, update=False):

print "Moving back to branch '{}'...".format(branch)
run("git checkout {}".format(branch))

print "Applying previously stashed contents..."
run("git stash apply {}".format(stash))
else:
Expand All @@ -476,7 +482,9 @@ def go_get(branch, update=False):

print "Moving back to branch '{}'...".format(branch)
run("git checkout {}".format(branch))


return True

def generate_md5_from_file(path):
m = hashlib.md5()
with open(path, 'rb') as f:
Expand All @@ -499,7 +507,7 @@ def build_packages(build_output, version, pkg_arch, nightly=False, rc=None, iter
for a in build_output[p]:
current_location = build_output[p][a]
# Create second-level directory displaying the architecture (amd64, etc)
build_root = os.path.join(tmp_build_dir, p, a, 'influxdb-{}-{}'.format(version, iteration))
build_root = os.path.join(tmp_build_dir, p, a, '{}-{}-{}'.format(PACKAGE_NAME, version, iteration))
# Create directory tree to mimic file system of package
create_dir(build_root)
create_package_fs(build_root)
Expand Down Expand Up @@ -531,20 +539,20 @@ def build_packages(build_output, version, pkg_arch, nightly=False, rc=None, iter
name = '{}-nightly_{}_{}'.format(name, p, a)
else:
name = '{}-{}-{}_{}_{}'.format(name, package_version, package_iteration, p, a)

if package_type == 'tar':
# Add `tar.gz` to path to ensure a small package size
current_location = os.path.join(current_location, name + '.tar.gz')
elif package_type == 'zip':
current_location = os.path.join(current_location, name + '.zip')

if rc is not None:
package_iteration = "0.rc{}".format(rc)
if pkg_arch is not None:
a = pkg_arch
if a == '386':
a = 'i386'

fpm_command = "fpm {} --name {} -a {} -t {} --version {} --iteration {} -C {} -p {} ".format(
fpm_common_args,
name,
Expand Down Expand Up @@ -613,7 +621,7 @@ def print_package_summary(packages):

def main():
global debug

# Command-line arguments
outdir = "build"
commit = None
Expand All @@ -638,7 +646,8 @@ def main():
run_get = True
upload_bucket = None
generate = False

no_stash = False

for arg in sys.argv[1:]:
if '--outdir' in arg:
# Output directory. If none is specified, then builds will be placed in the same directory.
Expand Down Expand Up @@ -670,6 +679,8 @@ def main():
elif '--package' in arg:
# Signifies that packages should be built.
package = True
# If packaging do not allow stashing of local changes
no_stash = True
elif '--nightly' in arg:
# Signifies that this is a nightly build.
nightly = True
Expand Down Expand Up @@ -706,6 +717,10 @@ def main():
elif '--bucket' in arg:
# The bucket to upload the packages to, relies on boto
upload_bucket = arg.split("=")[1]
elif '--no-stash' in arg:
# Do not stash uncommited changes
# Fail if uncommited changes exist
no_stash = True
elif '--generate' in arg:
# Run go generate ./...
# TODO - this currently does nothing for InfluxDB
Expand All @@ -728,7 +743,7 @@ def main():
# Pre-build checks
check_environ()
check_prereqs()

if not commit:
commit = get_current_commit(short=True)
if not branch:
Expand All @@ -750,20 +765,22 @@ def main():
target_arch = 'i386'
elif target_arch == 'x86_64':
target_arch = 'amd64'

build_output = {}

if generate:
if not run_generate():
return 1

if test:
if not run_tests(race, parallel, timeout, no_vet):
return 1
return 0

if run_get:
go_get(branch, update=update)
if not go_get(branch, update=update, no_stash=no_stash):
print "!! Cannot continue: go get failed"
return 1

platforms = []
single_build = True
Expand Down
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ dependencies:

test:
override:
- ./build.sh --test --generate --no-vet
- ./build.sh --test --generate --race --no-vet
- ./build.sh --test --generate --no-stash
- ./build.sh --test --generate --no-stash --race


deployment:
release:
tag: /v[0-9]+(\.[0-9]+){2}(-rc[0-9]+)?/
commands:
- ./build.sh --clean --generate --packages --upload --platform=all --arch=all
- ./build.sh --clean --generate --package --upload --platform=all --arch=all
Loading

0 comments on commit 1cf0d34

Please sign in to comment.