public async getDockerRunOptions()

in src/tasks/node/NodeTaskHelper.ts [107:162]


    public async getDockerRunOptions(context: DockerRunTaskContext, runDefinition: NodeRunTaskDefinition): Promise<DockerRunOptions> {
        const helperOptions = runDefinition.node || {};
        const runOptions = runDefinition.dockerRun;

        const packagePath = NodeTaskHelper.inferPackagePath(helperOptions && helperOptions.package, context.folder);

        const nodePackage = new Lazy<Promise<NodePackage>>(
            async () => {
                return await readPackage(packagePath);
            });

        const packageName = await inferPackageName(await nodePackage.value, packagePath);

        if (runOptions.containerName === undefined) {
            runOptions.containerName = getDefaultContainerName(packageName);
        }

        if (runOptions.image === undefined) {
            runOptions.image = inferImageName(runDefinition as DockerRunTaskDefinition, context, packageName);
        }

        if (helperOptions && helperOptions.enableDebugging) {
            const inspectMode = helperOptions.inspectMode || 'default';
            const inspectPort = helperOptions.inspectPort !== undefined ? helperOptions.inspectPort : 9229;

            if (runOptions.command === undefined) {
                runOptions.command = await inferCommand(await nodePackage.value, inspectMode, inspectPort);
            }

            if (runOptions.ports === undefined) {
                runOptions.ports = [];
            }

            let inspectPortPublished = false;

            // If not already defined, create a mapping for the inspect port between container and host...
            if (runOptions.ports.find(port => port.containerPort === inspectPort) === undefined) {
                runOptions.ports.push({
                    containerPort: inspectPort,
                    // TODO: Can this mapping be dynamic?
                    hostPort: inspectPort
                });

                inspectPortPublished = true;
            }

            // NOTE: By default, if no ports are explicitly published and the options do not say otherwise, all ports will be published.
            //       If we published the inspection port, and it was the only published port, that "publish all" behavior would unintentionally be disabled.
            //       Hence, in that situation, we force "publish all" in addition to the inspection port.
            if (runOptions.portsPublishAll === undefined && inspectPortPublished && runOptions.ports.length === 1) {
                runOptions.portsPublishAll = true;
            }
        }

        return runOptions;
    }