From cddc611ae3a6da15aaa2bded568209bb3eca27de Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 26 Jan 2016 16:10:52 -0500 Subject: Add a build step for generating version files. --- scripts/make-version-file | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 scripts/make-version-file (limited to 'scripts/make-version-file') diff --git a/scripts/make-version-file b/scripts/make-version-file new file mode 100755 index 00000000..fcc399f8 --- /dev/null +++ b/scripts/make-version-file @@ -0,0 +1,66 @@ +#!/usr/bin/python +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# File: make-version-file +# Purpose: +# Creates version file in live-build chroot includes dir +# that is included in the image and used by 'show version' command +# and install/upgrade scripts. + +from __future__ import print_function +import os +import datetime +import json +import uuid + +import defaults +import util + +util.check_build_config() +with open(defaults.BUILD_CONFIG, 'r') as f: + build_config = json.load(f) + + +now = datetime.datetime.today() + +build_timestamp = now.strftime("%Y%m%d%H%M") + +# FIXME: use aware rather than naive object +build_date = now.strftime("%a %d %b %Y %H:%M UTC") + +# Assign a (hopefully) unique identifier to the build (UUID) +build_id = str(uuid.uuid4()) + +if build_config['build_type'] == 'development': + version = "999.{0}".format(build_timestamp) +else: + version = build_config['version'] + +version_data = { + 'version': version, + 'built_by': build_config['build_by'], + 'built_on': build_date, + 'build_id': build_id +} + + +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version.json'), 'w') as f: + json.dump(version_data, f) + +# For backwards compatibility with 'add system image' script from older versions +# we need a file in old format so that script can find out the version of the image +# for upgrade +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version'), 'w') as f: + print("Version: {0}".format(version), file=f) -- cgit v1.2.3 From 6a7696a1122560073c3121fdecb5e3bd0c6549cf Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 3 Mar 2016 18:28:31 -0500 Subject: After build, create a properly named symlink to the ISO (ref T8). This is important for nightly builds, and handy for release builds. --- Makefile | 4 +++- scripts/make-version-file | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts/make-version-file') diff --git a/Makefile b/Makefile index 38448f39..0a0cb2dd 100644 --- a/Makefile +++ b/Makefile @@ -23,11 +23,12 @@ prepare: .PHONY: iso .ONESHELL: -iso: prepare +iso: clean prepare @set -e @echo "It's not like I'm building this specially for you or anything!" cd $(build_dir) lb build 2>&1 | tee build.log + ln -nsf live-image-amd64.hybrid.iso vyos-`cat version`-`dpkg --print-architecture`.iso .PHONY: prepare-package-env .ONESHELL: @@ -45,6 +46,7 @@ clean: rm -f config/binary config/bootstrap config/chroot config/common config/source rm -f build.log + rm -f vyos-*.iso .PHONY: purge purge: diff --git a/scripts/make-version-file b/scripts/make-version-file index fcc399f8..6c597090 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -64,3 +64,9 @@ with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version.jso # for upgrade with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version'), 'w') as f: print("Version: {0}".format(version), file=f) + +# Leaky abstraction: we want ISO file name include version number, +# but we probably don't want to have a separate build step just for this, +# neither we want to use lengthy paths in makefiles +with open(os.path.join(defaults.BUILD_DIR, 'version'), 'w') as f: + print(version, file=f) -- cgit v1.2.3 From ea48b7bd747df4ae5c8ee64c72cdc67e31ddcd5a Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 25 Jan 2017 17:01:16 -0500 Subject: Switch all build scripts to python3. Since we only support jessie as build host, and jessie knowingly does have python3 (although not by default), we don't really need to worry about being both 2 and 3 compatible. --- README.md | 2 +- scripts/build-config | 3 ++- scripts/check-build-env | 4 ++-- scripts/check-config | 2 +- scripts/check-vm-build-env | 2 +- scripts/live-build-config | 2 +- scripts/make-version-file | 4 ++-- scripts/pbuilder-setup | 3 +-- scripts/query-json | 5 +++-- 9 files changed, 14 insertions(+), 13 deletions(-) (limited to 'scripts/make-version-file') diff --git a/README.md b/README.md index 11edb5fb..0d6e53c2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ There are several directories with their own purpose: To build a VyOS image, you need a machine that runs Debian Jessie. Other build hosts are not supported. -Several packages are required for building the ISO and all packages, namely live-build, pbuilder, python-pystache and devscripts. +Several packages are required for building the ISO and all packages, namely python3, live-build, pbuilder, python3-pystache and devscripts. Individual packages may have other build dependencies. If some packages are missing, build scripts will tell you. ## Building the ISO image diff --git a/scripts/build-config b/scripts/build-config index d273717f..9ea92e1f 100755 --- a/scripts/build-config +++ b/scripts/build-config @@ -1,4 +1,5 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 +# # Copyright (C) 2015 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify diff --git a/scripts/check-build-env b/scripts/check-build-env index 6dcf885b..7f02c02a 100755 --- a/scripts/check-build-env +++ b/scripts/check-build-env @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # @@ -32,7 +32,7 @@ deps = { 'live-build', 'pbuilder', 'devscripts', - 'python-pystache' + 'python3-pystache' ], 'binaries': [] } diff --git a/scripts/check-config b/scripts/check-config index 55d5467a..d2236619 100755 --- a/scripts/check-config +++ b/scripts/check-config @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env index c32f2b13..8efab848 100755 --- a/scripts/check-vm-build-env +++ b/scripts/check-vm-build-env @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2016 VyOS maintainers and contributors # diff --git a/scripts/live-build-config b/scripts/live-build-config index cb9e84dc..2e2d4704 100755 --- a/scripts/live-build-config +++ b/scripts/live-build-config @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # diff --git a/scripts/make-version-file b/scripts/make-version-file index 6c597090..3bb33319 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 +# # Copyright (C) 2016 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify @@ -19,7 +20,6 @@ # that is included in the image and used by 'show version' command # and install/upgrade scripts. -from __future__ import print_function import os import datetime import json diff --git a/scripts/pbuilder-setup b/scripts/pbuilder-setup index fbd49a4f..a89348b8 100755 --- a/scripts/pbuilder-setup +++ b/scripts/pbuilder-setup @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (C) 2015 VyOS maintainers and contributors # @@ -50,4 +50,3 @@ result = os.system(pbuilder_create_command) if result > 0: print("pbuilder environment bootstrap failed") sys.exit(1) - diff --git a/scripts/query-json b/scripts/query-json index 23e64ef7..2f1ea32f 100755 --- a/scripts/query-json +++ b/scripts/query-json @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/python3 +# # Copyright (C) 2016 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify @@ -14,7 +15,7 @@ # along with this program. If not, see . # # File: query-config -# Purpose: Extracts field values a flat JSON file, +# Purpose: Extracts field values from a flat JSON file, # for use in languages that can't handle JSON easily, # (I'm looking at you, Bourne shell!) -- cgit v1.2.3 From d2e4f63f03ef5628ab94be34bf368e8c8458a2d0 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 5 Apr 2018 14:59:44 +0200 Subject: T596: use a more descriptive dev build version format. --- data/versions | 3 +++ scripts/check-build-env | 3 ++- scripts/make-version-file | 24 ++++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 data/versions (limited to 'scripts/make-version-file') diff --git a/data/versions b/data/versions new file mode 100644 index 00000000..3d0c2871 --- /dev/null +++ b/data/versions @@ -0,0 +1,3 @@ +{ + "current": "1.2.0" +} diff --git a/scripts/check-build-env b/scripts/check-build-env index 7f02c02a..7377be64 100755 --- a/scripts/check-build-env +++ b/scripts/check-build-env @@ -32,7 +32,8 @@ deps = { 'live-build', 'pbuilder', 'devscripts', - 'python3-pystache' + 'python3-pystache', + 'python3-git' ], 'binaries': [] } diff --git a/scripts/make-version-file b/scripts/make-version-file index 3bb33319..0459b8bf 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -1,6 +1,6 @@ #!/usr/bin/python3 # -# Copyright (C) 2016 VyOS maintainers and contributors +# Copyright (C) 2018 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -25,16 +25,18 @@ import datetime import json import uuid +import git + import defaults import util +# Load the build config util.check_build_config() with open(defaults.BUILD_CONFIG, 'r') as f: build_config = json.load(f) - +# Create a build timestamp now = datetime.datetime.today() - build_timestamp = now.strftime("%Y%m%d%H%M") # FIXME: use aware rather than naive object @@ -43,9 +45,23 @@ build_date = now.strftime("%a %d %b %Y %H:%M UTC") # Assign a (hopefully) unique identifier to the build (UUID) build_id = str(uuid.uuid4()) +# Create a build version if build_config['build_type'] == 'development': - version = "999.{0}".format(build_timestamp) + try: + # Load the branch to version mapping file + with open('data/versions') as f: + version_mapping = json.load(f) + + repo = git.Repo('.') + git_branch = repo.active_branch.name + branch_version = version_mapping[git_branch] + + version = "{0}-rolling+{1}".format(branch_version, build_timestamp) + except Exception as e: + print("Could not build a version string specific to git branch, falling back to default: {0}".format(str(e))) + version = "999.{0}".format(build_timestamp) else: + # Release build, use the version from ./configure arguments version = build_config['version'] version_data = { -- cgit v1.2.3 From 3af1486d488be0ce450b0f92fed3d45221bdac9f Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 6 Jun 2018 21:52:28 +0200 Subject: T596: replace + in new version format by - The new version scheme was introduced in commit d2e4f63f03 ("T596: use a more descriptive dev build version format.". It superseeded the old 999.something version numbers. New version numbers for rolling releases are in the form of vyos-1.2.0-rolling+201806062125-amd64.iso but the '+' sign will be replaced by '%2B' when e.g. downloading the file via http(s), this may be confusing. --- scripts/make-version-file | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'scripts/make-version-file') diff --git a/scripts/make-version-file b/scripts/make-version-file index 0459b8bf..bdf489d7 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -56,7 +56,7 @@ if build_config['build_type'] == 'development': git_branch = repo.active_branch.name branch_version = version_mapping[git_branch] - version = "{0}-rolling+{1}".format(branch_version, build_timestamp) + version = "{0}-rolling-{1}".format(branch_version, build_timestamp) except Exception as e: print("Could not build a version string specific to git branch, falling back to default: {0}".format(str(e))) version = "999.{0}".format(build_timestamp) @@ -71,7 +71,6 @@ version_data = { 'build_id': build_id } - with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version.json'), 'w') as f: json.dump(version_data, f) -- cgit v1.2.3 From 82d7ddb1b34e36fa399fd333efc716add8bf341a Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 8 Jun 2018 21:17:38 +0200 Subject: Move the version.json file used by newer code to /usr/share/vyos --- scripts/make-version-file | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'scripts/make-version-file') diff --git a/scripts/make-version-file b/scripts/make-version-file index bdf489d7..95574722 100755 --- a/scripts/make-version-file +++ b/scripts/make-version-file @@ -56,7 +56,7 @@ if build_config['build_type'] == 'development': git_branch = repo.active_branch.name branch_version = version_mapping[git_branch] - version = "{0}-rolling-{1}".format(branch_version, build_timestamp) + version = "{0}-rolling+{1}".format(branch_version, build_timestamp) except Exception as e: print("Could not build a version string specific to git branch, falling back to default: {0}".format(str(e))) version = "999.{0}".format(build_timestamp) @@ -71,7 +71,9 @@ version_data = { 'build_id': build_id } -with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'opt/vyatta/etc/version.json'), 'w') as f: + +os.makedirs(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'usr/share/vyos'), exist_ok=True) +with open(os.path.join(defaults.CHROOT_INCLUDES_DIR, 'usr/share/vyos/version.json'), 'w') as f: json.dump(version_data, f) # For backwards compatibility with 'add system image' script from older versions -- cgit v1.2.3