private static async buildImageFromBuilderAsync()

in azurecontainerapps.ts [464:522]


    private static async buildImageFromBuilderAsync(appSourcePath: string, imageToBuild: string, buildArguments: string[]) {
        if (buildArguments.length > 0) {
            buildArguments.forEach((buildArg) => {
                const nameAndValue = buildArg.split('=');
                const isNameValid = nameAndValue[0].match(buildpackEnvironmentNameRegex);
                if (!isNameValid) {
                    const invalidBuildArgumentsMessage = `Build environment variable name must consist of alphanumeric characters, numbers, '_', '.' or '-', start with 'BP_' or 'ORYX_'.`;
                    this.toolHelper.writeError(invalidBuildArgumentsMessage);
                    throw Error(invalidBuildArgumentsMessage);
                }
            });
        }
        // Install the pack CLI
        await this.appHelper.installPackCliAsync();
        this.toolHelper.writeInfo(`Successfully installed the pack CLI.`);

        // Enable experimental features for the pack CLI
        await this.appHelper.enablePackCliExperimentalFeaturesAsync();
        this.toolHelper.writeInfo(`Successfully enabled experimental features for the pack CLI.`);

        // Define the environment variables that should be propagated to the builder
        let environmentVariables: string[] = []

        // Parse the given runtime stack input and export the platform and version to environment variables
        const runtimeStack = this.toolHelper.getInput('runtimeStack', false);
        if (!this.util.isNullOrEmpty(runtimeStack)) {
            const runtimeStackSplit = runtimeStack.split(':');
            const platformName = runtimeStackSplit[0] == "dotnetcore" ? "dotnet" : runtimeStackSplit[0];
            const platformVersion = runtimeStackSplit[1];
            environmentVariables.push(`ORYX_PLATFORM_NAME=${platformName}`);
            environmentVariables.push(`ORYX_PLATFORM_VERSION=${platformVersion}`);
        }

        // Check if the user provided a builder stack to use
        const builderStack = this.toolHelper.getInput('builderStack', false);

        // Set the target port on the image produced by the builder
        if (!this.util.isNullOrEmpty(this.targetPort)) {
            environmentVariables.push(`ORYX_RUNTIME_PORT=${this.targetPort}`);
        }

        // Add user-specified build environment variables
        if (buildArguments.length > 0) {
            buildArguments.forEach((buildArg) => {
                environmentVariables.push(buildArg);
            });
        }

        this.toolHelper.writeInfo(`Building image "${imageToBuild}" using the Oryx++ Builder`);

        // Set the Oryx++ Builder as the default builder locally
        await this.appHelper.setDefaultBuilder();

        // Create a runnable application image
        await this.appHelper.createRunnableAppImage(imageToBuild, appSourcePath, environmentVariables, builderStack);

        // If telemetry is enabled, log that the builder scenario was targeted for this task
        this.telemetryHelper.setBuilderScenario();
    }