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 97d8e7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
43 changes: 29 additions & 14 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 @@ -15,10 +16,21 @@ def detect(self):
return os.path.exists(self.binder_path("Dockerfile"))

def render(self, build_args=None):
"""Render the Dockerfile using by reading it from the source repo"""
"""
Render the Dockerfile used by reading it from the source repo
If an appendix is configured, it will be appended to the Dockerfile
found in 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

return content

def build(
self,
Expand All @@ -45,17 +57,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 97d8e7a

Please sign in to comment.