Skip to content

Commit

Permalink
fix(network): apply migrations to imported networks
Browse files Browse the repository at this point in the history
  • Loading branch information
jamaljsr committed May 24, 2023
1 parent c27379d commit ed82b18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/store/models/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ const networkModel: NetworkModel = {
await save();
await injections.dockerService.saveComposeFile(network);

info('imported', network);
info('imported', JSON.stringify({ network, chart }));
return network;
},
),
Expand Down
19 changes: 16 additions & 3 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import {
DockerRepoState,
ManagedImage,
Network,
NetworksFile,
} from 'types';
import { dataPath, networksPath, nodePath } from './config';
import { BasePorts, DOCKER_REPO, dockerConfigs } from './constants';
import { read, rm } from './files';
import { migrateNetworksFile } from './migrations';
import { getName } from './names';
import { range } from './numbers';
import { isVersionCompatible } from './strings';
Expand Down Expand Up @@ -751,10 +753,21 @@ export const importNetworkFromZip = async (
if (!(parsed.chart && isChart(parsed.chart))) {
throw new Error(`${exportFilePath} did not contain a valid chart`);
}
const network = parsed.network as Network;
const chart = parsed.chart as IChart;
const netPath = join(dataPath, 'networks', `${id}`);

debug('Migrating the imported network:\n' + JSON.stringify(parsed));
const networksFile: NetworksFile = {
// the version is not available in the export.json file and is not needed
version: '',
networks: [parsed.network],
charts: {
[parsed.network.id]: parsed.chart,
},
};
const { networks, charts } = migrateNetworksFile(networksFile);

const network = networks[0];
const chart = charts[network.id];
const netPath = join(dataPath, 'networks', `${id}`);
debug(`Updating the network path from '${network.path}' to '${netPath}'`);
network.path = netPath;
debug(`Updating network id to '${id}'`);
Expand Down

0 comments on commit ed82b18

Please sign in to comment.