Skip to content

Commit 8405d96

Browse files
authored
Accept a custom image registry url (#3066)
1 parent 74cd078 commit 8405d96

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ The following environment variables can be used to configure Livebook on boot:
255255
By default iframes are loaded from local `LIVEBOOK_IFRAME_PORT` when accessing
256256
Livebook over http:// and from https://livebookusercontent.com when accessing over https://.
257257

258+
* `LIVEBOOK_IMAGE_REGISTRY_URL` - sets the container image registry used to fetch livebook images from.
259+
By default uses `ghcr.io/livebook-dev/livebook`.
260+
258261
* `LIVEBOOK_IP` - sets the ip address to start the web application on.
259262
Must be a valid IPv4 or IPv6 address.
260263

lib/livebook.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ defmodule Livebook do
264264
config :livebook, :agent_name, agent_name
265265
end
266266

267+
if image_registry_url = Livebook.Config.image_registry_url!("LIVEBOOK_IMAGE_REGISTRY_URL") do
268+
config :livebook, :image_registry_url, image_registry_url
269+
end
270+
267271
if Livebook.Config.boolean!("LIVEBOOK_FIPS", false) do
268272
if :crypto.enable_fips_mode(true) do
269273
IO.puts("[Livebook] FIPS mode enabled")

lib/livebook/config.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ defmodule Livebook.Config do
2020
Application.get_env(:livebook, :priv_dir) || Application.app_dir(:livebook, "priv")
2121
end
2222

23+
@doc """
24+
Returns container image registry URL.
25+
26+
This returns the usual container image registry URL, and allows users to specify a custom URL.
27+
"""
28+
@spec image_registry_url() :: String.t()
29+
def image_registry_url() do
30+
Application.get_env(:livebook, :image_registry_url) || "ghcr.io/livebook-dev/livebook"
31+
end
32+
2333
@doc """
2434
Returns docker images to be used when generating sample Dockerfiles.
2535
"""
@@ -663,6 +673,13 @@ defmodule Livebook.Config do
663673
end
664674
end
665675

676+
@doc """
677+
Parses image registry from env.
678+
"""
679+
def image_registry_url!(env) do
680+
System.get_env(env)
681+
end
682+
666683
@doc """
667684
Parses and validates default runtime from env.
668685
"""

lib/livebook/hubs/dockerfile.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule Livebook.Hubs.Dockerfile do
33

44
import Ecto.Changeset
55

6+
alias Livebook.Config
67
alias Livebook.Hubs
78

89
@type config :: %{
@@ -82,8 +83,10 @@ defmodule Livebook.Hubs.Dockerfile do
8283
) do
8384
base_image = Enum.find(Livebook.Config.docker_images(), &(&1.tag == config.docker_tag))
8485

86+
image_registry_url = Config.image_registry_url()
87+
8588
image = """
86-
FROM ghcr.io/livebook-dev/livebook:#{base_image.tag}
89+
FROM #{image_registry_url}:#{base_image.tag}
8790
"""
8891

8992
image_envs = format_envs(base_image.env)
@@ -316,7 +319,8 @@ defmodule Livebook.Hubs.Dockerfile do
316319
def online_docker_info(config, %Hubs.Team{} = hub, agent_key) do
317320
base_image = Enum.find(Livebook.Config.docker_images(), &(&1.tag == config.docker_tag))
318321

319-
image = "ghcr.io/livebook-dev/livebook:#{base_image.tag}"
322+
image_registry_url = Config.image_registry_url()
323+
image = "#{image_registry_url}:#{base_image.tag}"
320324

321325
env = [
322326
{"LIVEBOOK_AGENT_NAME", "default"},

lib/livebook/k8s/pod.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ defmodule Livebook.K8s.Pod do
1919
memory: 1Gi\
2020
"""
2121

22+
alias Livebook.Config
23+
2224
@doc """
2325
Returns the default pod template.
2426
"""
@@ -73,7 +75,8 @@ defmodule Livebook.K8s.Pod do
7375
"""
7476
@spec set_docker_tag(map(), String.t()) :: map()
7577
def set_docker_tag(manifest, docker_tag) do
76-
image = "ghcr.io/livebook-dev/livebook:#{docker_tag}"
78+
image_registry_url = Config.image_registry_url()
79+
image = "#{image_registry_url}:#{docker_tag}"
7780
put_in(manifest, ["spec", "containers", access_main_container(), "image"], image)
7881
end
7982

lib/livebook/runtime/fly.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ defmodule Livebook.Runtime.Fly do
5151

5252
use GenServer, restart: :temporary
5353

54+
alias Livebook.Config
5455
alias Livebook.Runtime.RemoteUtils
5556

5657
@type t :: %__MODULE__{
@@ -200,7 +201,10 @@ defmodule Livebook.Runtime.Fly do
200201

201202
defp create_machine(config, runtime_data) do
202203
base_image = Enum.find(Livebook.Config.docker_images(), &(&1.tag == config.docker_tag))
203-
image = "ghcr.io/livebook-dev/livebook:#{base_image.tag}"
204+
205+
image_registry_url = Config.image_registry_url()
206+
207+
image = "#{image_registry_url}:#{base_image.tag}"
204208

205209
env =
206210
Map.merge(

0 commit comments

Comments
 (0)