Merge pull request #1157 from influxdata/ross-build-updates
Minor fixes to build script
This commit is contained in:
commit
36b9e2e077
|
@ -132,13 +132,16 @@ def create_package_fs(build_root):
|
||||||
os.makedirs(os.path.join(build_root, d))
|
os.makedirs(os.path.join(build_root, d))
|
||||||
os.chmod(os.path.join(build_root, d), 0o755)
|
os.chmod(os.path.join(build_root, d), 0o755)
|
||||||
|
|
||||||
def package_scripts(build_root, windows=False):
|
def package_scripts(build_root, config_only=False, windows=False):
|
||||||
"""Copy the necessary scripts and configuration files to the package
|
"""Copy the necessary scripts and configuration files to the package
|
||||||
filesystem.
|
filesystem.
|
||||||
"""
|
"""
|
||||||
if windows:
|
if config_only or windows:
|
||||||
logging.info("Copying configuration to build directory.")
|
logging.info("Copying configuration to build directory")
|
||||||
shutil.copyfile(DEFAULT_WINDOWS_CONFIG, os.path.join(build_root, "telegraf.conf"))
|
if windows:
|
||||||
|
shutil.copyfile(DEFAULT_WINDOWS_CONFIG, os.path.join(build_root, "telegraf.conf"))
|
||||||
|
else:
|
||||||
|
shutil.copyfile(DEFAULT_CONFIG, os.path.join(build_root, "telegraf.conf"))
|
||||||
os.chmod(os.path.join(build_root, "telegraf.conf"), 0o644)
|
os.chmod(os.path.join(build_root, "telegraf.conf"), 0o644)
|
||||||
else:
|
else:
|
||||||
logging.info("Copying scripts and configuration to build directory")
|
logging.info("Copying scripts and configuration to build directory")
|
||||||
|
@ -239,21 +242,15 @@ def get_current_version():
|
||||||
"""Parse version information from git tag output.
|
"""Parse version information from git tag output.
|
||||||
"""
|
"""
|
||||||
version_tag = get_current_version_tag()
|
version_tag = get_current_version_tag()
|
||||||
# Remove leading 'v' and possible '-rc\d+'
|
# Remove leading 'v'
|
||||||
if version_tag[0] == 'v':
|
if version_tag[0] == 'v':
|
||||||
version_tag = version_tag[1:]
|
version_tag = version_tag[1:]
|
||||||
version = re.sub(r'-rc\d+', '', str(version_tag))
|
# Replace any '-'/'_' with '~'
|
||||||
return version
|
if '-' in version_tag:
|
||||||
|
version_tag = version_tag.replace("-","~")
|
||||||
def get_current_rc():
|
if '_' in version_tag:
|
||||||
"""Parse release candidate from git tag output.
|
version_tag = version_tag.replace("_","~")
|
||||||
"""
|
return version_tag
|
||||||
rc = None
|
|
||||||
version_tag = get_current_version_tag()
|
|
||||||
matches = re.match(r'.*-rc(\d+)', str(version_tag))
|
|
||||||
if matches:
|
|
||||||
rc, = matches.groups(1)
|
|
||||||
return rc
|
|
||||||
|
|
||||||
def get_current_commit(short=False):
|
def get_current_commit(short=False):
|
||||||
"""Retrieve the current git commit.
|
"""Retrieve the current git commit.
|
||||||
|
@ -418,7 +415,6 @@ def build(version=None,
|
||||||
platform=None,
|
platform=None,
|
||||||
arch=None,
|
arch=None,
|
||||||
nightly=False,
|
nightly=False,
|
||||||
rc=None,
|
|
||||||
race=False,
|
race=False,
|
||||||
clean=False,
|
clean=False,
|
||||||
outdir=".",
|
outdir=".",
|
||||||
|
@ -445,9 +441,6 @@ def build(version=None,
|
||||||
shutil.rmtree(outdir)
|
shutil.rmtree(outdir)
|
||||||
os.makedirs(outdir)
|
os.makedirs(outdir)
|
||||||
|
|
||||||
if rc:
|
|
||||||
# If a release candidate, update the version information accordingly
|
|
||||||
version = "{}rc{}".format(version, rc)
|
|
||||||
logging.info("Using version '{}' for build.".format(version))
|
logging.info("Using version '{}' for build.".format(version))
|
||||||
|
|
||||||
tmp_build_dir = create_temp_dir()
|
tmp_build_dir = create_temp_dir()
|
||||||
|
@ -540,7 +533,7 @@ def generate_sig_from_file(path):
|
||||||
run('gpg --armor --detach-sign --yes {}'.format(path))
|
run('gpg --armor --detach-sign --yes {}'.format(path))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def package(build_output, version, nightly=False, rc=None, iteration=1, static=False, release=False):
|
def package(build_output, pkg_name, version, nightly=False, iteration=1, static=False, release=False):
|
||||||
"""Package the output of the build process.
|
"""Package the output of the build process.
|
||||||
"""
|
"""
|
||||||
outfiles = []
|
outfiles = []
|
||||||
|
@ -564,10 +557,12 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
os.makedirs(build_root)
|
os.makedirs(build_root)
|
||||||
|
|
||||||
# Copy packaging scripts to build directory
|
# Copy packaging scripts to build directory
|
||||||
if platform == "windows" or static or "static_" in arch:
|
if platform == "windows":
|
||||||
# For windows and static builds, just copy
|
# For windows and static builds, just copy
|
||||||
# binaries to root of package (no other scripts or
|
# binaries to root of package (no other scripts or
|
||||||
# directories)
|
# directories)
|
||||||
|
package_scripts(build_root, config_only=True, windows=True)
|
||||||
|
elif static or "static_" in arch:
|
||||||
package_scripts(build_root, config_only=True)
|
package_scripts(build_root, config_only=True)
|
||||||
else:
|
else:
|
||||||
create_package_fs(build_root)
|
create_package_fs(build_root)
|
||||||
|
@ -592,7 +587,7 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
for package_type in supported_packages[platform]:
|
for package_type in supported_packages[platform]:
|
||||||
# Package the directory structure for each package type for the platform
|
# Package the directory structure for each package type for the platform
|
||||||
logging.debug("Packaging directory '{}' as '{}'.".format(build_root, package_type))
|
logging.debug("Packaging directory '{}' as '{}'.".format(build_root, package_type))
|
||||||
name = PACKAGE_NAME
|
name = pkg_name
|
||||||
# Reset version, iteration, and current location on each run
|
# Reset version, iteration, and current location on each run
|
||||||
# since they may be modified below.
|
# since they may be modified below.
|
||||||
package_version = version
|
package_version = version
|
||||||
|
@ -604,17 +599,12 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
package_arch = arch
|
package_arch = arch
|
||||||
if not release and not nightly:
|
if not release and not nightly:
|
||||||
# For non-release builds, just use the commit hash as the version
|
# For non-release builds, just use the commit hash as the version
|
||||||
package_version = "{}~{}.{}".format(version,
|
package_version = "{}~{}".format(version,
|
||||||
get_current_branch(),
|
get_current_commit(short=True))
|
||||||
get_current_commit(short=True))
|
|
||||||
package_iteration = "0"
|
package_iteration = "0"
|
||||||
package_build_root = build_root
|
package_build_root = build_root
|
||||||
current_location = build_output[platform][arch]
|
current_location = build_output[platform][arch]
|
||||||
|
|
||||||
if rc is not None and release:
|
|
||||||
# Set iteration to 0 since it's a release candidate
|
|
||||||
package_iteration = "0.rc{}".format(rc)
|
|
||||||
|
|
||||||
if package_type in ['zip', 'tar']:
|
if package_type in ['zip', 'tar']:
|
||||||
# For tars and zips, start the packaging one folder above
|
# For tars and zips, start the packaging one folder above
|
||||||
# the build root (to include the package name)
|
# the build root (to include the package name)
|
||||||
|
@ -639,18 +629,17 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
package_version,
|
package_version,
|
||||||
platform,
|
platform,
|
||||||
package_arch)
|
package_arch)
|
||||||
|
|
||||||
current_location = os.path.join(os.getcwd(), current_location)
|
current_location = os.path.join(os.getcwd(), current_location)
|
||||||
if package_type == 'tar':
|
if package_type == 'tar':
|
||||||
tar_command = "cd {} && tar -cvzf {}.tar.gz ./*".format(build_root, name)
|
tar_command = "cd {} && tar -cvzf {}.tar.gz ./*".format(package_build_root, name)
|
||||||
run(tar_command, shell=True)
|
run(tar_command, shell=True)
|
||||||
run("mv {}.tar.gz {}".format(os.path.join(build_root, name), current_location), shell=True)
|
run("mv {}.tar.gz {}".format(os.path.join(package_build_root, name), current_location), shell=True)
|
||||||
outfile = os.path.join(current_location, name + ".tar.gz")
|
outfile = os.path.join(current_location, name + ".tar.gz")
|
||||||
outfiles.append(outfile)
|
outfiles.append(outfile)
|
||||||
elif package_type == 'zip':
|
elif package_type == 'zip':
|
||||||
zip_command = "cd {} && zip -r {}.zip ./*".format(build_root, name)
|
zip_command = "cd {} && zip -r {}.zip ./*".format(package_build_root, name)
|
||||||
run(zip_command, shell=True)
|
run(zip_command, shell=True)
|
||||||
run("mv {}.zip {}".format(os.path.join(build_root, name), current_location), shell=True)
|
run("mv {}.zip {}".format(os.path.join(package_build_root, name), current_location), shell=True)
|
||||||
outfile = os.path.join(current_location, name + ".zip")
|
outfile = os.path.join(current_location, name + ".zip")
|
||||||
outfiles.append(outfile)
|
outfiles.append(outfile)
|
||||||
elif package_type not in ['zip', 'tar'] and static or "static_" in arch:
|
elif package_type not in ['zip', 'tar'] and static or "static_" in arch:
|
||||||
|
@ -681,7 +670,6 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
os.rename(outfile, new_outfile)
|
os.rename(outfile, new_outfile)
|
||||||
outfile = new_outfile
|
outfile = new_outfile
|
||||||
else:
|
else:
|
||||||
# Strip iteration from package name
|
|
||||||
if package_type == 'rpm':
|
if package_type == 'rpm':
|
||||||
# rpm's convert any dashes to underscores
|
# rpm's convert any dashes to underscores
|
||||||
package_version = package_version.replace("-", "_")
|
package_version = package_version.replace("-", "_")
|
||||||
|
@ -698,9 +686,6 @@ def package(build_output, version, nightly=False, rc=None, iteration=1, static=F
|
||||||
def main(args):
|
def main(args):
|
||||||
global PACKAGE_NAME
|
global PACKAGE_NAME
|
||||||
|
|
||||||
if args.nightly and args.rc:
|
|
||||||
logging.error("Cannot be both a nightly and a release candidate.")
|
|
||||||
return 1
|
|
||||||
if args.release and args.nightly:
|
if args.release and args.nightly:
|
||||||
logging.error("Cannot be both a nightly and a release.")
|
logging.error("Cannot be both a nightly and a release.")
|
||||||
return 1
|
return 1
|
||||||
|
@ -710,8 +695,6 @@ def main(args):
|
||||||
args.version = "{}~n{}".format(args.version,
|
args.version = "{}~n{}".format(args.version,
|
||||||
datetime.utcnow().strftime("%Y%m%d%H%M"))
|
datetime.utcnow().strftime("%Y%m%d%H%M"))
|
||||||
args.iteration = 0
|
args.iteration = 0
|
||||||
elif args.rc:
|
|
||||||
args.iteration = 0
|
|
||||||
|
|
||||||
# Pre-build checks
|
# Pre-build checks
|
||||||
check_environ()
|
check_environ()
|
||||||
|
@ -778,7 +761,6 @@ def main(args):
|
||||||
platform=platform,
|
platform=platform,
|
||||||
arch=arch,
|
arch=arch,
|
||||||
nightly=args.nightly,
|
nightly=args.nightly,
|
||||||
rc=args.rc,
|
|
||||||
race=args.race,
|
race=args.race,
|
||||||
clean=args.clean,
|
clean=args.clean,
|
||||||
outdir=od,
|
outdir=od,
|
||||||
|
@ -793,9 +775,9 @@ def main(args):
|
||||||
logging.error("FPM ruby gem required for packaging. Stopping.")
|
logging.error("FPM ruby gem required for packaging. Stopping.")
|
||||||
return 1
|
return 1
|
||||||
packages = package(build_output,
|
packages = package(build_output,
|
||||||
|
args.name,
|
||||||
args.version,
|
args.version,
|
||||||
nightly=args.nightly,
|
nightly=args.nightly,
|
||||||
rc=args.rc,
|
|
||||||
iteration=args.iteration,
|
iteration=args.iteration,
|
||||||
static=args.static,
|
static=args.static,
|
||||||
release=args.release)
|
release=args.release)
|
||||||
|
@ -844,6 +826,7 @@ if __name__ == '__main__':
|
||||||
help='Output directory')
|
help='Output directory')
|
||||||
parser.add_argument('--name', '-n',
|
parser.add_argument('--name', '-n',
|
||||||
metavar='<name>',
|
metavar='<name>',
|
||||||
|
default=PACKAGE_NAME,
|
||||||
type=str,
|
type=str,
|
||||||
help='Name to use for package name (when package is specified)')
|
help='Name to use for package name (when package is specified)')
|
||||||
parser.add_argument('--arch',
|
parser.add_argument('--arch',
|
||||||
|
@ -871,14 +854,10 @@ if __name__ == '__main__':
|
||||||
type=str,
|
type=str,
|
||||||
default=get_current_version(),
|
default=get_current_version(),
|
||||||
help='Version information to apply to build output (ex: 0.12.0)')
|
help='Version information to apply to build output (ex: 0.12.0)')
|
||||||
parser.add_argument('--rc',
|
|
||||||
metavar='<release candidate>',
|
|
||||||
type=int,
|
|
||||||
help='Release Candidate (RC) version to apply to build output')
|
|
||||||
parser.add_argument('--iteration',
|
parser.add_argument('--iteration',
|
||||||
metavar='<package iteration>',
|
metavar='<package iteration>',
|
||||||
type=int,
|
type=str,
|
||||||
default=1,
|
default="1",
|
||||||
help='Package iteration to apply to build output (defaults to 1)')
|
help='Package iteration to apply to build output (defaults to 1)')
|
||||||
parser.add_argument('--stats',
|
parser.add_argument('--stats',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|
Loading…
Reference in New Issue