Azure / azure-cli

Azure Command-Line Interface
MIT License
3.98k stars 2.96k forks source link

"az acr build" failed, but "docker build" successful with the same source #20413

Closed caiwan-msft closed 1 year ago

caiwan-msft commented 2 years ago

[Enter feedback here]

Issue: "az acr build" failed, but "docker build" successful with the same source

Errors:
Step 11/16 : RUN dotnet publish --no-restore -c Release -o /app ---> Running in 3162c0aeebfc Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly. [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: NuGet.Packaging.Core.PackagingException : Unable to find fallback package folder 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'. [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at NuGet.Packaging.FallbackPackagePa thResolver..ctor(String userPackageFolder, IEnumerable1 fallbackPackageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver..ctor(String userPackageFolder, IEnumerable1 fallbackPackageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver.CreateResolver(IEnumerable`1 packageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver.CreateResolver(LockFile lockFile) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheReader..ctor(ResolvePackageAssets task) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.ReadItemGroups() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.ExecuteCore() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBas e.Execute() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecu tionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuild er.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExec uteTask) [/src/Api/Api.csproj] The command '/bin/sh -c dotnet publish --no-restore -c Release -o /app' returned a non-zero code: 1 2021/11/18 12:36:42 Container failed during run: build. No retries remaining. failed to run step ID: build: exit status 1

Run ID: fb1 failed after 29s. Error: failed during run, err: exit status 1 Run failed

(Please refer to the attached 'az_acr_build_failures.txt' for details. )

root@philUbuntu1804:~/AzureAcrContainer/src# az version { "azure-cli": "2.22.0", "azure-cli-core": "2.22.0", "azure-cli-telemetry": "1.0.6", "extensions": {} }

How to reproduce it:
1) Decompress the attached package 'AzureAcrContainer.zip' and upload to your Linux machine with az cli installed.
2) Run command as below: az cloud set -n AzureChinaCloud az login az acr login -n "'your azure container registry'"

cd ~/AzureAcrContainer/src az acr build --registry "'your azure container registry'" --file Dockerfile --image ssmr/api-test:0.1.8 ./ You will see the errors pasted above and also attached.

Comparison test:

  1. docker build -t aa:v1.1 ./ It executes successfully without any errors.
  2. Delete '--no-restore' option in Dockerfile, and then run 'az acr build --registry "'your azure container registry'" --file Dockerfile --image ssmr/api-test:0.1.8 ./'. image

It will also successful without any errors.

Please PG help check:

  1. Why does the az acr build failure occur? (Also tried on az ali 2.30.0, it also failed. )
  2. Please tell the difference between 'az acr build' and 'docker build' in underlying mechanisms.

Document Details

AzureAcrContainer.zip az_acr_build_failures.txt

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ghost commented 2 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @toddysm, @luisdlp, @northtyphoon.

