1#!/usr/bin/python 2 3import os 4import sys 5import json 6import subprocess 7from pprint import pprint 8 9REGISTRY = 'crossbar.local:5000' 10 11try: 12 BUILD_DATE = os.environ['BUILD_DATE'] 13 CROSSBAR_VERSION = os.environ['CROSSBAR_VERSION'] 14 AUTOBAHN_JS_VERSION = os.environ['AUTOBAHN_JS_VERSION'] 15 AUTOBAHN_PYTHON_VERSION = os.environ['AUTOBAHN_PYTHON_VERSION'] 16 AUTOBAHN_CPP_VERSION = os.environ['AUTOBAHN_CPP_VERSION'] 17except KeyError: 18 print('Autobahn/Crossbar.io Docker image versions not set: you need to run "source versions.sh" first!') 19 sys.exit(1) 20 21PACKAGE_TO_VERSION = { 22 # need to remove leading "v", as GitHub version tags do have "vX.Y.Z", but 23 # Docker image tags do NOT have the leading "v" 24 'crossbar': CROSSBAR_VERSION.replace('v', ''), 25 'autobahn-js': AUTOBAHN_JS_VERSION.replace('v', ''), 26 'autobahn-python': AUTOBAHN_PYTHON_VERSION.replace('v', ''), 27 'autobahn-cpp': AUTOBAHN_CPP_VERSION.replace('v', ''), 28} 29 30 31# 32# add these 3rd party images by default 33# 34IMAGES = [ 35 # Debian Stretch 36 'debian:stretch', 37 'aarch64/debian:stretch', 38 'armhf/debian:stretch', 39 40 # Debian Jessie 41 'debian:jessie', 42 'aarch64/debian:jessie', 43 'armhf/debian:jessie', 44 45 # Alpine 46 'alpine', 47 'armhf/alpine', 48 'aarch64/alpine', 49 50 # Ubuntu Xenial 51 'ubuntu:xenial', 52 'armhf/ubuntu:xenial', 53 'aarch64/ubuntu:xenial', 54 55 # Ubuntu Trusty 56 'ubuntu:trusty', 57 'armhf/ubuntu:trusty', 58 'aarch64/ubuntu:trusty', 59 60 # Python 61 'python', 62 'python:2', 63 'armhf/python', 64 'armhf/python:2', 65 'aarch64/python', 66 'aarch64/python:2', 67 68 # Node 69 'node', 70 'armhf/node', 71 'aarch64/node', 72 73 # Node RED 74 'nodered/node-red-docker', 75] 76 77 78# 79# expand list with all our Autobahn/Crossbar.io images 80# 81with open('images.json') as f_in: 82 data = f_in.read() 83 obj = json.loads(data) 84 for image in obj.get('images', []): 85 package = image.get('package', None) 86 architectures = image.get('architectures', None) 87 tags = image.get('tags', []) 88 for architecture in architectures: 89 for _tag in tags: 90 if package in PACKAGE_TO_VERSION: 91 _tag = _tag.format(version=PACKAGE_TO_VERSION[package]) 92 arch = '-{}'.format(architecture) if architecture != 'x86_64' else '' 93 image_id = 'crossbario/{package}{arch}:{tag}'.format(package=package, tag=_tag, arch=arch) 94 IMAGES.append(image_id) 95 96 97PUSHED_IMAGES = [] 98 99# 100# now actually pull the images, and push to the private registry 101# 102if True: 103 for image in IMAGES: 104 try: 105 tag = '{registry}/{image}'.format(image=image, registry=REGISTRY) 106 subprocess.check_output(['docker', 'pull', image], stderr=subprocess.STDOUT) 107 subprocess.check_output(['docker', 'tag', image, tag], stderr=subprocess.STDOUT) 108 subprocess.check_output(['docker', 'push', tag], stderr=subprocess.STDOUT) 109 except Exception as e: 110 print('\nWARNING: failed to process image "{}":'.format(image)) 111 print(e.output) 112 else: 113 print('OK: image "{}" pushed!'.format(image)) 114 PUSHED_IMAGES.append(image) 115 116# 117# generate a user help file for the images 118# 119if True: 120 with open('pushed_images.md', 'w') as f: 121 f.write("# Docker images available in the private Docker registry\n\n") 122 f.write("The private Docker registry at `crossbar.local:5000` contains dozens of images. For convenience, the following list contains the full commands to pull these images to your local system.\n\n") 123 for image in PUSHED_IMAGES: 124 f.write('1. `docker pull crossbar.local:5000/{}`\n'.format(image)) 125