microsoft / vscode-docker

Docker Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
Other
1.19k stars 508 forks source link

Docker Extension generates ASP.NET Core Dockerfile with $BUILDPLATFORM Which is not Recognized by Azure Container Registry #4149

Closed simonkurtz-MSFT closed 8 months ago

simonkurtz-MSFT commented 8 months ago

Does this issue occur when all extensions are disabled?: No, but it's a Microsoft extension for which I am filing the issue.

Steps to Reproduce:

  1. From a VS Code terminal, generate a new Web Api: dotnet new webapi -o Foo
  2. Press CTRL + SHIFT +P, select "Docker: Add Docker Files to Workspace..."
  3. Select ".NET: ASP.NET Core"
  4. Select "Linux"
  5. Select any port.
  6. Select "No" for optional Docker Compose files.
  7. This generates a Dockerfile with FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
  8. Create an Azure Container Registry and attempt a build:
$RANDOM_STRING=-join ((97..122) + (48..57) | Get-Random -Count 6 | ForEach-Object { [char]$_})
$RESOURCE_GROUP="rg-$RANDOM_STRING"
$LOCATION="eastus"
$AZURE_CONTAINER_REGISTRY_NAME="cr$RANDOM_STRING"

az group create `
--name $RESOURCE_GROUP `
--location "$LOCATION"

az acr create `
--resource-group $RESOURCE_GROUP `
--name $AZURE_CONTAINER_REGISTRY_NAME `
--sku Basic `
--admin-enabled true

az acr build `
--registry $AZURE_CONTAINER_REGISTRY_NAME `
--image "foo" `
--file 'Foo/Dockerfile' .

Observe the following error:

unable to understand line FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
failed to run step ID: build: failed to scan dependencies: exit status 1

Run ID: ca1 failed after 3s. Error: failed during run, err: exit status 1
Run failed

Given that the ASP.NET Core image is a multi-platform image, the build image makes sense as it tailors to the architecture upon which it is executing the build. What I can't quite make sense of is how to best marry this with a build that is done in Azure Container Registry. This may well not be something that the extension can address, but I am filing it here as a first start since that's where it originates. What should be the appropriate path to generate a Dockerfile with the extension and subsequently run it in ACR?

Mitigations

simonkurtz-MSFT commented 8 months ago

For a little more context, we are using the aforementioned approach with the workaround in our Azure Container Apps with .NET Workshop, which is a freely available workshop for anyone who wants to learn Azure Container Apps.

bamurtaugh commented 8 months ago

Thanks for opening!

No, but it's a Microsoft extension for which I am filing the issue.

Which extension? We'll want to move this to whichever extension repo, i.e. https://github.com/microsoft/vscode-remote-release/issues if you're having trouble with the Dev Containers extension, or https://github.com/microsoft/vscode-docker for the Docker extension.

simonkurtz-MSFT commented 8 months ago

Hi @bamurtaugh, thank you! I think it would be appropriate in the vscode-docker repo. Could I ask you to transfer it, please?

simonkurtz-MSFT commented 8 months ago

The trouble is that when Linux is selected, --platform=$BUILDPLATFORM is included. That may work on someone's local machine, but when it gets sent up to Azure Container Registry for a build, it fails as it is not set there.

[https://github.com/microsoft/vscode-docker/blob/0c33ed0670c0bce3da56933ba9578fb834f82aea/resources/templates/netCore/Dockerfile.template#L29]

bamurtaugh commented 8 months ago

Transferred! And assigning Christof and myself (as we work on the Dev Containers extension).

bwateratmsft commented 8 months ago

BUILDPLATFORM is set by Docker during build so it might be worth asking ACR to do the same.

simonkurtz-MSFT commented 8 months ago

@bwateratmsft, makes sense to me. Is that something you all can facilitate with the ACR team by way of an issue? Might be more impactful coming from the PG.

bwateratmsft commented 8 months ago

Looks like this is already known by the ACR team; https://github.com/Azure/acr/issues/697 and https://github.com/Azure/acr-builder/issues/449. We'll see if we can draw more attention to it.

simonkurtz-MSFT commented 8 months ago

@bwateratmsft, thank you! Our workaround at this time is to simply remove --platform=$BUILDPLATFORM.

bwateratmsft commented 8 months ago

We'll close this issue since it doesn't look like there are any changes on our side to make. @fiveisprime is going to follow up with the ACR team to work on prioritizing this.

simonkurtz-MSFT commented 8 months ago

[like] Simon Kurtz reacted to your message:


From: Brandon Waterloo [MSFT] @.> Sent: Wednesday, November 8, 2023 7:40:09 PM To: microsoft/vscode-docker @.> Cc: Author @.>; Comment @.> Subject: Re: [microsoft/vscode-docker] Docker Extension generates ASP.NET Core Dockerfile with $BUILDPLATFORM Which is not Recognized by Azure Container Registry (Issue #4149)

We'll close this issue since it doesn't look like there are any changes on our side to make. @fiveisprimehttps://github.com/fiveisprime is going to follow up with the ACR team to work on prioritizing this.

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/vscode-docker/issues/4149#issuecomment-1802535350 or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUHBQRJN4FZSRSHFFUJZYLDYDPNZVBFKMF2HI4TJMJ2XIZLTSWBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIYTANRVGE4DKOJZGCSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRRGE4TQMBVHA2TONNENZQW2ZNJNBQXGX3MMFRGK3FMON2WE2TFMN2F65DZOBS2YSLTON2WKQ3PNVWWK3TUUZ2G64DJMNZZJAVEOR4XAZNKOJSXA33TNF2G64TZUV3GC3DVMWUDINBUGE2TINRZQKSHI6LQMWSWS43TOVS2K5TBNR2WLKRRHE3TKMJYHE2DAMMCUR2HS4DFUVWGCYTFNSSXMYLMOVS2UMJQGY2TCOBVHE4TBAVEOR4XAZNFNRQWEZLMUV3GC3DVMWVDCMJZHAYDKOBVG422O5DSNFTWOZLSUZRXEZLBORSQ. You are receiving this email because you authored the thread.

Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.