Issue Details
[Enter feedback here] Issue: "az acr build" failed, but "docker build" successful with the same source **Errors:** Step 11/16 : RUN dotnet publish --no-restore -c Release -o /app ---> Running in 3162c0aeebfc Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Copyright (C) Microsoft Corporation. All rights reserved. /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly. [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: NuGet.Packaging.Core.PackagingException : Unable to find fallback package folder 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'. [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at NuGet.Packaging.FallbackPackagePa thResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver.CreateResolver(IEnumerable`1 packageFolders) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.NuGetPa ckageResolver.CreateResolver(LockFile lockFile) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.CacheReader..ctor(ResolvePackageAssets task) [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.ReadItemGroups() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.Resolve PackageAssets.ExecuteCore() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBas e.Execute() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecu tionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/Api/Api.csproj] /usr/share/dotnet/sdk/5.0.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuild er.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExec uteTask) [/src/Api/Api.csproj] The command '/bin/sh -c dotnet publish --no-restore -c Release -o /app' returned a non-zero code: 1 2021/11/18 12:36:42 Container failed during run: build. No retries remaining. failed to run step ID: build: exit status 1 Run ID: fb1 failed after 29s. Error: failed during run, err: exit status 1 Run failed (Please refer to the attached 'az_acr_build_failures.txt' for details. ) root@philUbuntu1804:~/AzureAcrContainer/src# **az version** { "azure-cli": "2.22.0", "azure-cli-core": "2.22.0", "azure-cli-telemetry": "1.0.6", "extensions": {} } How to reproduce it: 1) Decompress the attached package 'AzureAcrContainer.zip' and upload to your Linux machine with az cli installed. 2) Run command as below: _az cloud set -n AzureChinaCloud az login az acr login -n "'your azure container registry'"_ cd ~/AzureAcrContainer/src _az acr build --registry "'your azure container registry'" --file Dockerfile --image ssmr/api-test:0.1.8 ./_ You will see the errors pasted above and also attached. Comparison test: 1. docker build -t aa:v1.1 ./ It executes successfully without any errors. 2. Delete '--no-restore' option in Dockerfile, and then run 'az acr build --registry "'your azure container registry'" --file Dockerfile --image ssmr/api-test:0.1.8 ./'. ![image](https://user-images.githubusercontent.com/8428301/142430142-58a684b3-963e-4ac3-bb72-0a2f6a00b3cd.png) It will also successful without any errors. Please PG help check: 1. Why does the az acr build failure occur? (Also tried on az ali 2.30.0, it also failed. ) 2. Please tell the difference between 'az acr build' and 'docker build' in underlying mechanisms. --- #### Document Details [AzureAcrContainer.zip](https://github.com/Azure/azure-cli/files/7563398/AzureAcrContainer.zip) [az_acr_build_failures.txt](https://github.com/Azure/azure-cli/files/7563399/az_acr_build_failures.txt) ⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.* * ID: c608162e-cf40-9d53-da4a-51f51a0311ea * Version Independent ID: eccbb543-be68-7de2-d41d-abee55c81452 * Content: [az acr](https://docs.microsoft.com/en-us/cli/azure/acr?view=azure-cli-latest) * Content Source: [latest/docs-ref-autogen/acr.yml](https://github.com/MicrosoftDocs/azure-docs-cli/blob/master/latest/docs-ref-autogen/acr.yml) * Service: **container-registry** * GitHub Login: @rloutlaw * Microsoft Alias: **routlaw**
Author: caiwan-msft
Assignees: -
Labels: `Service Attention`, `Container Registry`
Milestone: -
yonzhan commented 2 years ago

route to service team

caiwan-msft commented 2 years ago

Hi @yonzhan and @service team,
May I have an update about this issue? Thanks.

yonzhan commented 2 years ago

container registry service team could help with

huanwu commented 2 years ago

@caiwan-msft Could you add bin and obj directories into .dockerignore file to avoid the lingering files and try again?

northtyphoon commented 2 years ago

@caiwan-msft specifically you need to change src/.dockerignore file in the sample project and remove the trailing slash. It will make az acr build ignore the corresponding folders when package and upload for build.

**/bin/
**/obj/

to

**/bin
**/obj
caiwan-msft commented 2 years ago

Thank you for your reply and confirmation, and I will have a try and then give you the result.

BTW, why does 'docker build' succeeds, but 'az acr build' fails? What' s the difference between 'az acr build' and 'docker build' in underlying mechanisms?

caiwan-msft commented 2 years ago

Verified solution successfully.

root@philUbuntu1804:~ / AzureAcrContainer/src# cat .dockerignore .dockerignore .env .git .gitignore .vs .vscode docker-compose.yml .md hosts LICENSE *.testsettings /bin /obj /node_modules/ /bower_components/ /wwwroot/lib/ global.json /appsettings.localhost.json packages/ root@philUbuntu1804: ~ /AzureAcrContainer# cd src/ root@philUbuntu1804:~/AzureAcrContainer/src# ls Api AzureAcrContainer.sln Dockerfile root@philUbuntu1804:~/AzureAcrContainer/src# az acr login -n philtestacr Login Succeeded root@philUbuntu1804:~/AzureAcrContainer/src# az acr build --registry philtestacr --file Dockerfile --image ssmr/api-test:0.1.9 ./ Packing source code into tar to upload... Uploading archived source code from '/tmp/build_archive_d67aa841d1134d9db905959a70f541d5.tar.gz'... Sending context (2.967 KiB) to registry: philtestacr... Queued a build with ID: fb3 Waiting for an agent... 2021/11/26 01:42:13 Downloading source code... 2021/11/26 01:42:14 Finished downloading source code 2021/11/26 01:42:14 Using acb_vol_b38a8ceb-f60e-4f5c-892b-24a8536c3b8e as the home volume 2021/11/26 01:42:14 Setting up Docker configuration... 2021/11/26 01:42:15 Successfully set up Docker configuration 2021/11/26 01:42:15 Logging in to registry: philtestacr.azurecr.cn 2021/11/26 01:42:15 Successfully logged into philtestacr.azurecr.cn 2021/11/26 01:42:15 Executing step ID: build. Timeout(sec): 28800, Working directory: '', Network: '' 2021/11/26 01:42:15 Scanning for dependencies... 2021/11/26 01:42:16 Successfully scanned dependencies 2021/11/26 01:42:16 Launching container with name: build Sending build context to Docker daemon 20.99kB Step 1/16 : FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base 5.0: Pulling from dotnet/aspnet a10c77af2613: Pulling fs layer f4a871514cd9: Pulling fs layer 5701e2369bef: Pulling fs layer 73d52259e7cd: Pulling fs layer 3cc26497b473: Pulling fs layer 73d52259e7cd: Waiting 3cc26497b473: Waiting f4a871514cd9: Verifying Checksum f4a871514cd9: Download complete a10c77af2613: Verifying Checksum a10c77af2613: Download complete 5701e2369bef: Verifying Checksum 5701e2369bef: Download complete 73d52259e7cd: Verifying Checksum 73d52259e7cd: Download complete 3cc26497b473: Verifying Checksum 3cc26497b473: Download complete a10c77af2613: Pull complete f4a871514cd9: Pull complete 5701e2369bef: Pull complete 73d52259e7cd: Pull complete 3cc26497b473: Pull complete Digest: sha256:8550452e9c42ce045d642860eef636598274aab606506eb7cba071e4b6bd4976 Status: Downloaded newer image for mcr.microsoft.com/dotnet/aspnet:5.0 ---> b63a25852a66 Step 2/16 : WORKDIR /app ---> Running in 2e995db65879 Removing intermediate container 2e995db65879 ---> 78464d162ca6 Step 3/16 : EXPOSE 80 ---> Running in 3847b1f92e27 Removing intermediate container 3847b1f92e27 ---> e37d77d966a4 Step 4/16 : FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build 5.0: Pulling from dotnet/sdk a10c77af2613: Already exists f4a871514cd9: Already exists 5701e2369bef: Already exists 73d52259e7cd: Already exists 3cc26497b473: Already exists 324c8cc708b3: Pulling fs layer ab8d1a2a0d87: Pulling fs layer 1abaaa8b3390: Pulling fs layer 1abaaa8b3390: Verifying Checksum 1abaaa8b3390: Download complete 324c8cc708b3: Verifying Checksum 324c8cc708b3: Download complete ab8d1a2a0d87: Verifying Checksum ab8d1a2a0d87: Download complete 324c8cc708b3: Pull complete ab8d1a2a0d87: Pull complete 1abaaa8b3390: Pull complete Digest: sha256:b2f3f15ee6100efdd36819a429b75d936e4be71bb2487cc48223554f08e11285 Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:5.0 ---> 326ee605795b Step 5/16 : WORKDIR /src ---> Running in beffb1921287 Removing intermediate container beffb1921287 ---> e555b1ff80a9 Step 6/16 : COPY "AzureAcrContainer.sln" "AzureAcrContainer.sln" ---> 8a41aeb625c8 Step 7/16 : COPY "Api/Api.csproj" "Api/Api.csproj" ---> 0694d1365d91 Step 8/16 : RUN dotnet restore "AzureAcrContainer.sln" ---> Running in 339524b4ae34 Determining projects to restore... Restored /src/Api/Api.csproj (in 2.67 sec). Removing intermediate container 339524b4ae34 ---> a73a51ac6f9f Step 9/16 : COPY . . ---> cd7bd67f91db Step 10/16 : WORKDIR /src/Api ---> Running in b10548ee4f52 Removing intermediate container b10548ee4f52 ---> c00a9b473f41 Step 11/16 : RUN dotnet publish -c Release -o /app ---> Running in 031fc10112c5 Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... All projects are up-to-date for restore. Api -> /src/Api/bin/Release/net5.0/Api.dll Api -> /app/ Removing intermediate container 031fc10112c5 ---> 14be219dd2b4 Step 12/16 : FROM build AS publish ---> 14be219dd2b4 Step 13/16 : FROM base AS final ---> e37d77d966a4 Step 14/16 : WORKDIR /app ---> Running in b85a8b9dafb6 Removing intermediate container b85a8b9dafb6 ---> 9e93ce96d89a Step 15/16 : COPY --from=publish /app . ---> 3c81ac1d6167 Step 16/16 : ENTRYPOINT ["dotnet", "Api.dll"] ---> Running in 403085287eae Removing intermediate container 403085287eae ---> acb32ef9361c Successfully built acb32ef9361c Successfully tagged philtestacr.azurecr.cn/ssmr/api-test:0.1.9 2021/11/26 01:42:48 Successfully executed container: build 2021/11/26 01:42:48 Executing step ID: push. Timeout(sec): 3600, Working directory: '', Network: '' 2021/11/26 01:42:48 Pushing image: philtestacr.azurecr.cn/ssmr/api-test:0.1.9, attempt 1 The push refers to repository [philtestacr.azurecr.cn/ssmr/api-test] a64495455d6a: Preparing 23dea7984588: Preparing 9484b524d86a: Preparing 63030c407567: Preparing 0d581923e9dc: Preparing a39150e53df4: Preparing 77b323d4ec74: Preparing a39150e53df4: Waiting 77b323d4ec74: Waiting 63030c407567: Layer already exists 9484b524d86a: Layer already exists 0d581923e9dc: Layer already exists a39150e53df4: Layer already exists 77b323d4ec74: Layer already exists a64495455d6a: Pushed 23dea7984588: Pushed 0.1.9: digest: sha256:865a965fa84fd0cd70a19fcd5b40090357470b9b34ea2b7fea8c146ab3f4c47e size: 1788 2021/11/26 01:42:55 Successfully pushed image: philtestacr.azurecr.cn/ssmr/api-test:0.1.9 2021/11/26 01:42:55 Step ID: build marked as successful (elapsed time in seconds: 32.451211) 2021/11/26 01:42:55 Populating digests for step ID: build... 2021/11/26 01:42:57 Successfully populated digests for step ID: build 2021/11/26 01:42:57 Step ID: push marked as successful (elapsed time in seconds: 7.431271) 2021/11/26 01:42:57 The following dependencies were found: 2021/11/26 01:42:57

Run ID: fb3 was successful after 44s

caiwan-msft commented 2 years ago

Hi @huanwu and @northtyphoon ,
Thank you both help on this issue.

In my opinion, there should be no difference between '/bin/' and '/bin'.

May I know what is the reason of the solution, just the difference between '/bin/' and '/bin' in this issue here?
Thanks.

caiwan-msft commented 2 years ago

Get reply from @northtyphoon : 'az acr build' doesn't support trailing slash in the ignore. It' s just the restriction of 'az acr build'.

Thanks.

rayoef commented 1 year ago

Thank you for commenting on the documentation! This issue appears to be addressed.

please-close