diff --git a/app/actions/add_ons/install_helm_chart.rb b/app/actions/add_ons/install_helm_chart.rb index e5047eb2..9baddb7a 100644 --- a/app/actions/add_ons/install_helm_chart.rb +++ b/app/actions/add_ons/install_helm_chart.rb @@ -5,7 +5,9 @@ class AddOns::InstallHelmChart executed do |context| add_on = context.add_on + add_on.update_install_stage!(0) create_namespace(add_on) + if add_on.installed? add_on.updating! else @@ -20,12 +22,17 @@ class AddOns::InstallHelmChart chart_url = add_on.chart_url package_details = add_on.metadata['package_details'] + + add_on.update_install_stage!(1) client.add_repo( package_details['repository']['name'], package_details['repository']['url'] ) + + add_on.update_install_stage!(2) client.repo_update(repo_name: chart_url.split('/').first) + add_on.update_install_stage!(3) client.install( add_on.name, chart_url, diff --git a/app/javascript/controllers/logs_controller.js b/app/javascript/controllers/logs_controller.js index 9f1d258c..b098826a 100644 --- a/app/javascript/controllers/logs_controller.js +++ b/app/javascript/controllers/logs_controller.js @@ -4,7 +4,6 @@ export default class extends Controller { static targets = ["container"] connect() { - console.log("connected") // Scroll to the bottom of the container this.scrollToBottom(); diff --git a/app/javascript/controllers/progress_progressing_controller.js b/app/javascript/controllers/progress_progressing_controller.js new file mode 100644 index 00000000..e053050e --- /dev/null +++ b/app/javascript/controllers/progress_progressing_controller.js @@ -0,0 +1,16 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + debugger + const progress = this.element; + let value = 0; + + setInterval(() => { + value = (value + 1) % 101; + progress.value = value; + }, 15); + } + + +} diff --git a/app/models/add_on.rb b/app/models/add_on.rb index 6004696e..b45459ba 100644 --- a/app/models/add_on.rb +++ b/app/models/add_on.rb @@ -26,7 +26,16 @@ class AddOn < ApplicationRecord include Loggable belongs_to :cluster has_one :account, through: :cluster - enum :status, { installing: 0, installed: 1, uninstalling: 2, uninstalled: 3, failed: 4, updating: 5 } + + enum :status, { + installing: 0, + installed: 1, + uninstalling: 2, + uninstalled: 3, + failed: 4, + updating: 5 + } + validates :chart_type, presence: true validate :chart_type_exists validates :name, presence: true, format: { with: /\A[a-z0-9-]+\z/, message: "must be lowercase, numbers, and hyphens only" } @@ -34,6 +43,19 @@ class AddOn < ApplicationRecord validates_presence_of :chart_url validate :has_package_details, if: :helm_chart? + after_update_commit do + broadcast_replace_later_to [ self, :install_stage ], target: dom_id(self, :install_stage), partial: "add_ons/install_stage", locals: { add_on: self } + end + + def update_install_stage!(stage) + self.metadata['install_stage'] = stage + save + end + + def install_stage + metadata['install_stage'] || 0 + end + def name_is_unique_to_cluster if cluster.namespaces.include?(name) errors.add(:name, "must be unique to this cluster") diff --git a/app/views/add_ons/_install_animation.html.erb b/app/views/add_ons/_install_animation.html.erb new file mode 100644 index 00000000..02c2c20e --- /dev/null +++ b/app/views/add_ons/_install_animation.html.erb @@ -0,0 +1,30 @@ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/add_ons/_install_stage.html.erb b/app/views/add_ons/_install_stage.html.erb new file mode 100644 index 00000000..1dcdec86 --- /dev/null +++ b/app/views/add_ons/_install_stage.html.erb @@ -0,0 +1,36 @@ +<%= turbo_frame_tag dom_id(add_on, :install_stage) do %> + <% if add_on.installed? %> + + <% end %> +
+
+ <% 4.times do |i| %> + + data-controller="progress-progressing" + <% end %> + class="progress progress-primary w-full" + <% if add_on.install_stage > i %> + value="100" + <% else %> + value="0" + <% end %> + max="100"> + + <% end %> +
+
+ <% ["Creating namespace", "Downloading chart", "Installing chart", "Waiting for chart to be ready"].each_with_index do |step, i| %> +
"> + <%= step %> + <% if add_on.install_stage > i %> + + <% end %> +
+ <% end %> +
+
+ Go grab a coffee, this could take a while. +
+
+<% end %> \ No newline at end of file diff --git a/app/views/add_ons/_installing.html.erb b/app/views/add_ons/_installing.html.erb deleted file mode 100644 index b043731e..00000000 --- a/app/views/add_ons/_installing.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file diff --git a/app/views/add_ons/_layout.html.erb b/app/views/add_ons/_layout.html.erb index ae26df86..ebfd5aef 100644 --- a/app/views/add_ons/_layout.html.erb +++ b/app/views/add_ons/_layout.html.erb @@ -1,20 +1,21 @@ <% if add_on.installing? %>
-
- <%= render "add_ons/installing" %> -
- Your add-on is installing... Go grab a coffee, this could take a while. -
+
+
+ <%= render "add_ons/install_animation", add_on: %> -
- -
Show install logs
-
- <%= render "log_outputs/logs", loggable: @add_on %> + <%= turbo_stream_from [add_on, :install_stage] %> + <%= render "add_ons/install_stage", add_on: %> + +
+ +
Show install logs
+
+ <%= render "log_outputs/logs", loggable: add_on %> +
-
@@ -23,20 +24,20 @@
- <%= render "add_ons/status", add_on: @add_on %> + <%= render "add_ons/status", add_on: add_on %>

- <%= @add_on.name %> + <%= add_on.name %>

- <%= link_to "https://artifacthub.io/packages/helm/#{@add_on.chart_url}", class: "underline", target: "_blank" do %> - <%= @add_on.chart_url %> + <%= link_to "https://artifacthub.io/packages/helm/#{add_on.chart_url}", class: "underline", target: "_blank" do %> + <%= add_on.chart_url %> <% end %> <%= link_to add_on.cluster.name, add_on.cluster, target: "_blank", class: "underline" %>
- <%= button_to "Restart", restart_add_on_path(@add_on), method: :post, class: "btn btn-primary" %> + <%= button_to "Restart", restart_add_on_path(add_on), method: :post, class: "btn btn-primary" %>