DEV: Restore the outdated-image logic

This commit is contained in:
Jarek Radosz 2023-01-30 11:41:39 +01:00
parent 633bc2c414
commit 4c8593cf43
6 changed files with 88 additions and 77 deletions

View File

@ -6,32 +6,6 @@ require_dependency "docker_manager/upgrader"
module DockerManager
class AdminController < Admin::AdminController
def index
return if Rails.env.development?
version =
begin
File.read("/VERSION")
rescue StandardError
"1.0.0"
end
version = Gem::Version.new(version)
expected_version = Gem::Version.new("2.0.20221221-0050")
ruby_version = Gem::Version.new(RUBY_VERSION)
expected_ruby_version = Gem::Version.new("3.1.3")
min_stable_version = Gem::Version.new("3.0.0")
min_beta_version = Gem::Version.new("3.1.0.beta1")
upgrade_image = version < expected_version
upgrade_ruby = ruby_version < expected_ruby_version
upgrade_discourse =
discourse_upgrade_required?(min_stable_version, min_beta_version)
if upgrade_image || upgrade_ruby || upgrade_discourse
render "upgrade_required", layout: false
else
render
end
end
def repos
@ -62,10 +36,38 @@ module DockerManager
result[:version] = r.upgrade_version
end
end
result
end
render json: { repos: repos }
response = { repos: repos }
if !Rails.env.development?
version =
begin
File.read("/VERSION")
rescue StandardError
"1.0.0"
end
version = Gem::Version.new(version)
expected_version = Gem::Version.new("2.0.20221221-0050")
ruby_version = Gem::Version.new(RUBY_VERSION)
expected_ruby_version = Gem::Version.new("3.1.3")
min_stable_version = Gem::Version.new("3.0.0")
min_beta_version = Gem::Version.new("3.1.0.beta1")
upgrade_image = version < expected_version
upgrade_ruby = ruby_version < expected_ruby_version
upgrade_discourse =
discourse_upgrade_required?(min_stable_version, min_beta_version)
if upgrade_image || upgrade_ruby || upgrade_discourse
response[:upgrade_required] = true
end
end
render json: response
end
def progress

View File

@ -1,21 +0,0 @@
<html>
<head></head>
<body>
<h2>You are running an old version of the Discourse image.</h2>
<p>
Upgrades via the web UI are disabled until you run the latest image.
</p>
<p>
To do so log in to your server using SSH and run:
</p>
<pre>
cd /var/discourse
git pull
./launcher rebuild app
</pre>
<p>
<a href='https://meta.discourse.org/t/how-do-i-update-my-docker-image-to-latest/23325'>More info on our support site</a>
</p>
</body>
</html>

View File

@ -2,6 +2,7 @@ import Controller from "@ember/controller";
import { inject as service } from "@ember/service";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { needsImageUpgrade } from "discourse/plugins/docker_manager/discourse/models/repo";
export default class UpgradeIndex extends Controller {
@service router;
@ -9,6 +10,10 @@ export default class UpgradeIndex extends Controller {
@tracked managerRepo = null;
@tracked upgrading = null;
get outdated() {
return needsImageUpgrade;
}
get upgradeAllButtonDisabled() {
return !this.managerRepo.upToDate || this.allUpToDate;
}
@ -19,6 +24,6 @@ export default class UpgradeIndex extends Controller {
@action
upgradeAllButton() {
this.router.replaceWith("upgrade.show", "all");
this.router.transitionTo("upgrade.show", "all");
}
}

View File

@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";
import { TrackedObject } from "@ember-compat/tracked-built-ins";
let loaded = [];
export let needsImageUpgrade = false;
function concatVersions(repos) {
return repos.map((repo) => repo.version).join(", ");
@ -140,6 +141,8 @@ Repo.findAll = async function () {
const result = await ajax("/admin/docker/repos");
loaded = result.repos.map((r) => new Repo(r));
needsImageUpgrade = result.upgrade_required;
return loaded;
};

View File

@ -1,31 +1,50 @@
<h1>{{i18n "admin.docker.upgrade_title"}}</h1>
<button
disabled={{upgradeAllButtonDisabled}}
id="upgrade-all"
class="btn"
{{action "upgradeAllButton"}}
>
{{#if allUpToDate}}
{{i18n "admin.docker.all_up_to_date"}}
{{else}}
{{i18n "admin.docker.upgrade_all"}}
{{/if}}
</button>
{{#if this.outdated}}
<h2>{{i18n "admin.docker.outdated_image_header"}}</h2>
<p>{{i18n "admin.docker.outdated_image_info"}}</p>
<table class="table" id="repos">
<thead>
<th></th>
<th style="width: 50%">{{i18n "admin.docker.repository"}}</th>
<th>{{i18n "admin.docker.status"}}</th>
</thead>
<tbody>
{{#each this.model as |repo|}}
<RepoStatus
@repo={{repo}}
@upgradingRepo={{this.upgrading}}
@managerRepo={{this.managerRepo}}
/>
{{/each}}
</tbody>
</table>
{{! prettier-ignore }}
<pre>
cd /var/discourse
git pull
./launcher rebuild app
</pre>
<p>
<a
href="https://meta.discourse.org/t/how-do-i-update-my-docker-image-to-latest/23325"
>
{{i18n "admin.docker.outdated_image_link"}}
</a>
</p>
{{else}}
<button
disabled={{upgradeAllButtonDisabled}}
id="upgrade-all"
class="btn"
{{action "upgradeAllButton"}}
>
{{#if allUpToDate}}
{{i18n "admin.docker.all_up_to_date"}}
{{else}}
{{i18n "admin.docker.upgrade_all"}}
{{/if}}
</button>
<table class="table" id="repos">
<thead>
<th></th>
<th style="width: 50%">{{i18n "admin.docker.repository"}}</th>
<th>{{i18n "admin.docker.status"}}</th>
</thead>
<tbody>
{{#each this.model as |repo|}}
<RepoStatus
@repo={{repo}}
@upgradingRepo={{this.upgrading}}
@managerRepo={{this.managerRepo}}
/>
{{/each}}
</tbody>
</table>
{{/if}}

View File

@ -15,6 +15,9 @@ en:
main_branch_warning: "<b>WARNING:</b> Your Discourse is tracking the 'main' branch which may be unstable, <a href='https://meta.discourse.org/t/change-tracking-branch-for-your-discourse-instance/17014'> we recommend tracking the 'tests-passed' branch</a>."
new_version_available: "New Version Available!"
official_plugin: "Official Plugin"
outdated_image_header: "You are running an old version of the Discourse image"
outdated_image_info: "Upgrades via the web UI are disabled until you run the latest image. To do so log in to your server using SSH and run:"
outdated_image_link: "More info on our support site"
outdated_notice: "Your Discourse installation is out of date"
perform_upgrade: "Click here to upgrade."
repo_newest_version: "%{name} is at the newest version."