Repository: aws/aws-sam-cli

Issue:
Bug: build error using podman
<!-- Make sure we don't have an existing Issue that reports the bug you are seeing (both open and closed). 
If you do find an existing Issue, re-open or add a comment to that Issue instead of creating a new one. -->

### Description:
<!-- Briefly describe the bug you are facing.-->
Error building image with "docker compatible tool" podman.


### Steps to reproduce:
<!-- Provide detailed steps to replicate the bug, including steps from third party tools (CDK, etc.) -->
Start podman
run `sam build -u`

### Observed result:
<!-- Please provide command output with `--debug` flag set. -->
2023-04-14 10:39:57,621 | Config file location: /<snip>/sam-hello-world/samconfig.toml
2023-04-14 10:39:57,622 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at '/<snip>/sam-hello-world/samconfig.toml'...
2023-04-14 10:39:57,624 | Configuration values successfully loaded.
2023-04-14 10:39:57,624 | Configuration values are: {}
2023-04-14 10:39:57,629 | Using SAM Template at /<snip>/sam-hello-world/template.yaml
2023-04-14 10:39:57,648 | Using config file: samconfig.toml, config environment: default
2023-04-14 10:39:57,648 | Expand command line arguments to:
2023-04-14 10:39:57,648 | --template_file=/<snip>sam-hello-world/template.yaml --use_container --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache 
2023-04-14 10:39:58,377 | 'build' command is called
2023-04-14 10:39:58,377 | Starting Build inside a container
2023-04-14 10:39:58,383 | Collected default values for parameters: {}
2023-04-14 10:39:58,400 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2023-04-14 10:39:58,400 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-04-14 10:39:58,401 | 0 stacks found in the template
2023-04-14 10:39:58,401 | Collected default values for parameters: {}
2023-04-14 10:39:58,410 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2023-04-14 10:39:58,410 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-04-14 10:39:58,410 | 2 resources found in the stack 
2023-04-14 10:39:58,410 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2023-04-14 10:39:58,410 | --base-dir is not presented, adjusting uri hello_world/ relative to /<snip>/sam-hello-world/template.yaml
2023-04-14 10:39:58,414 | 2 resources found in the stack 
2023-04-14 10:39:58,415 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2023-04-14 10:39:58,415 | Instantiating build definitions
2023-04-14 10:39:58,416 | Same function build definition found, adding function (Previous: BuildDefinition(python3.10, /<snip>/sam-hello-world/hello_world, Zip, , aa9be8ec-e101-4712-8496-468de4ca138c, {}, {}, arm64, []), Current: BuildDefinition(python3.10, /<snip>/sam-hello-world/hello_world, Zip, , 4c168b03-f965-47c9-894a-38e54517eb14, {}, {}, arm64, []), Function: Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='python3.10', memory=None, timeout=3, handler='app.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/<snip>/sam-hello-world/hello_world', environment=None, rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['arm64'], function_url_config=None, stack_path='', runtime_management_config=None))
2023-04-14 10:39:58,417 | Building codeuri: /<snip>/sam-hello-world/hello_world runtime: python3.10 metadata: {} architecture: arm64 functions: HelloWorldFunction
2023-04-14 10:39:58,417 | Building to following folder /<snip>/sam-hello-world/.aws-sam/build/HelloWorldFunction
2023-04-14 10:39:58,444 | Failed to download image with name public.ecr.aws/sam/build-python3.10:latest-arm64
2023-04-14 10:39:58,444 | Container was not created. Skipping deletion
2023-04-14 10:39:58,444 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-04-14 10:39:58,445 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-04-14 10:39:58,445 | Unable to find Click Context for getting session_id.

Error: Could not find public.ecr.aws/sam/build-python3.10:latest-arm64 image locally and failed to pull it from docker.
Traceback:
  File "click/core.py", line 1055, in main
  File "click/core.py", line 1657, in invoke
  File "click/core.py", line 1404, in invoke
  File "click/core.py", line 760, in invoke
  File "click/decorators.py", line 84, in new_func
  File "click/core.py", line 760, in invoke
  File "samcli/lib/telemetry/metric.py", line 183, in wrapped
  File "samcli/lib/telemetry/metric.py", line 148, in wrapped
  File "samcli/lib/utils/version_checker.py", line 42, in wrapped
  File "samcli/cli/main.py", line 92, in wrapper
  File "samcli/commands/build/command.py", line 180, in cli
  File "samcli/commands/build/command.py", line 276, in do_cli
  File "samcli/commands/build/build_context.py", line 279, in run
  File "samcli/lib/build/app_builder.py", line 214, in build
  File "samcli/lib/build/build_strategy.py", line 80, in build
  File "samcli/lib/build/build_strategy.py", line 90, in _build_functions
  File "samcli/lib/build/build_strategy.py", line 163, in build_single_function_definition
  File "samcli/lib/build/app_builder.py", line 688, in _build_function
  File "samcli/lib/build/app_builder.py", line 930, in _build_function_on_container
  File "samcli/local/docker/manager.py", line 114, in run
  File "samcli/local/docker/manager.py", line 87, in create

An unexpected error was encountered while executing "sam build".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20build%20-%20DockerImagePullFailedException
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20build%20-%20DockerImagePullFailedException


### Expected result:
<!-- Describe what you expected. -->
The image to build successfully


### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

<!-- Either provide the following info (for AWS SAM CLI v1.68.0 or before) or paste the output of `sam --info` (AWS SAM CLI v1.69.0 or after). -->

1. OS: OS X 13.3.1
2. `sam --version`: SAM CLI, version 1.79.0
3. AWS region: us-west-2

```
{
  "version": "1.79.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-13.3.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "4.4.2",
    "aws_cdk": "2.72.1 (build ddbfac7)",
    "terraform": "1.4.4"
  }
}
```

`Add --debug flag to command you are running`
ok.


Discussion:

Resolving patch:
diff --git a/samcli/local/docker/manager.py b/samcli/local/docker/manager.py
--- a/samcli/local/docker/manager.py
+++ b/samcli/local/docker/manager.py
@@ -142,7 +142,12 @@ def pull_image(self, image_name, tag=None, stream=None):
             If the Docker image was not available in the server
         """
         if tag is None:
-            tag = image_name.split(":")[1] if ":" in image_name else "latest"
+            _image_name_split = image_name.split(":")
+            # Separate the image_name from the tag so less forgiving docker clones
+            # (podman) get the image name as the URL they expect. Official docker seems
+            # to clean this up internally.
+            tag = _image_name_split[1] if len(_image_name_split) > 1 else "latest"
+            image_name = _image_name_split[0]
         # use a global lock to get the image lock
         with self._lock:
             image_lock = self._lock_per_image.get(image_name)


Test patch: