Skip to content
Snippets Groups Projects
Commit eaa94792 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Use git to determine changed files

parent bfb1f049
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ variables:
before_script:
- apk --no-cache add python
- pip install gitpython
build:
......
......@@ -4,39 +4,39 @@ import subprocess as sp
import sys
import time
import git
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):
changed_dockerfiles = [f.a_path for f in git.Repo('.').index.diff("HEAD~1")
if f.a_path.startswith("base/")]
n_files = len(changed_dockerfiles)
if n_files == 0:
print("Nothing to do!")
exit(0)
print("Processing {} dockerfile{}..."
.format(n_files, 's' if n_files else ''))
for idx, fname in enumerate(changed_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))
steps = [("Building",
"docker build --pull -t {0}/{1} -f {1} . "
.format(REGISTRY_URL, fname)),
("Pushing",
"docker push {0}/{1}"
.format(REGISTRY_URL, fname))]
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()
for step, cmd in steps:
print("{} {} '{}'".format(progress, step, fname))
child = sp.Popen(
cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr)
child.communicate()
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment