Skip to content

Commit

Permalink
core: docker installs delay update prompt until image is ready (#1034)
Browse files Browse the repository at this point in the history
* core: docker installs delay update prompt until image is ready

* update settings page with new check
  • Loading branch information
bjia56 committed Aug 23, 2023
1 parent efce576 commit 9b828a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
8 changes: 3 additions & 5 deletions plugins/core/ui/src/components/Drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<script>
import { getComponentViewPath } from "./helpers";
import { checkUpdate } from "./plugin/plugin";
import { checkServerUpdate } from "./plugin/plugin";
export default {
props: {
Expand Down Expand Up @@ -160,11 +160,9 @@ export default {
// in which case fall back and determine what the install type is.
const info = await this.$scrypted.systemManager.getComponent("info");
const version = await info.getVersion();
const scryptedEnv = await info.getScryptedEnv();
this.currentVersion = version;
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
);
const { updateAvailable } = await checkServerUpdate(version, scryptedEnv.SCRYPTED_INSTALL_ENVIRONMENT);
this.updateAvailable = updateAvailable;
}
Expand Down
8 changes: 3 additions & 5 deletions plugins/core/ui/src/components/builtin/SettingsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</v-layout>
</template>
<script>
import { checkUpdate } from "../plugin/plugin";
import { checkServerUpdate } from "../plugin/plugin";
import Settings from "../../interfaces/Settings.vue"
import {createSystemSettingsDevice} from './system-settings';
Expand Down Expand Up @@ -140,10 +140,8 @@ export default {
catch (e) {
// old scrypted servers dont support this call, or it may be unimplemented
// in which case fall back and determine what the install type is.
const { updateAvailable } = await checkUpdate(
"@scrypted/server",
version
);
const scryptedEnv = await info.getScryptedEnv();
const { updateAvailable } = await checkServerUpdate(version, scryptedEnv.SCRYPTED_INSTALL_ENVIRONMENT);
this.updateAvailable = updateAvailable;
}
},
Expand Down
33 changes: 33 additions & 0 deletions plugins/core/ui/src/components/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const pluginSnapshot = require("!!raw-loader!./plugin-snapshot.ts").default.spli

export interface PluginUpdateCheck {
updateAvailable?: string;
updatePublished?: Date;
versions: any;
}

Expand All @@ -29,11 +30,17 @@ export async function checkUpdate(npmPackage: string, npmPackageVersion: string)
const { data } = response;
const versions = Object.values(data.versions).sort((a: any, b: any) => semver.compare(a.version, b.version)).reverse();
let updateAvailable: any;
let updatePublished: any;
let latest: any;
if (data["dist-tags"]) {
latest = data["dist-tags"].latest;
if (npmPackageVersion && semver.gt(latest, npmPackageVersion)) {
updateAvailable = latest;
try {
updatePublished = new Date(data["time"][latest]);
} catch {
updatePublished = null;
}
}
}
for (const [k, v] of Object.entries(data['dist-tags'])) {
Expand All @@ -54,10 +61,36 @@ export async function checkUpdate(npmPackage: string, npmPackageVersion: string)
}
return {
updateAvailable,
updatePublished,
versions,
};
}

export async function checkServerUpdate(version: string, installEnvironment: string): Promise<PluginUpdateCheck> {
const { updateAvailable, updatePublished, versions } = await checkUpdate(
"@scrypted/server",
version
);

if (installEnvironment == "docker" && updatePublished) {
console.log(`New scrypted server version published ${updatePublished}`);

// check if there is a new docker image available, using 'latest' tag
// this is done so newer server versions in npm are not immediately
// displayed until a docker image has been published
let response: AxiosResponse<any> = await axios.get("https://corsproxy.io?https://hub.docker.com/v2/namespaces/koush/repositories/scrypted/tags/latest");
const { data } = response;
const imagePublished = new Date(data.last_updated);
console.log(`Latest docker image published ${imagePublished}`);

if (imagePublished < updatePublished) {
// docker image is not yet published
return { updateAvailable: null, updatePublished: null, versions: null }
}
}
return { updateAvailable, updatePublished, versions };
}

export async function installNpm(systemManager: SystemManager, npmPackage: string, version?: string): Promise<string> {
const plugins = await systemManager.getComponent('plugins');
await plugins.installNpm(npmPackage, version);
Expand Down

0 comments on commit 9b828a6

Please sign in to comment.