Skip to content

Commit

Permalink
Add url to vendor the current agent chart
Browse files Browse the repository at this point in the history
This will allow users to not have to manually vendor this in airgapped environments, dramatically simplifying e2e setup.  Will need to follow-on with some terraform provider/cli changes as well.
  • Loading branch information
michaeljguarino committed Feb 22, 2025
1 parent fb79b5f commit 5879bbf
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ RUN ls -al

COPY --from=node /app/build ./priv/static

RUN mix release
RUN mix do agent.chart, release

FROM ${TOOLS_IMAGE} as tools

Expand All @@ -74,6 +74,8 @@ ENV CLI_VERSION=v0.12.1
# renovate: datasource=github-tags depName=kubernetes/kubernetes
# ENV KUBECTL_VERSION=v1.31.3

COPY AGENT_VERSION AGENT_VERSION

RUN apk update && apk add curl wget unzip
RUN curl -L https://github.com/pluralsh/plural-cli/releases/download/${CLI_VERSION}/plural-cli_${CLI_VERSION#v}_Linux_${TARGETARCH}.tar.gz | tar xvz plural && \
mv plural /usr/local/bin/plural && \
Expand Down
3 changes: 1 addition & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ config :console, ConsoleWeb.Endpoint,
http: [port: 4002],
server: false

config :logger, level: :warning
config :logger, level: :error

config :goth,
disabled: true

config :piazza_core, aes_key: "1HdFP1DuK7xkkcEBne41yAwUY8NSfJnYfGVylYYCS2U="


secrets_path = __ENV__.file |> Path.dirname() |> Path.join("secrets")
binfile = fn p ->
__ENV__.file
Expand Down
7 changes: 7 additions & 0 deletions lib/console/deployments/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Console.Deployments.Settings do

@agent_vsn File.read!("AGENT_VERSION") |> String.trim()
@kube_vsn File.read!("KUBE_VERSION") |> String.trim()
@agent_chart Path.join(:code.priv_dir(:console), "agent-chart.tgz")
@cache_adapter Console.conf(:cache_adapter)
@ttl :timer.minutes(45)

Expand Down Expand Up @@ -64,6 +65,12 @@ defmodule Console.Deployments.Settings do
@spec agent_vsn() :: binary
def agent_vsn(), do: @agent_vsn

@doc """
Local file containing the valid, working agent chart tarball
"""
@spec agent_chart() :: binary
def agent_chart(), do: @agent_chart

@doc "same as fetch/0 but always reads from db"
def fetch_consistent() do
Console.Repo.get_by(DeploymentSettings, name: "global")
Expand Down
5 changes: 5 additions & 0 deletions lib/console_web/controllers/git_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ defmodule ConsoleWeb.GitController do
end
end

def agent_chart(conn, _) do
path = Console.Deployments.Settings.agent_chart()
chunk_send_tar(conn, File.open!(path, [:raw]))
end

def stack_tarball(conn, %{"id" => run_id}) do
with %Cluster{} = cluster <- ConsoleWeb.Plugs.Token.get_cluster(conn),
{:ok, run} <- Stacks.authorized(run_id, cluster),
Expand Down
1 change: 1 addition & 0 deletions lib/console_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule ConsoleWeb.Router do
pipe_through [:api]

scope "/v1", ConsoleWeb do
get "/agent/chart", GitController, :agent_chart
post "/webhooks/observability/:type/:id", WebhookController, :observability
post "/webhooks/:type/:id", WebhookController, :scm

Expand Down
21 changes: 21 additions & 0 deletions lib/mix/tasks/agent.chart.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Mix.Tasks.Agent.Chart do
use Mix.Task
alias Console.Deployments.Settings

@deps ~w(logger req)a

def run(_) do
Enum.each(@deps, &Application.ensure_all_started/1)
Logger.configure(level: :error)

file = Settings.agent_chart()

Settings.agent_vsn()
|> String.trim_leading("v")
|> agent_chart_url()
|> Req.get!(into: File.stream!(file))
end

defp agent_chart_url(vsn),
do: "https://github.com/pluralsh/deployment-operator/releases/download/agent-v#{vsn}/deployment-operator-#{vsn}.tgz"
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ defmodule Console.MixProject do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "elasticsearch.down", "elasticsearch.up", "test"]
test: ["ecto.create --quiet", "agent.chart", "ecto.migrate", "elasticsearch.down", "elasticsearch.up", "test"]
]
end
end
Binary file added priv/agent-chart.tgz
Binary file not shown.
8 changes: 8 additions & 0 deletions test/console_web/controllers/git_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
defmodule ConsoleWeb.GitControllerTest do
use ConsoleWeb.ConnCase, async: false

describe "agent_chart/2" do
test "it can download the current valid agent chart", %{conn: conn} do
conn
|> get("/ext/v1/agent/chart")
|> response(200)
end
end

describe "#tarball/2" do
test "it will download git content for valid deploy tokens", %{conn: conn} do
git = insert(:git_repository, url: "https://github.com/pluralsh/console.git")
Expand Down

0 comments on commit 5879bbf

Please sign in to comment.