diff --git a/src/lib/migration.coffee b/src/lib/migration.coffee deleted file mode 100644 index d60cd32e..00000000 --- a/src/lib/migration.coffee +++ /dev/null @@ -1,53 +0,0 @@ - -exports.defaultLegacyVolume = -> 'resin-data' - -exports.singleToMulticontainerApp = (app) -> - environment = {} - for key of app.env - if !/^RESIN_/.test(key) - environment[key] = app.env[key] - - appId = app.appId - conf = app.config ? {} - newApp = { - appId: appId - commit: app.commit - name: app.name - releaseId: 1 - networks: {} - volumes: {} - } - defaultVolume = exports.defaultLegacyVolume() - newApp.volumes[defaultVolume] = {} - updateStrategy = conf['RESIN_SUPERVISOR_UPDATE_STRATEGY'] ? 'download-then-kill' - handoverTimeout = conf['RESIN_SUPERVISOR_HANDOVER_TIMEOUT'] ? '' - restartPolicy = conf['RESIN_APP_RESTART_POLICY'] ? 'always' - newApp.services = { - '1': { - appId: appId - serviceName: 'main' - imageId: 1 - commit: app.commit - releaseId: 1 - image: app.imageId - privileged: true - networkMode: 'host' - volumes: [ - "#{defaultVolume}:/data" - ], - labels: { - 'io.resin.features.kernel-modules': '1' - 'io.resin.features.firmware': '1' - 'io.resin.features.dbus': '1', - 'io.resin.features.supervisor-api': '1' - 'io.resin.features.resin-api': '1' - 'io.resin.update.strategy': updateStrategy - 'io.resin.update.handover-timeout': handoverTimeout - 'io.resin.legacy-container': '1' - }, - environment: environment - restart: restartPolicy - running: true - } - } - return newApp diff --git a/src/lib/migration.ts b/src/lib/migration.ts new file mode 100644 index 00000000..a0f5895e --- /dev/null +++ b/src/lib/migration.ts @@ -0,0 +1,69 @@ +import * as _ from 'lodash'; + +import { Application } from '../types/application'; + +export const defaultLegacyVolume = () => 'resin-data'; + +export function singleToMulticontainerApp(app: Dictionary): Application { + const environment: Dictionary = {}; + for (const key in app.env) { + if (!/^RESIN_/.test(key)) { + environment[key] = app.env[key]; + } + } + + const { appId } = app; + const conf = app.config != null ? app.config : {}; + const newApp = new Application(); + _.assign(newApp, { + appId, + commit: app.commit, + name: app.name, + releaseId: 1, + networks: {}, + volumes: {}, + }); + const defaultVolume = exports.defaultLegacyVolume(); + newApp.volumes[defaultVolume] = {}; + const updateStrategy = + conf['RESIN_SUPERVISOR_UPDATE_STRATEGY'] != null + ? conf['RESIN_SUPERVISOR_UPDATE_STRATEGY'] + : 'download-then-kill'; + const handoverTimeout = + conf['RESIN_SUPERVISOR_HANDOVER_TIMEOUT'] != null + ? conf['RESIN_SUPERVISOR_HANDOVER_TIMEOUT'] + : ''; + const restartPolicy = + conf['RESIN_APP_RESTART_POLICY'] != null + ? conf['RESIN_APP_RESTART_POLICY'] + : 'always'; + newApp.services = { + // Disable the next line, as this *has* to be a string + // tslint:disable-next-line + '1': { + appId, + serviceName: 'main', + imageId: 1, + commit: app.commit, + releaseId: 1, + image: app.imageId, + privileged: true, + networkMode: 'host', + volumes: [`${defaultVolume}:/data`], + labels: { + 'io.resin.features.kernel-modules': '1', + 'io.resin.features.firmware': '1', + 'io.resin.features.dbus': '1', + 'io.resin.features.supervisor-api': '1', + 'io.resin.features.resin-api': '1', + 'io.resin.update.strategy': updateStrategy, + 'io.resin.update.handover-timeout': handoverTimeout, + 'io.resin.legacy-container': '1', + }, + environment, + restart: restartPolicy, + running: true, + }, + }; + return newApp; +} diff --git a/src/types/application.ts b/src/types/application.ts new file mode 100644 index 00000000..3afac3ef --- /dev/null +++ b/src/types/application.ts @@ -0,0 +1,12 @@ +import { ServiceComposeConfig } from '../compose/types/service'; + +export class Application { + public appId: number; + public commit: string; + public name: string; + public releaseId: number; + public networks: Dictionary; + public volumes: Dictionary; + + public services: Dictionary; +}