-
Notifications
You must be signed in to change notification settings - Fork 437
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
Prevent npm install for JavaScript functions #6609
Comments
@rudfoss Can you share more details about the build/deploy process you'd like to use? The docs you pointed to probably require a bit of updating as it appears to be specific to deploying to Windows. For now, we can help you figure out what works best for your situation. The first thing to keep in mind is that headless Chromium currently only works in our Linux environments (this was recently added, more info in this blog post here). There are multiple ways to deploy your app, which is why understanding how you want to deploy is important. I've put together a sample app that uses Yarn and will walk you through how to deploy it. Hopefully that'll work with your CI/CD process. If not, we can figure something out. Here's the sample app. I've added a super old version of moment.js (2.0.0) to it and it's in the yarn lockfile. The simplest way to deploy this app is with the Azure Functions Core Tools using remote build. This runs a build in the cloud. In Linux (perhaps Windows as well now), remote build uses Oryx to build apps and it's able to detect and use Yarn for Node projects. To deploy the sample to a Node.js 12 Linux Consumption app, run this command: func azure functionapp publish $APP_NAME -b remote You should see in the output that it noticed yarn.lock and is installing dependencies using Yarn instead of npm.
One way to browse the files after they've been deployed is using the Azure Functions VS Code extension. You can see that yarn correctly used the lockfile to install You should be able to use Core Tools to deploy from your CI/CD pipeline. If you use specific tasks for deploying Azure Functions (like in GitHub Actions or an Azure DevOps), I'm not sure if it's possible to run the build remotely. One potential problem if you're not using remote build is that the execute bit on the Chromium binary might not be set properly. We can help you if you run into this with your deployment method. /cc @ggailey777 on possible doc updates |
Hi @anthonychu! Thanks for getting back to me so quickly. I've read your answer and unfortunately I don't think we can easily rewrite our pipeline to support this. I'll explain our pipeline in more detail: Code structureOur code is structured in a monorepo using
Each package is basically a separate node project with its own // in our azure function:
import { findObject } from "utilities/findObject" This is important because it greatly reduces the need for duplicating functionality and allows us to use strongly typed objects that share an interface between projects. In addition to this our
Each function folder contains a separate azure function with it's own
BuildWe've set up a build script that will build each function using webpack and output a single The builld produces a
The upside of this is that there is no need for a The problem with puppeteerNow we want to build a new function that follows the regimen above. It's only task is to receive a url through a service bus topic message, print a PDF of that url using The problem is that
With this structure it is trivial for us to run The problem with Azure FunctionsNow, because Azure Function deployments look for Our solutionAfter writing this issue yesterday we actually seem to have found a solution for the problem. By moving our
We then run
This is what we zip and deploy. Now since the process.chdir(__dirname) This alters the const browser = await puppeteer.launch() to start the browser and do our thing. This became a really long post, but hopefully it clears up why we have this issue. As I wrote we have already (seemingly) found a solution to the issue, but I'm open to suggestions for anything we can improve. |
Glad you got it to work. I think I understand what you're doing and why it works. That's a pretty non-standard setup so, as you've discovered, you're more or less on your own when it comes to figuring out how to deploy it. I'm not super familiar with the Azure DevOps task, but you should be able to build everything as you like it in your pipeline, then zip it up and deploy it without running a remote build. @balag0 is there a way deploy from Azure DevOps without running a remote build? |
I kind of agree and then kind of not ;) The thing is we don't want to use the Visual Studio Code deployment tools as we want our builds to run through our build pipeline with does testing and validation as well. Having individual devs deploying code directly to Azure Functions in production is also not a feasible scenario. So from that alone we must drop the direct deployment extensions. Our build pipeline produces a set of files that we can basically copy into the Azure Function app. It probably does some trickery behind the scenes to hook everything up, but apart from that it should be nothing more than a file copy with JavaScript files. From what I can tell this also does not seem that far off from a normal deployment where we have an artifact (our functions) produced from a build that we then deploy using the deployment task. As far as I can see the biggest non-standard thing we are doing is not wanting to run |
100% agree that you want your pipeline to deploy the app and I'm not suggesting you do anything different. What I am hoping for is that you can configure the pipeline to build the app as you'd expect it to run in Azure (with node_modules at the app root and containing all necessary dependencies). Then the pipeline can take that artifact and simply deploy it without triggering a remote build. This should be possible. What you have is pretty close, except the |
Great! That is exactly what I was hoping we could achieve. I totally agree that the We'd still like to bundle with webpack as we do as our build process has a really simple escape hatch for configuring external dependencies such as I was thinking that having some indicator to tell the deployment that we have already done the |
@anthonychu / @balag0, any thoughts on this request? |
I’m running into the same issue, albeit for different reasons. I think at the simplest, a configuration option to choose a version of npm or Yarn would suffice. But zipping an app that has been built using yarn, and running it via npm is not a solid solution:
I've run into both of these issues when trying to deploy a Yarn project via an Azure DevOps pipeline. Is there any way I can provide more information about our setup if wanted. Thanks in advance! |
We are attempting to use puppeteer in an Azure Function to produce PDFs using Chromium. We have a mono-repo setup that uses
yarn
to manage dependencies and we need to install puppeteer along with apackage.json
file in production in order forpuppeteer
to pick up the Chromium install.The problem is that according to this documentation Azure Functions will run npm install automatically when it detects a
package.json
file, but because we are using yarn to manage dependencies this install will not respect theyarn.lock
file version hashes.We are easily able to do the install deterministically during our build process, but we need to have the
package.json
file alongside the project in order for puppeteer to find the chromium install. This in turn triggers annpm install
during deploy which will install our dependency, but not in a deterministic way as it does not know aboutyarn.lock
.Is there a way to prevent Azure Function deployments from triggering
npm install
even when there is a package.json present?The text was updated successfully, but these errors were encountered: