Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
bbaee5f
Adding patch list
harryli0108 May 4, 2023
5419d8e
Added patch list command
snehapar9 May 4, 2023
9f425d8
Revert thumbprint arg
snehapar9 May 4, 2023
1d8078a
Fix bugs
harryli0108 May 4, 2023
9af1fc8
Merge branch 'snehapar/patch-list' into patchList
snehapar9 May 4, 2023
04f21ed
Merge pull request #1 from harryli0108/patchList
snehapar9 May 4, 2023
1821286
Integrated with Harry
snehapar9 May 4, 2023
2b5cb59
Merge pull request #1 from snehapar9/snehapar/patch-list
daniv-msft May 5, 2023
1a607e9
Use buildpacks for 'az containerapp up --source' no Dockerfile scenario
cormacpayne May 5, 2023
3fb96b9
Merge branch 'main' into corm/containerapp-up-buildpack
cormacpayne May 5, 2023
e46dd23
Merge pull request #2 from cormacpayne/corm/containerapp-up-buildpack
daniv-msft May 5, 2023
e373062
Fixed bug
snehapar9 May 5, 2023
0730384
Merge pull request #3 from snehapar9/snehapar/patch-list
daniv-msft May 5, 2023
eae2a49
Fixed command usage text
snehapar9 May 5, 2023
2655993
Merge pull request #4 from snehapar9/snehapar/patch-list
daniv-msft May 5, 2023
a3201dc
Add warning when Docker client cannot be instantiated
cormacpayne May 5, 2023
7deac82
Update dev fork with latest changes (#1)
harryli0108 May 8, 2023
2f8316b
Updated data structure
harryli0108 May 8, 2023
ac8b467
Update image tag parsing to determine rebase
harryli0108 May 8, 2023
6a15d25
Remove temp bom.json
harryli0108 May 8, 2023
733ac82
Adding patch run command
harryli0108 May 8, 2023
44371f1
Made managed env optional
snehapar9 May 8, 2023
9ba04df
Fixed identation
snehapar9 May 8, 2023
fd55c59
Fixed identation
snehapar9 May 8, 2023
3a5f808
Merge branch 'snehapar/test-branch' into test
harryli0108 May 8, 2023
4ee1946
Merge branch 'snehapar/test-branch' into test
harryli0108 May 8, 2023
ee786b5
Merge pull request #2 from harryli0108/test
snehapar9 May 8, 2023
a87ee0a
Updated patch run command
harryli0108 May 8, 2023
0d67583
Fixed bugs when running patch run
harryli0108 May 9, 2023
9556936
Removed debug print statement
harryli0108 May 9, 2023
01ec69a
Made env optional
snehapar9 May 9, 2023
f00eba5
Merge pull request #3 from harryli0108/main
snehapar9 May 9, 2023
5e075ec
- Use latest runtime tag from MCR for 'pack build'
cormacpayne May 9, 2023
6a17a94
Merge branch 'snehapar/patch-list' into snehapar/test-branch
snehapar9 May 9, 2023
dba30cc
Resolve feedback comments
cormacpayne May 9, 2023
1a32460
Merge pull request #5 from cormacpayne/corm/containerapp-up-buildpack
daniv-msft May 9, 2023
feaad1e
Stream output of 'pack build' to warning stream
cormacpayne May 10, 2023
cfb5fe2
Remove patch list
snehapar9 May 10, 2023
a4c81ae
Remove patch list + make managed env optional (#3)
snehapar9 May 10, 2023
eca488e
Update help text for patch list and patch run
snehapar9 May 10, 2023
f75be55
Modified help text
snehapar9 May 11, 2023
d6aa33d
Merge branch 'main' into snehapar/test-branch
snehapar9 May 11, 2023
d1f890b
Made resouce group optional
snehapar9 May 11, 2023
e20e7de
Merge branch 'snehapar/test-branch' of https://github.com/snehapar9/a…
snehapar9 May 11, 2023
9b3e381
Added custom telemetry
snehapar9 May 11, 2023
398f7ce
Fixed linting errors
snehapar9 May 11, 2023
113cc53
Resolve review feedback
cormacpayne May 11, 2023
5cbaa2f
Modified help text (#4)
snehapar9 May 11, 2023
ebf890c
Cleaned up non-supported platform flow for buildpacks
cormacpayne May 11, 2023
b4a920c
Added multithreading (#5)
harryli0108 May 11, 2023
2271fba
`--show-all` option bug fix
harryli0108 May 11, 2023
27316d5
Merge pull request #6 from cormacpayne/corm/containerapp-up-buildpack
daniv-msft May 11, 2023
84d3fcc
Merge remote-tracking branch 'harry/main' into snehapar/test-branch
snehapar9 May 11, 2023
ca37ef8
Fix merge resolution fails
snehapar9 May 11, 2023
49d747e
Telemetry for patch run
snehapar9 May 11, 2023
68d12fb
Added telemetry for patch apply count
snehapar9 May 11, 2023
6c8effd
Removed revision mode
snehapar9 May 11, 2023
34cfd69
Removed print statement
snehapar9 May 11, 2023
34c4467
Added interactive patch command
harryli0108 May 11, 2023
aabac78
Removed `patch run` interactive step
harryli0108 May 11, 2023
626d461
Quiet rebasing and docker push reduce noise
harryli0108 May 11, 2023
156da83
Merge branch 'main' into snehapar/test-branch
harryli0108 May 11, 2023
75fa8cd
Snehapar/test branch (#6)
snehapar9 May 11, 2023
4e5c1e6
Fixed missing managed env in result
harryli0108 May 11, 2023
2a5edfd
Merge remote-tracking branch 'harry/main' into snehapar/test-branch
snehapar9 May 11, 2023
2f871c8
Fixed merge conflict errors
snehapar9 May 11, 2023
4cfde73
linting
harryli0108 May 11, 2023
fef7b05
Merge branch 'main' into snehapar/test-branch
harryli0108 May 11, 2023
73d250c
Snehapar/test branch (#7)
snehapar9 May 11, 2023
01a00d1
Made changes to record number of patches applied
snehapar9 May 12, 2023
aca924f
Merge branch 'snehapar/test-branch' of https://github.com/snehapar9/a…
snehapar9 May 12, 2023
ffeea7b
Record telemetry if user responded 'y' or id
snehapar9 May 12, 2023
ef9d76d
Fixed linting error
snehapar9 May 12, 2023
b83e04b
Added new line to fix linting errors
snehapar9 May 12, 2023
8b414e8
Fixed linting errors
snehapar9 May 12, 2023
d26a6cf
Merge branch 'snehapar/test-branch' of https://github.com/snehapar9/a…
snehapar9 May 12, 2023
2f964d3
Fixed bug when no rg passed in `patch` and `run`
harryli0108 May 12, 2023
0b3e66f
Merge branch 'main' into snehapar/test-branch
snehapar9 May 12, 2023
8b27fc9
Deleted pack
snehapar9 May 12, 2023
2eb49c6
Merge branch 'snehapar/test-branch' of https://github.com/snehapar9/a…
snehapar9 May 12, 2023
b7d3caa
Snehapar/test branch (#9)
snehapar9 May 12, 2023
02d9f37
Bug fix and change `patch` to `interactive-run`
harryli0108 May 12, 2023
5262603
Linting
harryli0108 May 12, 2023
aae4e4d
Merge branch 'main' into dan-branch-sync
harryli0108 May 12, 2023
bc81d0f
Removed telemetry to count patches
snehapar9 May 12, 2023
5b2150b
Temp remove one telemetry due to bug
harryli0108 May 12, 2023
dddbc48
Merge pull request #8 from daniv-msft/dan-branch-sync
daniv-msft May 12, 2023
13a28b8
Various updates to clean the code or smoothen slightly the UX/help text
daniv-msft May 12, 2023
0e3d1cb
Fix for telemetry
snehapar9 May 12, 2023
b33eaae
Added comments
snehapar9 May 12, 2023
3a90ea5
Merge pull request #10 from daniv-msft/snehapar/telemetry
daniv-msft May 12, 2023
647319f
Temp fix using run tag as image tag
harryli0108 May 12, 2023
092d245
Various updates to clean the code or smoothen slightly the UX/help text
daniv-msft May 12, 2023
c7f63ce
Fixed image name matching bug
harryli0108 May 12, 2023
f83756e
Merge branch 'main' into daniv/variousMinorUpdates
daniv-msft May 12, 2023
c67fd7b
Merge pull request #9 from daniv-msft/daniv/variousMinorUpdates
daniv-msft May 12, 2023
a43c9c0
Merge branch 'main' into built-image-tag-fix
daniv-msft May 12, 2023
13c981f
Merge pull request #11 from daniv-msft/built-image-tag-fix
daniv-msft May 12, 2023
fb1d991
Fixed linting errors
snehapar9 May 12, 2023
a7d4632
Merge branch 'main' into snehapar/telemetry
snehapar9 May 12, 2023
82ed69c
Merge pull request #12 from daniv-msft/snehapar/telemetry
daniv-msft May 12, 2023
e3f7241
Update the name of the commands + minor updates
daniv-msft May 12, 2023
def6ad2
Merge pull request #13 from daniv-msft/daniv/variousMinorupdates2
daniv-msft May 12, 2023
a8dddb3
Merge branch 'Azure:main' into main
daniv-msft May 12, 2023
76b81fc
Merge remote-tracking branch 'daniv/main' into snehapar/test-branch
snehapar9 May 12, 2023
85c50f8
- Fix pack CLI not having proper permission
cormacpayne May 15, 2023
8e4c60d
Merge pull request #14 from cormacpayne/corm/misc-containerapp-changes
cormacpayne May 15, 2023
5fb0ecd
Linting
harryli0108 May 15, 2023
f3cb3ed
- Fix pack CLI not having proper permission
cormacpayne May 15, 2023
b58e39e
Merge branch 'main' into harrli/lint-fix
harryli0108 May 15, 2023
ae2cb41
Merge remote-tracking branch 'dan/main' into snehapar/test-branch
snehapar9 May 15, 2023
11ea2b9
Addressed comments
harryli0108 May 15, 2023
084f310
Updated subprocess outputs
harryli0108 May 15, 2023
a470a78
Fixed wrong github issue link
harryli0108 May 15, 2023
fe89d6e
Merge pull request #15 from daniv-msft/harrli/lint-fix
harryli0108 May 15, 2023
8dc3c9f
Removing versions from Docker import
daniv-msft May 15, 2023
4ec3b88
Added examples to help text for patch list
snehapar9 May 15, 2023
d19d7b2
Merge remote-tracking branch 'dan/main' into snehapar/test-branch
snehapar9 May 15, 2023
f62d0ca
Merge branch 'snehapar/test-branch' of https://github.com/snehapar9/a…
snehapar9 May 15, 2023
e5c56a8
Remove need for 'docker' PyPI package
cormacpayne May 15, 2023
7910f4f
Merge branch 'main' of https://github.com/daniv-msft/azure-cli-extens…
cormacpayne May 15, 2023
153ff1d
Merge pull request #16 from cormacpayne/corm/misc-containerapp-changes
daniv-msft May 15, 2023
dd41eb3
Added more examples for patch list
snehapar9 May 15, 2023
87a8515
Modified example with --show-all for patch list
snehapar9 May 15, 2023
a1f46d6
Remove last docker import
daniv-msft May 15, 2023
f668a63
Addressed comments
harryli0108 May 15, 2023
7bfdb87
Merge pull request #17 from daniv-msft/snehapar/miscellaneous
daniv-msft May 16, 2023
3cf452a
Merge pull request #18 from daniv-msft/harrli/lint-fix
daniv-msft May 16, 2023
2ec6850
Fixed linting error
snehapar9 May 16, 2023
5c45d64
Merge pull request #19 from daniv-msft/snehapar/miscellaneous
daniv-msft May 16, 2023
0f513f4
Merge branch 'Azure:main' into main
daniv-msft May 16, 2023
586a839
Addressed PR comments
snehapar9 May 16, 2023
508e957
Merging with remote repo
snehapar9 May 16, 2023
9f0c56b
Merge remote-tracking branch 'dan/snehapar/miscellaneous' into snehap…
snehapar9 May 16, 2023
46bb4ec
Addressed comments in main PR
harryli0108 May 16, 2023
3f499f0
Fixed linting error
snehapar9 May 16, 2023
6c9c0c4
Lint
harryli0108 May 16, 2023
855f595
Fixed linting errors
snehapar9 May 16, 2023
1ae51f8
Addressed PR comment
snehapar9 May 16, 2023
6f59090
Merge pull request #21 from daniv-msft/snehapar/miscellaneous
daniv-msft May 16, 2023
c70993d
Updated telemetry method record
harryli0108 May 16, 2023
2fde4a0
Merge pull request #20 from daniv-msft/harrli/lint-fix
daniv-msft May 16, 2023
befc7f2
Renaming the UserResponse telemetry field to PatchUserResponse
daniv-msft May 16, 2023
c5b62c0
Merge remote-tracking branch 'dan/main' into snehapar/test-branch
snehapar9 May 16, 2023
cec419e
Merge branch 'main' into snehapar/resolve-merge-conflict
snehapar9 May 16, 2023
04cd7e7
Remove one space in the params.py file
daniv-msft May 16, 2023
28efe7d
Remove empty white space
daniv-msft May 16, 2023
ffaf38e
Merge branch 'main' into snehapar/resolve-merge-conflict
daniv-msft May 17, 2023
c1e4413
Addressed PR comments
snehapar9 May 17, 2023
4da6f7c
Merge remote-tracking branch 'dan/snehapar/miscellaneous' into snehap…
snehapar9 May 17, 2023
d2a892c
Merge pull request #22 from daniv-msft/snehapar/miscellaneous
daniv-msft May 17, 2023
4f48733
Addressed comment and fixed bug
harryli0108 May 17, 2023
7914e8e
Merge branch 'snehapar/resolve-merge-conflict' into harrli/lint-fix
harryli0108 May 17, 2023
5d15930
Merge pull request #23 from daniv-msft/harrli/lint-fix
daniv-msft May 17, 2023
020423b
Merge remote-tracking branch 'dan/snehapar/resolve-merge-conflict' in…
snehapar9 May 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/containerapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Temporary folders for shared libraries
azext_containerapp/bin/
azext_containerapp/bin/*
60 changes: 60 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,3 +1329,63 @@
--environment MyContainerappEnv \\
--compose-file-path "path/to/docker-compose.yml"
"""

# Patch commands
helps['containerapp patch'] = """
type: group
short-summary: Patch Azure Container Apps. Patching is only available for the apps built using the source to cloud feature. See https://aka.ms/aca-local-source-to-cloud
"""

helps['containerapp patch list'] = """
type: command
short-summary: List container apps that can be patched. Patching is only available for the apps built using the source to cloud feature. See https://aka.ms/aca-local-source-to-cloud
examples:
- name: List patchable container apps in the current subscription.
text: |
az containerapp patch list
- name: List patchable container apps by resource group.
text: |
az containerapp patch list -g MyResourceGroup
- name: List patchable container apps by managed environment.
text: |
az containerapp patch list -g MyResourceGroup --environment MyContainerAppEnv
- name: List patchable and unpatchable container apps by managed environment with the show-all option.
text: |
az containerapp patch list -g MyResourceGroup --environment MyContainerAppEnv --show-all
"""

helps['containerapp patch apply'] = """
type: command
short-summary: List and apply container apps to be patched. Patching is only available for the apps built using the source to cloud feature. See https://aka.ms/aca-local-source-to-cloud
examples:
- name: List patchable container apps in the current subscription and apply patch.
text: |
az containerapp patch apply
- name: List patchable container apps by resource group and apply patch.
text: |
az containerapp patch apply -g MyResourceGroup
- name: List patchable container apps by managed environment and apply patch.
text: |
az containerapp patch apply -g MyResourceGroup --environment MyContainerAppEnv
- name: List patchable and unpatchable container apps by managed environment with the show-all option and apply patch for patchable container apps.
text: |
az containerapp patch apply -g MyResourceGroup --environment MyContainerAppEnv --show-all
"""

helps['containerapp patch interactive'] = """
type: command
short-summary: List and select container apps to be patched in an interactive way. Patching is only available for the apps built using the source to cloud feature. See https://aka.ms/aca-local-source-to-cloud
examples:
- name: List patchable container apps in the current subscription and apply patch interactively.
text: |
az containerapp patch interactive
- name: List patchable container apps by resource group and apply patch interactively.
text: |
az containerapp patch interactive -g MyResourceGroup
- name: List patchable container apps by managed environment and apply patch interactively.
text: |
az containerapp patch interactive -g MyResourceGroup --environment MyContainerAppEnv
- name: List patchable and unpatchable container apps by managed environment with the show-all option and apply patch for patchable container apps interactively.
text: |
az containerapp patch interactive -g MyResourceGroup --environment MyContainerAppEnv --show-all
"""
28 changes: 28 additions & 0 deletions src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,31 @@
"validationMethod": None # str
}
}

# ContainerApp Patch
ImageProperties = {
"imageName": None,
"targetContainerName": None,
"targetContainerAppName": None,
"revisionMode": None,
}

ImagePatchableCheck = {
"targetContainerAppName": None,
"targetContainerName": None,
"revisionMode": None,
"targetImageName": None,
"oldRunImage": None,
"newRunImage": None,
"id": None,
"reason": None,
}

OryxMarinerRunImgTagProperty = {
"fullTag": None,
"framework": None,
"version": None,
"marinerVersion": None,
"architectures": None,
"support": None,
}
8 changes: 7 additions & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def load_arguments(self, _):
c.argument('name', configured_default='name', id_part=None)
c.argument('managed_env', configured_default='managed_env')
c.argument('registry_server', configured_default='registry_server')
c.argument('source', help='Local directory path containing the application source and Dockerfile for building the container image. Preview: If no Dockerfile is present, a container image is generated using Oryx. See the supported Oryx runtimes here: https://github.com/microsoft/Oryx/blob/main/doc/supportedRuntimeVersions.md.')
c.argument('source', help='Local directory path containing the application source and Dockerfile for building the container image. Preview: If no Dockerfile is present, a container image is generated using buildpacks. If Docker is not running or buildpacks cannot be used, Oryx will be used to generate the image. See the supported Oryx runtimes here: https://github.com/microsoft/Oryx/blob/main/doc/supportedRuntimeVersions.md.')
c.argument('image', options_list=['--image', '-i'], help="Container image, e.g. publisher/image-name:tag.")
c.argument('browse', help='Open the app in a web browser after creation and deployment, if possible.')
c.argument('workload_profile_name', options_list=['--workload-profile-name', '-w'], help='The friendly name for the workload profile')
Expand Down Expand Up @@ -440,3 +440,9 @@ def load_arguments(self, _):
c.argument('workload_profile_type', help="The type of workload profile to update. Run 'az containerapp env workload-profile list-supported -l <region>' to check the options for your region.")
c.argument('min_nodes', help="The minimum node count for the workload profile")
c.argument('max_nodes', help="The maximum node count for the workload profile")

# Patch
with self.argument_context('containerapp patch') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('managed_env', options_list=['--environment', '-e'], help='Name or resource id of the Container App environment.')
c.argument('show_all', action='store_true', help='Show all patchable and unpatchable container apps')
128 changes: 118 additions & 10 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from tempfile import NamedTemporaryFile
from urllib.parse import urlparse
import subprocess
import requests

from azure.cli.core.azclierror import (
Expand Down Expand Up @@ -48,7 +49,11 @@
register_provider_if_needed,
validate_environment_location,
list_environment_locations,
format_location
format_location,
is_docker_running,
get_pack_exec_path,
get_latest_buildpack_run_tag

)

from ._constants import (MAXIMUM_SECRET_LENGTH,
Expand Down Expand Up @@ -354,7 +359,86 @@ def create_acr(self):
self.cmd.cli_ctx, registry_name
)

def build_container_from_source(self, image_name, source):
def build_container_from_source_with_buildpack(self, image_name, source): # pylint: disable=too-many-statements
# Ensure that Docker is running
if not is_docker_running():
raise ValidationError("Docker is not running. Please start Docker to use buildpacks.")

# Ensure that the pack CLI is installed
pack_exec_path = get_pack_exec_path()
if pack_exec_path is None:
raise ValidationError("The pack CLI could not be installed.")

logger.info("Docker is running and pack CLI is installed; attempting to use buildpacks to build container image...")

registry_name = self.registry_server.lower()
image_name = f"{registry_name}/{image_name}"
builder_image_name = "mcr.microsoft.com/oryx/builder:builder-dotnet-7.0"

# Ensure that the builder is trusted
command = [pack_exec_path, 'config', 'default-builder', builder_image_name]
logger.debug(f"Calling '{' '.join(command)}'")
try:
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
_, stderr = process.communicate()
if process.returncode != 0:
raise CLIError(f"Error thrown when running 'pack config': {stderr.decode('utf-8')}")
logger.debug(f"Successfully set the default builder to {builder_image_name}.")
except Exception as ex:
raise ValidationError(f"Unable to run 'pack config' command to set default builder: {ex}") from ex

# Run 'pack build' to produce a runnable application image for the Container App
command = [pack_exec_path, 'build', image_name, '--builder', builder_image_name, '--path', source]
buildpack_run_tag = get_latest_buildpack_run_tag("aspnet", "7.0")
if buildpack_run_tag is not None:
buildpack_run_image = f"mcr.microsoft.com/oryx/builder:{buildpack_run_tag}"
logger.debug(f"Determined the run image to use as {buildpack_run_image}.")
command.extend(['--run-image', buildpack_run_image])

logger.debug(f"Calling '{' '.join(command)}'")
try:
is_non_supported_platform = False
with subprocess.Popen(command, stdout=subprocess.PIPE) as process:

# Stream output of 'pack build' to warning stream
while process.stdout.readable():
line = process.stdout.readline()
if not line:
break

stdout_line = str(line.strip(), 'utf-8')
logger.warning(stdout_line)
if not is_non_supported_platform and "No buildpack groups passed detection" in stdout_line:
is_non_supported_platform = True

# Update the result of process.returncode
process.communicate()
if is_non_supported_platform:
raise ValidationError("Current buildpacks do not support the platform targeted in the provided source code.")

if process.returncode != 0:
raise CLIError("Non-zero exit code returned from 'pack build'; please check the above output for more details.")

logger.debug(f"Successfully built image {image_name} using buildpacks.")
except ValidationError as ex:
raise ex
except Exception as ex:
raise CLIError(f"Unable to run 'pack build' command to produce runnable application image: {ex}") from ex

# Run 'docker push' to push the image to the ACR
command = ['docker', 'push', image_name]
logger.debug(f"Calling '{' '.join(command)}'")
logger.warning(f"Built image {image_name} locally using buildpacks, attempting to push to registry...")
try:
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
_, stderr = process.communicate()
if process.returncode != 0:
raise CLIError(f"Error thrown when running 'docker push': {stderr.decode('utf-8')}")
logger.debug(f"Successfully pushed image {image_name} to ACR.")
except Exception as ex:
raise CLIError(f"Unable to run 'docker push' command to push image to ACR: {ex}") from ex

def build_container_from_source_with_acr_task(self, image_name, source):
from azure.cli.command_modules.acr.task import acr_task_create, acr_task_run
from azure.cli.command_modules.acr._client_factory import cf_acr_tasks, cf_acr_runs
from azure.cli.core.profiles import ResourceType
Expand Down Expand Up @@ -403,19 +487,43 @@ def run_acr_build(self, dockerfile, source, quiet=False, build_from_source=False
image_name = self.image if self.image is not None else self.name
from datetime import datetime

now = datetime.now()
# Add version tag for acr image
image_name += ":{}".format(
str(now).replace(" ", "").replace("-", "").replace(".", "").replace(":", "")
)

self.image = self.registry_server + "/" + image_name
# Creating a tag for the image using the current time to avoid overwriting customer's existing images
now = datetime.now()
tag_now_suffix = str(now).replace(" ", "").replace("-", "").replace(".", "").replace(":", "")

if build_from_source:
# TODO should we prompt for confirmation here?
logger.warning("No dockerfile detected. Attempting to build a container directly from the provided source...")
self.build_container_from_source(image_name, source)

try:
# First try to build source using buildpacks
# Temporary fix: using run time tag as customer image tag
# Waiting for buildpacks side to fix this issue: https://github.com/buildpacks/pack/issues/1750
logger.warning("Attempting to build image using buildpacks...")
run_image_tag = get_latest_buildpack_run_tag("aspnet", "7.0")
if run_image_tag is not None:
image_name = f"{image_name}:{run_image_tag}-{tag_now_suffix}"
self.build_container_from_source_with_buildpack(image_name, source)
self.image = self.registry_server + "/" + image_name
return
except ValidationError as e:
logger.warning(f"Unable to use buildpacks to build image from source: {e}\nFalling back to ACR Task...")
except CLIError as e:
logger.error("Failed to use buildpacks to build image from source.")
raise e

# If we're unable to use the buildpack, build source using an ACR Task
# Moving tagging img to here
# Skipping the buildpacks scenario for now due to issues with buildpacks
# Add version tag for acr image
image_name += ":{}".format(tag_now_suffix)
logger.warning("Attempting to build image using ACR Task...")
self.build_container_from_source_with_acr_task(image_name, source)
else:
# Moving tagging img to here
# Skipping the buildpacks scenario for now due to issues with buildpacks
# Add version tag for acr image
image_name += ":{}".format(tag_now_suffix)
queue_acr_build(
self.cmd,
self.acr.resource_group.name,
Expand Down
Loading