private static setupContainerAppProperties()

in azurecontainerapps.ts [547:623]


    private static setupContainerAppProperties() {
        this.commandLineArgs = [];

        // Get the ingress inputs
        this.ingress = this.toolHelper.getInput('ingress', false);
        this.targetPort = this.toolHelper.getInput('targetPort', false);

        // If both ingress and target port were not provided for an existing Container App, or if ingress is to be disabled,
        // use the 'update' command, otherwise we should use the 'up' command that performs a PATCH operation on the ingress properties.
        this.noIngressUpdate = this.containerAppExists &&
            this.util.isNullOrEmpty(this.targetPort) &&
            (this.util.isNullOrEmpty(this.ingress) || this.ingress == 'disabled');

        // Pass the Container Registry credentials when creating a Container App or updating a Container App via the 'up' command
        if (!this.util.isNullOrEmpty(this.registryUrl) && !this.util.isNullOrEmpty(this.registryUsername) && !this.util.isNullOrEmpty(this.registryPassword) &&
            (!this.containerAppExists || (this.containerAppExists && !this.noIngressUpdate))) {
            this.adminCredentialsProvided = true;
            this.commandLineArgs.push(
                `--registry-server ${this.registryUrl}`,
                `--registry-username ${this.registryUsername}`,
                `--registry-password ${this.registryPassword}`);
        }

        // Determine default values only for the 'create' scenario to avoid overriding existing values for the 'update' scenario
        if (!this.containerAppExists) {
            this.ingressEnabled = true;

            // Set the ingress value to 'external' if it was not provided
            if (this.util.isNullOrEmpty(this.ingress)) {
                this.ingress = 'external';
                this.toolHelper.writeInfo(`Default ingress value: ${this.ingress}`);
            }

            // Set the value of ingressEnabled to 'false' if ingress was provided as 'disabled'
            if (this.ingress == 'disabled') {
                this.ingressEnabled = false;
                this.toolHelper.writeInfo(`Ingress is disabled for this Container App.`);
            }

            // Handle setup for ingress values when enabled
            if (this.ingressEnabled) {
                // Get the target port if provided, or set it to the default value
                this.targetPort = this.toolHelper.getInput('targetPort', false);

                // Set the target port to 80 if it was not provided
                if (this.util.isNullOrEmpty(this.targetPort)) {
                    this.targetPort = '80';
                    this.toolHelper.writeInfo(`Default target port: ${this.targetPort}`);
                }

                // Add the ingress value and target port to the optional arguments array
                // Note: this step should be skipped if we're updating an existing Container App (ingress is enabled via a separate command)
                this.commandLineArgs.push(`--ingress ${this.ingress}`);
                this.commandLineArgs.push(`--target-port ${this.targetPort}`);
            }
        }

        const environmentVariables: string = this.toolHelper.getInput('environmentVariables', false);
        const isCappUpdateCommandUsed: boolean = this.noIngressUpdate || (!this.noIngressUpdate && !this.adminCredentialsProvided)
        // Add user-specified environment variables
        if (!this.util.isNullOrEmpty(environmentVariables)) {
            // The --replace-env-vars flag is only used for the 'update' command,
            // otherwise --env-vars is used for 'create' and 'up'
            if (isCappUpdateCommandUsed) {
                this.commandLineArgs.push(`--replace-env-vars ${environmentVariables}`);
            } else {
                this.commandLineArgs.push(`--env-vars ${environmentVariables}`);
            }
        }

        // Ensure '-i' argument and '--source' argument are not both provided
        if (!this.util.isNullOrEmpty(this.imageToDeploy)) {
            this.commandLineArgs.push(`-i ${this.imageToDeploy}`);
        } else if (!this.util.isNullOrEmpty(this.appSourcePath) && this.useInternalRegistry) {
            this.commandLineArgs.push(`--source ${this.appSourcePath}`);
        }
    }