private static async buildAndPushImageAsync()

in azurecontainerapps.ts [408:456]


    private static async buildAndPushImageAsync() {
        // Get the name of the image to build if it was provided, or generate it from build variables
        this.imageToBuild = this.toolHelper.getInput('imageToBuild', false);

        if (this.util.isNullOrEmpty(this.imageToBuild)) {
            const imageRepository = this.toolHelper.getDefaultImageRepository()
            // Constructs the image to build based on the provided registry URL, image repository,  build ID, and build number.
            this.imageToBuild = `${this.registryUrl}/${imageRepository}:${this.buildId}.${this.buildNumber}`;
            this.toolHelper.writeInfo(`Default image to build: ${this.imageToBuild}`);
        }

        // Get the name of the image to deploy if it was provided, or set it to the value of 'imageToBuild'
        if (this.util.isNullOrEmpty(this.imageToDeploy)) {
            this.imageToDeploy = this.imageToBuild;
            this.toolHelper.writeInfo(`Default image to deploy: ${this.imageToDeploy}`);
        }

        // Get the build arguments to pass to the Dockerfile or builder
        let buildArguments: string[] = [];
        if (!this.util.isNullOrEmpty(this.buildArguments)) {
            this.buildArguments.match(buildArgumentRegex).forEach((buildArg) => {
                buildArguments.push(buildArg);
            });
        }

        // Get Dockerfile to build, if provided, or check if one exists at the root of the provided application
        let dockerfilePath: string = this.toolHelper.getInput('dockerfilePath', false);
        if (this.util.isNullOrEmpty(dockerfilePath)) {
            this.toolHelper.writeInfo(`No Dockerfile path provided; checking for Dockerfile at root of application source.`);
            const rootDockerfilePath = path.join(this.appSourcePath, 'Dockerfile');
            if (fs.existsSync(rootDockerfilePath)) {
                this.toolHelper.writeInfo(`Dockerfile found at root of application source.`)
                dockerfilePath = rootDockerfilePath;
            } else {
                // No Dockerfile found or provided, build the image using the builder
                await this.buildImageFromBuilderAsync(this.appSourcePath, this.imageToBuild, buildArguments);
            }
        } else {
            dockerfilePath = path.join(this.appSourcePath, dockerfilePath);
        }

        if (!this.util.isNullOrEmpty(dockerfilePath)) {
            // Build the image from the provided/discovered Dockerfile
            await this.buildImageFromDockerfile(this.appSourcePath, dockerfilePath, this.imageToBuild, buildArguments);
        }

        // Push the image to the Container Registry
        await this.registryHelper.pushImageToContainerRegistry(this.imageToBuild);
    }