Skip to content

Commit

Permalink
cli: fixes generation of image tag for docker runner
Browse files Browse the repository at this point in the history
When a step references a local dockerfile, the tag of the image was
being assigned to the GIT_TAG of the underlying git project. When a
workflow gets executed in a folder that is not part of a repo, an empty
tag (with a `{}` string) was being generated and this caused an error:

  [1] docker build popper_1_step:{} /private/tmp/example/./foo
  ERROR: 500 Server Error: Internal Server Error ("invalid reference format")

With this commit adds logic to generate "na" as the tag for the image,
when running inside a "gitless" folder.

fixes #886
  • Loading branch information
ivotron committed Jul 19, 2020
1 parent 066cf5d commit db30d41
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/popper/runner_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def _get_build_info(self, step):
tag = "latest"
build = False
elif "./" in step.uses:
img = f'{pu.sanitized_name(step.id, "step")}'.lower()
tag = f"{self._config.git_sha_short}"
img = pu.sanitized_name(step.id, "step").lower()
tag = self._config.git_sha_short if self._config.git_sha_short else "na"
build_ctx_path = os.path.join(self._config.workspace_dir, step.uses)
else:
_, service, user, repo, step_dir, version = scm.parse(step.uses)
Expand Down
40 changes: 30 additions & 10 deletions src/test/test_runner_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from testfixtures import LogCapture
from subprocess import Popen

import popper.scm as scm
import popper.utils as pu

from popper.config import ConfigLoader
Expand Down Expand Up @@ -247,12 +248,12 @@ def test_get_build_info(self):
default_box=True,
)
with DockerRunner(init_docker_client=False) as dr:
build, img, tag, build_sources = dr._get_build_info(step)
build, img, tag, build_ctx_path = dr._get_build_info(step)
self.assertEqual(build, True)
self.assertEqual(img, "popperized/bin")
self.assertEqual(tag, "master")
self.assertTrue(f"{os.environ['HOME']}/.cache/popper" in build_sources)
self.assertTrue("github.com/popperized/bin/sh" in build_sources)
self.assertTrue(f"{os.environ['HOME']}/.cache/popper" in build_ctx_path)
self.assertTrue("github.com/popperized/bin/sh" in build_ctx_path)

step = Box(
{
Expand All @@ -265,11 +266,30 @@ def test_get_build_info(self):
)

with DockerRunner(init_docker_client=False) as dr:
build, img, tag, build_sources = dr._get_build_info(step)
build, img, tag, build_ctx_path = dr._get_build_info(step)
self.assertEqual(build, False)
self.assertEqual(img, "alpine")
self.assertEqual(tag, "3.9")
self.assertEqual(build_sources, None)
self.assertEqual(build_ctx_path, None)

step = Box({"uses": "./", "args": ["ls"], "id": "one",}, default_box=True,)
conf = ConfigLoader.load(workspace_dir="/tmp")
with DockerRunner(init_docker_client=False, config=conf) as dr:
build, img, tag, build_ctx_path = dr._get_build_info(step)
self.assertEqual(build, True)
self.assertEqual(img, "popper_one_step")
self.assertEqual(tag, "na")
self.assertEqual(build_ctx_path, f"{os.path.realpath('/tmp')}/./")

# test within a git repo
repo = self.mk_repo()
conf = ConfigLoader.load(workspace_dir=repo.working_dir)
with DockerRunner(init_docker_client=False, config=conf) as dr:
build, img, tag, build_ctx_path = dr._get_build_info(step)
self.assertEqual(build, True)
self.assertEqual(img, "popper_one_step")
self.assertEqual(tag, scm.get_sha(repo, short=7))
self.assertEqual(build_ctx_path, f"{os.path.realpath(repo.working_dir)}/./")

@unittest.skipIf(os.environ.get("ENGINE", "docker") != "docker", "ENGINE != docker")
def test_docker_basic_run(self):
Expand Down Expand Up @@ -463,11 +483,11 @@ def test_get_build_info(self):
default_box=True,
)
with SingularityRunner() as sr:
build, img, build_sources = sr._get_build_info(step)
build, img, build_ctx_path = sr._get_build_info(step)
self.assertEqual(build, True)
self.assertEqual(img, "popperized/bin")
self.assertTrue(f"{os.environ['HOME']}/.cache/popper" in build_sources)
self.assertTrue(f"github.com/popperized/bin/sh" in build_sources)
self.assertTrue(f"{os.environ['HOME']}/.cache/popper" in build_ctx_path)
self.assertTrue("github.com/popperized/bin/sh" in build_ctx_path)

step = Box(
{
Expand All @@ -480,10 +500,10 @@ def test_get_build_info(self):
)

with SingularityRunner() as sr:
build, img, build_sources = sr._get_build_info(step)
build, img, build_ctx_path = sr._get_build_info(step)
self.assertEqual(build, False)
self.assertEqual(img, "docker://alpine:3.9")
self.assertEqual(build_sources, None)
self.assertEqual(build_ctx_path, None)

@unittest.skipIf(
os.environ.get("ENGINE", "docker") != "singularity", "ENGINE != singularity"
Expand Down

0 comments on commit db30d41

Please sign in to comment.