Skip to content
Snippets Groups Projects
publish_images.py 1.38 KiB
Newer Older
Tamas Gal's avatar
Tamas Gal committed
#!/usr/bin/env python
from glob import glob
import subprocess as sp
import sys
import time

REGISTRY_URL = 'docker.km3net.de'


def main():
    dockerfiles = glob('base/*:*')
    n_files = len(dockerfiles)
    print("Processing {} dockerfiles...".format(n_files))
    for idx, fname in enumerate(dockerfiles):
        progress = "({}/{})".format(idx + 1, n_files)

        print('-' * 79)
        print("{} Checking for existing '{}'".format(progress, fname))
        pull_cmd = ("docker pull {0}/{1}".format(REGISTRY_URL, fname))
        child = sp.Popen(
            pull_cmd, shell=True, stdout=sys.stdout, stderr=sp.PIPE)
        child.communicate()
        if child.returncode > 0:
            print("  -> no image found for '{}', starting from scratch.".
                  format(fname))

Tamas Gal's avatar
Tamas Gal committed
        print('-' * 79)
        print("{} Building '{}'".format(progress, fname))
        build_cmd = ("docker build --pull -t {0}/{1} -f {1} . ".format(
            REGISTRY_URL, fname))
        child = sp.Popen(
            build_cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
        child.communicate()

        print("{} Publishing '{}'".format(progress, fname))
        push_cmd = ("docker push {0}/{1}".format(REGISTRY_URL, fname))
        child = sp.Popen(
            push_cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
        child.communicate()

Tamas Gal's avatar
Tamas Gal committed
if __name__ == '__main__':
    main()