From 9532bc7405b4f4172935206fbd2e84d9269d1a0e Mon Sep 17 00:00:00 2001 From: Disassembler Date: Mon, 9 Dec 2019 21:41:04 +0100 Subject: [PATCH] Use repo.build.vm as local build host --- apk/vmmgr | 2 +- build/clean-all.sh | 5 +- build/etc/nginx/conf.d/repo.conf | 2 +- build/install-toolchain.sh | 5 +- build/usr/bin/lxcbuild | 102 +++++++++--------- doc/toolchain/vm-creation.md | 4 +- lxc-shared/alpine3.9/lxc/etc/apk/repositories | 2 +- vm/etc/apk/repositories | 2 +- 8 files changed, 63 insertions(+), 61 deletions(-) diff --git a/apk/vmmgr b/apk/vmmgr index ca10263..ad1bfc8 160000 --- a/apk/vmmgr +++ b/apk/vmmgr @@ -1 +1 @@ -Subproject commit ca10263696d9488ee384430b2e2a0bc55e877b77 +Subproject commit ad1bfc8860b84148794f26c437a42b932087495f diff --git a/build/clean-all.sh b/build/clean-all.sh index 95a8421..2918709 100755 --- a/build/clean-all.sh +++ b/build/clean-all.sh @@ -44,16 +44,13 @@ cat </etc/hosts 127.0.0.1 localhost ::1 localhost 172.17.0.1 host -172.17.0.1 repo.spotter.cz +172.17.0.1 repo.build.vm EOF # Reset vmmgr config export ADMINPWD=$(python3 -c "import json; f = open('/etc/vmmgr/config.json'); j = json.load(f); print(j['host']['adminpwd'])") envsubst /etc/vmmgr/config.json -# Reset lxcmgr config -echo '{"url":"https://repo.spotter.cz/lxc","user":"","pwd":""}' >/etc/lxcmgr/repo.json - # Clean locally installed LXC packages rm -rf /var/lib/lxcmgr/storage/* rm -rf /var/lib/lxcmgr/cache/apps/* diff --git a/build/etc/nginx/conf.d/repo.conf b/build/etc/nginx/conf.d/repo.conf index 1b91492..40e81ea 100644 --- a/build/etc/nginx/conf.d/repo.conf +++ b/build/etc/nginx/conf.d/repo.conf @@ -1,6 +1,6 @@ server { listen [::]:80; - server_name repo.spotter.cz; + server_name repo.build.vm; location / { root /srv/build; diff --git a/build/install-toolchain.sh b/build/install-toolchain.sh index 7bf2762..2e4390f 100755 --- a/build/install-toolchain.sh +++ b/build/install-toolchain.sh @@ -28,9 +28,12 @@ mkdir -p /srv/build/lxc/apps /srv/build/lxc/images # Prepare local APK repository cp etc/nginx/conf.d/apkrepo.conf /etc/nginx/conf.d/apkrepo.conf -echo "172.17.0.1 repo.spotter.cz" >>/etc/hosts +echo "172.17.0.1 repo.build.vm" >>/etc/hosts service nginx reload +# Change LXCMgr repository +echo '{"url":"http://repo.build.vm/lxc","user":"","pwd":""}' >/etc/lxcmgr/repo.json + # Supply abuild key # echo '/srv/build/repokey.rsa' | abuild-keygen diff --git a/build/usr/bin/lxcbuild b/build/usr/bin/lxcbuild index 06b00e1..114ca1f 100755 --- a/build/usr/bin/lxcbuild +++ b/build/usr/bin/lxcbuild @@ -8,19 +8,6 @@ from lxcbuild.app import App from lxcbuild.image import Image from lxcbuild.imagebuilder import BuildType -parser = argparse.ArgumentParser(description='VM application builder and packager') -group = parser.add_mutually_exclusive_group() -group.add_argument('-f', '--force', action='store_true', help='Force rebuild already built package') -group.add_argument('-s', '--scratch', action='store_true', help='Build container for testing purposes, i.e. without cleanup on failure and packaging') -group.add_argument('-r', '--remove-image', action='store_true', help='Delete image (including scratch) from build repository') -group.add_argument('-e', '--remove-app', action='store_true', help='Delete application from build repository') -parser.add_argument('buildarg', help='Either specific "lxcfile" or "meta" file or a directory containing at least one of them') - -if len(sys.argv) < 2: - parser.print_usage() - sys.exit(1) -args = parser.parse_args() - def build_and_pack_image(path, args): image = Image() if args.scratch: @@ -33,45 +20,60 @@ def pack_app(path): app = App() app.pack(path) -if args.remove_image: - image = Image() - image.name = args.buildarg - image.remove() -elif args.remove_app: - app = App() - app.name = args.buildarg - app.remove() -else: - buildpath = os.path.realpath(args.buildarg) - # If the buildpath is a file, determine type from filename - if os.path.isfile(buildpath): - basename = os.path.basename(buildpath) - if basename == 'lxcfile' or basename.endswith('.lxcfile'): - build_and_pack_image(buildpath, args) - # Compose files needs to be ignored when performing scratch builds - elif not args.scratch and basename == 'meta': - pack_app(buildpath) - else: - print('Unknown file {} given, expected "lxcfile"{}'.format(buildpath, '' if args.scratch else ' or "meta"')) - sys.exit(1) - # If the buildpath is a directory, build as much as possible, unless scratch build was requested, in which case don't build anything +def main(args): + if args.remove_image: + image = Image() + image.name = args.buildarg + image.remove() + elif args.remove_app: + app = App() + app.name = args.buildarg + app.remove() else: - if args.scratch: - lxcfile = os.path.join(buildpath, 'lxcfile') - if os.path.exists(lxcfile): - build_and_pack_image(lxcfile, args) + buildpath = os.path.realpath(args.buildarg) + # If the buildpath is a file, determine type from filename + if os.path.isfile(buildpath): + basename = os.path.basename(buildpath) + if basename == 'lxcfile' or basename.endswith('.lxcfile'): + build_and_pack_image(buildpath, args) + # Compose files needs to be ignored when performing scratch builds + elif not args.scratch and basename == 'meta': + pack_app(buildpath) else: - print('Please specify an lxcfile for scratch build') + print('Unknown file {} given, expected "lxcfile"{}'.format(buildpath, '' if args.scratch else ' or "meta"')) sys.exit(1) + # If the buildpath is a directory, build as much as possible, unless scratch build was requested, in which case don't build anything else: - valid_dir = False - for entry in os.scandir(buildpath): - if entry.is_file() and (entry.name == 'lxcfile' or entry.name.endswith('.lxcfile')): + if args.scratch: + lxcfile = os.path.join(buildpath, 'lxcfile') + if os.path.exists(lxcfile): + build_and_pack_image(lxcfile, args) + else: + print('Please specify an lxcfile for scratch build') + sys.exit(1) + else: + valid_dir = False + for entry in os.scandir(buildpath): + if entry.is_file() and (entry.name == 'lxcfile' or entry.name.endswith('.lxcfile')): + valid_dir = True + build_and_pack_image(entry.path, args) + meta = os.path.join(buildpath, 'meta') + if os.path.exists(meta): valid_dir = True - build_and_pack_image(entry.path, args) - meta = os.path.join(buildpath, 'meta') - if os.path.exists(meta): - valid_dir = True - pack_app(meta) - if not valid_dir: - print('Directory {} doesn\'t contain anything to build, skipping'.format(buildpath)) + pack_app(meta) + if not valid_dir: + print('Directory {} doesn\'t contain anything to build, skipping'.format(buildpath)) + +parser = argparse.ArgumentParser(description='VM application builder and packager') +group = parser.add_mutually_exclusive_group() +group.add_argument('-f', '--force', action='store_true', help='Force rebuild already built package') +group.add_argument('-s', '--scratch', action='store_true', help='Build container for testing purposes, i.e. without cleanup on failure and packaging') +group.add_argument('-r', '--remove-image', action='store_true', help='Delete image (including scratch) from build repository') +group.add_argument('-e', '--remove-app', action='store_true', help='Delete application from build repository') +parser.add_argument('buildarg', help='Either specific "lxcfile" or "meta" file or a directory containing at least one of them') + +args = parser.parse_args() +if hasattr(args, 'buildarg'): + main(args) +else: + parser.print_usage() diff --git a/doc/toolchain/vm-creation.md b/doc/toolchain/vm-creation.md index 1dca777..e9130c4 100644 --- a/doc/toolchain/vm-creation.md +++ b/doc/toolchain/vm-creation.md @@ -19,8 +19,8 @@ Download **Alpine Virtual 3.9.0 x86_64** from