Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{AzureContainerApp} fixes Azure/azure-cli-extensions#5743 PermissionError for temp file #5749

Merged
merged 7 commits into from
Jan 16, 2023

Conversation

navba-MSFT
Copy link
Contributor

@navba-MSFT navba-MSFT commented Jan 12, 2023

fixes #5743 PermissionError for temp file

We get the below error When executing az containerapp up without Dockerfile on Windows OS, PermissionError occurs at the ACR task creation step. It seems that temporary files cannot be accessed. This issue can be reproduced on Windows Sandbox also. And it was succeeded to deploy this app from WSL(Ubuntu 22.04) by executing the same command.

  File "C:\Users\WDAGUtilityAccount\.azure\cliextensions\containerapp\azext_containerapp\_up_utils.py", line 407, in run_acr_build
    self.build_container_from_source(image_name, source)
  File "C:\Users\WDAGUtilityAccount\.azure\cliextensions\containerapp\azext_containerapp\_up_utils.py", line 375, in build_container_from_source
    acr_task_create(self.cmd, task_client, task_name, registry_name, context_path="/dev/null", file=task_file.name)
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/task.py", line 137, in acr_task_create
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/task.py", line 292, in create_task_step
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_utils.py", line 266, in get_yaml_template
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\WDAGUT~1\\AppData\\Local\\Temp\\tmpaa2d2k9z'

Since the behavior of NamedTemporaryFile depends on OS. Hence this is failing on windows and works on WSL Ubuntu.
This PR fixes this issue.

This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally?

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
The precondition is to put your code inside this repository and upgrade the version in the pull request but do not modify src/index.json.

 fixes Azure#5743 PermissionError for temp file

We get the below error When executing az containerapp up without Dockerfile on Windows OS, PermissionError occurs at the ACR task creation step.
It seems that temporary files cannot be accessed. This issue can be reproduced on Windows Sandbox also. And it was succeeded to deploy this app from WSL(Ubuntu 22.04) by executing the same command.

```
  File "C:\Users\WDAGUtilityAccount\.azure\cliextensions\containerapp\azext_containerapp\_up_utils.py", line 407, in run_acr_build
    self.build_container_from_source(image_name, source)
  File "C:\Users\WDAGUtilityAccount\.azure\cliextensions\containerapp\azext_containerapp\_up_utils.py", line 375, in build_container_from_source
    acr_task_create(self.cmd, task_client, task_name, registry_name, context_path="/dev/null", file=task_file.name)
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/task.py", line 137, in acr_task_create
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/task.py", line 292, in create_task_step
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_utils.py", line 266, in get_yaml_template
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\WDAGUT~1\\AppData\\Local\\Temp\\tmpaa2d2k9z'
```
@ghost ghost requested a review from yonzhan January 12, 2023 10:21
@ghost ghost added the Auto-Assign Auto assign by bot label Jan 12, 2023
@ghost ghost requested a review from wangzelin007 January 12, 2023 10:21
@ghost ghost assigned zhoxing-ms Jan 12, 2023
@ghost ghost added this to the Jan 2023 (2023-02-07) milestone Jan 12, 2023
@ghost ghost added the ContainerApp label Jan 12, 2023
@ghost ghost requested review from zhoxing-ms and jsntcy January 12, 2023 10:21
@yonzhan
Copy link
Collaborator

yonzhan commented Jan 12, 2023

AzureContainerApp

@horihiro
Copy link

It seems that there is no code for removing the temp file after creating an ACR task. Isn't it needed?

@navba-MSFT
Copy link
Contributor Author

It seems that there is no code for removing the temp file after creating an ACR task. Isn't it needed?

@horihiro Thanks for the suggestion. I have committed the suggestion now. It is currently under review.

@horihiro
Copy link

@navba-MSFT
I think removing the temp file by os.unlink in finally block needs to be located after calling acr_task_create.
# And import os is needed to call os.unlink.

src/containerapp/setup.py Outdated Show resolved Hide resolved
@navba-MSFT
Copy link
Contributor Author

navba-MSFT commented Jan 13, 2023

@Juliehzl Thanks for reviewing this. Your suggestion has been incorporated and the tests are passed. Could you please review and approve once you get a chance ? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot ContainerApp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PermissionError occurs at the creating ACR task step when executing az containerapp up on Windows
5 participants