azure-dev icon indicating copy to clipboard operation
azure-dev copied to clipboard

Service build phase doesn't support mixed language services

Open aaronpowell opened this issue 3 years ago • 2 comments

Output from azd version Run azd version and copy and paste the output here:

azd version 0.2.0-beta.2 (commit bdd2dfe1f31494642145e4383bc50a2818559e2c)

Output from az version Run az version and copy and paste the output here (minimum required version is 2.38.0):

{
  "azure-cli": "2.40.0",
  "azure-cli-core": "2.40.0",
  "azure-cli-telemetry": "1.0.8",
  "extensions": {}
}

Describe the bug I have a project that is an Azure Static Web App that deploys to the free tier and as such, uses the provided Azure Functions backend.

When you run a azd up or azd deploy it will fail to deploy as the API doesn't get built (the API is a dotnet Azure Functions, the UI is TypeScript/React).

My assumption is that because it looks at the language of the service and then runs a generic build command (in this case npm run build) it doesn't understand mixed language services.

To Reproduce

  1. Clone the sample repo:

    git clone https://github.com/newpatiente2e/Contoso-New-Patient-App.git contoso_new_patient_app
    
  2. Open the repo in VS Code and reload using a devcontainer

  3. From the terminal run azd init, answer the questions to setup an environment

  4. Deploy with azd up

When attempting to deploy it'll fail because:

✖ The provided API folder /workspaces/new-patient-e2e/src/api/bin/Release/net6.0/publish does not exist. Abort.

This is because the user hasn't run dotnet publish against the API.

Expected behavior When azd up is deployed it'll deploy.

I'd like some way that I can control the "build" phase of the CLI, or completely omit it from azd up/deploy.

Workaround The workaround that we need is to add swa build as a step before they run azd up (or azd deploy later in the workshop) to ensure the codebase is built correctly before deploying.

aaronpowell avatar Oct 18 '22 05:10 aaronpowell

@aaronpowell can you share your azure.yaml file?

rajeshkamal5050 avatar Oct 18 '22 16:10 rajeshkamal5050

I just realised I put the wrong git repo in the issue, it should have been https://github.com/newpatiente2e/Contoso-New-Patient-App.git, which has the azd stuff.

Here's the azure.yaml - https://github.com/newpatiente2e/Contoso-New-Patient-App/blob/main/azure.yaml, contents are:


name: new-patient-e2e
services:
  web:
    language: ts
    project: "./src"
    host: staticwebapp
    dist: "dist"

aaronpowell avatar Oct 18 '22 20:10 aaronpowell

@wbreza @ellismg @jongio looks like we don't support building and deploying SWA front-end app and API - https://github.com/Azure/azure-dev/blob/main/cli/azd/pkg/tools/swa/swa.go

The SWA build supports it https://azure.github.io/static-web-apps-cli/docs/cli/swa-build/ assuming that the deploy would also support it.

cc @savannahostrowski

rajeshkamal5050 avatar Oct 26 '22 04:10 rajeshkamal5050

Deployment works, because it uses swa deploy and if you have a swa CLI config file, the settings there will override the command line arguments that are provided by azd when you do a deploy.

Unfortunately, the build phase doesn't use swa build, it goes more generic and uses npm build

aaronpowell avatar Oct 26 '22 04:10 aaronpowell

Closing this in favor of #837 which is also a similar request

rajeshkamal5050 avatar Oct 26 '22 05:10 rajeshkamal5050

I agree it's similar, but it's not just for SWA, it's for any project where you might need to do something across a few languages, say an AppService deployment that has a dotnet backend and compile-to-JS frontend (without a container).

Having no control over the "build" aspect does make a complex build more challenging to use.

aaronpowell avatar Oct 26 '22 05:10 aaronpowell

@aaronpowell - Can you provide an example of this not working outside of the context of SWA? I'm wondering, because our Todo templates do mix langs - so I feel like I'm missing something.

jongio avatar Oct 31 '22 15:10 jongio

@aaronpowell - Can you provide an example of this not working outside of the context of SWA? I'm wondering, because our Todo templates do mix langs - so I feel like I'm missing something.

An AppService deployment is a prime candidate for this. Let's say you have an aspnet core web app that uses some JavaScript to enhance the in-browser experience. It's not a SPA, as a SPA doesn't always make sense, it's just a single web app deployment that needs to build both aspnet and a JS bundle.

You'd have a single service definition, web, and running azd deploy --service web will result in it only building one of the runtimes.

aaronpowell avatar Oct 31 '22 22:10 aaronpowell

Could you provide a code example of that? Thanks

jongio avatar Nov 01 '22 16:11 jongio

Do you have a sample that does that?

jongio avatar Nov 08 '22 23:11 jongio

I don't have a sample, the scenario is a hypothetical, based on the sort of thing I'd commonly come across when I was consulting (in my pre-Microsoft days).

I reached out to the aspnet folks to see if they had any insights on this scenario, relative to the usage of the SPA Templates (which are ones that will do the npm pipeline as part of the dotnet build). It seems a bit mixed on their usage, but there's unlikely enough data to categorize it as a commonly hit problem.

So with that in mind, I'll close it for now.

aaronpowell avatar Nov 09 '22 00:11 aaronpowell

Do you have a sample that does that?

@jongio @aaronpowell https://github.com/MicrosoftDocs/mslearn-staticwebapp-api was the sample referenced by @manekinekko on a similar request with #837

rajeshkamal5050 avatar Nov 09 '22 03:11 rajeshkamal5050