Skip to content

Commit

Permalink
Merge pull request #52 from TimoRoth/add_buildargs
Browse files Browse the repository at this point in the history
Expose custom build-args as advanced option in the UI
  • Loading branch information
jtpio authored Dec 31, 2021
2 parents fe7d689 + 43a990d commit 0fc8e1a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
13 changes: 12 additions & 1 deletion tljh_repo2docker/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async def post(self):
name = data["name"].lower()
memory = data["memory"]
cpu = data["cpu"]
buildargs = data.get("buildargs", None)
username = data.get("username", None)
password = data.get("password", None)

Expand All @@ -63,7 +64,17 @@ async def post(self):
f"The name of the environment is restricted to the following characters: {IMAGE_NAME_RE}",
)

await build_image(repo, ref, name, memory, cpu, username, password)
extra_buildargs = []
if buildargs:
for barg in buildargs.split("\n"):
if "=" not in barg:
raise web.HTTPError(
400,
"Invalid build argument format"
)
extra_buildargs.append(barg)

await build_image(repo, ref, name, memory, cpu, username, password, extra_buildargs)

self.set_status(200)
self.finish(json.dumps({"status": "ok"}))
9 changes: 8 additions & 1 deletion tljh_repo2docker/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ async def list_containers():


async def build_image(
repo, ref, name="", memory=None, cpu=None, username=None, password=None
repo, ref, name="", memory=None, cpu=None, username=None, password=None,
extra_buildargs=None
):
"""
Build an image given a repo, ref and limits
Expand Down Expand Up @@ -100,6 +101,12 @@ async def build_image(
label
]

for barg in extra_buildargs or []:
cmd += [
"--build-arg",
barg
]

cmd.append(repo)

config = {
Expand Down
3 changes: 3 additions & 0 deletions tljh_repo2docker/static/js/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require([
dialog.find(".name-input").val("");
dialog.find(".memory-input").val("");
dialog.find(".cpu-input").val("");
dialog.find(".build-args-input").val("");
dialog.find(".username-input").val("");
dialog.find(".password-input").val("");
dialog.modal();
Expand All @@ -50,6 +51,7 @@ require([
var name = dialog.find(".name-input").val().trim();
var memory = dialog.find(".memory-input").val().trim();
var cpu = dialog.find(".cpu-input").val().trim();
var buildargs = dialog.find(".build-args-input").val().trim();
var username = dialog.find(".username-input").val().trim();
var password = dialog.find(".password-input").val().trim();
var spinner = $("#adding-environment-dialog");
Expand All @@ -63,6 +65,7 @@ require([
name: name,
memory: memory,
cpu: cpu,
buildargs: buildargs,
username: username,
password: password,
}),
Expand Down
11 changes: 10 additions & 1 deletion tljh_repo2docker/templates/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@
</div>
</div>
<details>
<summary>˃ Credentials (optional)</summary>
<summary>&gt; Advanced</summary>
<div class="form-group">
<label for="build-args" class="col-sm-4 control-label">Build Arguments</label>
<div class="col-sm-8">
<textarea class="form-control build-args-input" id="build-args" rows="4" placeholder="arg1=val1&#10;arg2=val2&#10;..."></textarea>
</div>
</div>
</details>
<details>
<summary>&gt; Credentials (optional)</summary>
<div class="form-group">
<label for="username" class="col-sm-4 control-label">Git Username</label>
<div class="col-sm-8">
Expand Down

0 comments on commit 0fc8e1a

Please sign in to comment.