Hi, is there a best practice for running `npm buil...
# general
w
Hi, is there a best practice for running
npm build
inside pulumi? Here's the use case: We need to build and deploy a frontend REACT application to S3. And we need to know which stack to deploy while building the application, so we can set up the environment variables properly. For example, if we are deploying to
dev
, we should run
ENV=dev npm build
. Since we can easily get the stack name in pulumi, it would be convenient if I can run
npm build
inside pulumi.
l
I'm not aware of a best practice. If I was doing this, I'd probably consider wrapping the build and pulumi app in a sinlgle script, rather than putting the build into the deploy. I'd be worried about sharing node_modules accidentally, using wrong versions of dependencies, etc.
I'm sure it can be done though.
s
I am using pulumi only to deploy infrastructure (s3 in this case) and I use circleci for building the client and pushing it to the s3 bucket
you can use aws circleci orb for that, it's pretty easy
Copy code
- run:
    name: Deploy to S3
    command: |
      aws s3 sync dist/client s3://${S3_SITE_BUCKET_NAME} --no-progress --delete
m
Not sure if running it as part of the pulumi deploy would be a good idea, but you should be able to do it using Dynamic Resource Providers. There is an example that may be useful to adapt - https://github.com/pulumi/examples/tree/master/aws-ts-ec2-provisioners. Likely to much more work that just doing it as a build step or wrapper script though...
l
@wide-jackal-86020 the default way, when using Pulumi, is that Pulumi invokes
node
to create the needed resources. If you want to drive Pulumi from within your NodeJS code, have a look a the Automation API. In that setup, the Pulumi engine will be started by your NodeJS code and you can programmatically set the environment, stack config, etc. https://www.pulumi.com/docs/guides/automation-api/
w
Thank you all!
wrapping the build and pulumi app in a sinlgle script,
This is what we are doing now. The problem is that the API endpoints are generated in other pulumi projects, they are not accessible when building the REACT application. @little-cartoon-10569 @miniature-king-36473
use circleci for building the client and pushing it to the s3 bucket
CI/CD works, But we don't have CI/CD setup for every stack. @sparse-spring-91820
Pulumi invokes 
node
 to create the needed resources.
This is what I am thinking to give it a try. Thank you for sharing the other way of driving Pulumi from within NodeJS code using the Automation API. 👍 @limited-rainbow-51650
140 Views