Commit 55f18bd2 authored by Alexander Lercher's avatar Alexander Lercher

Build script with docker hub push enabled

parent 0c03ffeb
...@@ -2,10 +2,13 @@ import os ...@@ -2,10 +2,13 @@ import os
import shutil import shutil
import sys import sys
if len(sys.argv) != 2:
raise Exception("Push to Docker Hub will not work, please provide username as argument")
DOCKER_COMPOSE_NAME = "Dockerfile" DOCKER_COMPOSE_NAME = "Dockerfile"
ROOT = '../' ROOT = '../'
SOURCEPATH = f'{ROOT}src/' SOURCEPATH = f'{ROOT}src/'
DOCKER_USERNAME = sys.argv[1]
paths = [] paths = []
for r, _, f in os.walk(SOURCEPATH): for r, _, f in os.walk(SOURCEPATH):
...@@ -21,18 +24,18 @@ command_args = [{'path': path, ...@@ -21,18 +24,18 @@ command_args = [{'path': path,
res_str = [] res_str = []
for command_arg in command_args: for command_arg in command_args:
path = command_arg['path'] path = command_arg['path']
image_name = command_arg['name'] image_name = f"{DOCKER_USERNAME}/{command_arg['name']}"
# copy Dockerfile into root dir to have access to modules folder # copy Dockerfile into root dir to have access to modules folder
shutil.copy2(os.path.join(path, DOCKER_COMPOSE_NAME), ROOT) shutil.copy2(os.path.join(path, DOCKER_COMPOSE_NAME), ROOT)
# build then remove Dockerfile # build then remove Dockerfile
exit_val = os.system(f"docker image build -t {image_name} {ROOT}") exit_val = os.system(f"docker image build -t {image_name} {ROOT}")
os.remove(os.path.normpath(ROOT, DOCKER_COMPOSE_NAME)) os.remove(os.path.join(ROOT, DOCKER_COMPOSE_NAME))
res_str.append(f"### {image_name} built with exit code {exit_val}") res_str.append(f"### {image_name} built with exit code {exit_val}")
# os.system(f"docker push {image_name}") os.system(f"docker push {image_name}")
print(f"Found {len(command_args)} images") print(f"Found {len(command_args)} images")
for s in res_str: for s in res_str:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment