Skip to content

Commit

Permalink
Support setting appendix on Dockerfiles too
Browse files Browse the repository at this point in the history
Until now, 'appendix' was ignored for repos built with
their own Dockerfile. This fixes that, and sets the appendix
on repos built with Dockerfiles too.

I want to set a REPO_URL env var for all images built with
repo2docker-action
(jupyterhub/repo2docker-action#86)
and this is needed for that.
  • Loading branch information
yuvipanda committed Mar 15, 2022
1 parent ec99349 commit 936a0e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
38 changes: 25 additions & 13 deletions repo2docker/buildpacks/docker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Generates a variety of Dockerfiles based on an input matrix
"""
import os
import tempfile
import docker
from .base import BuildPack

Expand All @@ -18,7 +19,15 @@ def render(self, build_args=None):
"""Render the Dockerfile using by reading it from the source repo"""
Dockerfile = self.binder_path("Dockerfile")
with open(Dockerfile) as f:
return f.read()
content = f.read()

if self.appendix:
content += "\n"
content += self.appendix

print(content)

return content

def build(
self,
Expand All @@ -45,17 +54,20 @@ def build(
# we use no swap.
limits = {"memory": memory_limit, "memswap": memory_limit}

build_kwargs = dict(
path=os.getcwd(),
dockerfile=self.binder_path(self.dockerfile),
tag=image_spec,
buildargs=build_args,
container_limits=limits,
cache_from=cache_from,
labels=self.get_labels(),
)
with tempfile.NamedTemporaryFile(mode="w") as f:
f.write(self.render())
f.flush()
build_kwargs = dict(
path=os.getcwd(),
dockerfile=f.name,
tag=image_spec,
buildargs=build_args,
container_limits=limits,
cache_from=cache_from,
labels=self.get_labels(),
)

build_kwargs.update(extra_build_kwargs)
build_kwargs.update(extra_build_kwargs)

for line in client.build(**build_kwargs):
yield line
for line in client.build(**build_kwargs):
yield line
3 changes: 3 additions & 0 deletions tests/dockerfile/simple/verify
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash
set -euo pipefail
/usr/local/bin/sayhi.sh

# Test that the appendix worked, even though this is a custom Dockerfile
test $(cat /tmp/appendix) == "appendix"

0 comments on commit 936a0e9

Please sign in to comment.