in src/edge/edgeManager.ts [476:543]
private async addModuleToDeploymentTemplate(templateJson: any, templateFile: string, envFilePath: string,
moduleInfo: ModuleInfo, isTempsensorNeeded: boolean, isDebug: boolean = false): Promise<{ usernameEnv: string, passwordEnv: string }> {
const modules = templateJson.modulesContent.$edgeAgent["properties.desired"].modules;
const routes = templateJson.modulesContent.$edgeHub["properties.desired"].routes;
const runtimeSettings = templateJson.modulesContent.$edgeAgent["properties.desired"].runtime.settings;
if (moduleInfo.moduleTwin) {
templateJson.modulesContent[moduleInfo.moduleName] = moduleInfo.moduleTwin;
}
const address = await Utility.getRegistryAddress(moduleInfo.repositoryName);
let registries = runtimeSettings.registryCredentials;
if (registries === undefined) {
registries = {};
runtimeSettings.registryCredentials = registries;
}
let result = { registries: {}, usernameEnv: undefined, passwordEnv: undefined };
if (!moduleInfo.isPublic) {
result = await this.updateRegistrySettings(address, registries, envFilePath);
}
const imageName = isDebug ? moduleInfo.debugImageName : moduleInfo.imageName;
const createOptions = isDebug ? moduleInfo.debugCreateOptions : moduleInfo.createOptions;
const environmentVariables = moduleInfo.environmentVariables ? moduleInfo.environmentVariables : undefined;
const newModuleSection = {
version: "1.0",
type: "docker",
status: "running",
restartPolicy: "always",
settings: {
image: imageName,
createOptions,
},
env: environmentVariables,
};
modules[moduleInfo.moduleName] = newModuleSection;
if (moduleInfo.routes && moduleInfo.routes.length > 0) {
for (const route of moduleInfo.routes) {
routes[route.name] = route.value;
}
} else {
const newModuleToUpstream = `${moduleInfo.moduleName}ToIoTHub`;
routes[newModuleToUpstream] = `FROM /messages/modules/${moduleInfo.moduleName}/outputs/* INTO $upstream`;
}
if (isTempsensorNeeded) {
const tempSensor = {
version: "1.0",
type: "docker",
status: "running",
restartPolicy: "always",
settings: {
image: `mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:${Versions.tempSensorVersion()}`,
createOptions: {},
},
};
modules.SimulatedTemperatureSensor = tempSensor;
const tempSensorToModule = `sensorTo${moduleInfo.moduleName}`;
routes[tempSensorToModule] =
`FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/${moduleInfo.moduleName}/inputs/input1\")`;
}
await fse.writeFile(templateFile, JSON.stringify(templateJson, null, 2), { encoding: "utf8" });
return {
usernameEnv: result.usernameEnv,
passwordEnv: result.passwordEnv,
};
}