Replies: 51 comments 48 replies
-
Hello! Any update on this? |
Beta Was this translation helpful? Give feedback.
-
No, I was hoping for some discussion with the community. I have got mine deploying via circle ci to heroku for the nestjs api and netlify for the angular front end but it feels a little hacky. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. I tried deploying my express app to Heroku but the main issue is that we don't have a |
Beta Was this translation helpful? Give feedback.
-
My current approach is to send the whole NX project to Heroku and then Taylor the build and deploy npm commands to only deploy the nest backend |
Beta Was this translation helpful? Give feedback.
-
I also do the same thing but it's just CI/CD commands stacked together just to deploy and this whole process feels wrong for some reason because if any update and symlinks are added to the project, this whole chain won't work anymore and we have to write another stack of CI/CD. Hopefully, we find a real solution soon because this project has increased our productivity so much and it's such a shame if we cannot deploy stuff properly. |
Beta Was this translation helpful? Give feedback.
-
If I'm not mistaken, a similar pain point was raised in this issue #3817 |
Beta Was this translation helpful? Give feedback.
-
Yes. Unfortunately that's the same issue. |
Beta Was this translation helpful? Give feedback.
-
I too am trying to use nx with Heroku and running into issues. So far im trying to follow this guide which basically involves building docker first then pushing to heroku: https://hackmd.io/US2eky6lSMecuHxegFZCbA?view but it doesnt seem to work for me Just a quick edit I was able to follow a suggestion on this discussion: #1777 which mentioned using https://github.com/vercel/ncc which seems to work pretty well |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
Is there any example of guidance here by nrwl on how to deploy these apps? |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Beta Was this translation helpful? Give feedback.
-
a reply from a maintainer with their recommendations would be great |
Beta Was this translation helpful? Give feedback.
-
any update on it? |
Beta Was this translation helpful? Give feedback.
-
Some best practices or some basic guidance would be nice here :) |
Beta Was this translation helpful? Give feedback.
-
I ended up deploying the front-end to Netlify and the back-end to Heroku off of the same repo. Basically, configure two different commands in
The back-end APIs were:
Depending on where you host your FE or BE, you may have to edit your boot files (e.g., for Heroku it was |
Beta Was this translation helpful? Give feedback.
-
I think tools like this and turborepo are the future of development. But Nx plays horribly deployment-wise. It doesn't make sense at all that when you deploy, let's say a React app to Vercel, it also installs Nest and Bcrypt that you use in your microservices, and it's the same the other way around. What I found was best is to just use a standard monorepo with yarn workspaces, and in your CD just delete the packages that have dependencies you don't care about. I'm doing so here You could also create a Dockerfile for each service / frontend:
FROM node:lts-alpine
WORKDIR /app
COPY . .
RUN rm -rf frontend
RUN yarn install
RUN yarn workspace local-lib build
RUN yarn workspace service-a build
CMD yarn workspace service-a start:prod
FROM node:lts-alpine
WORKDIR /app
COPY . .
RUN rm -rf backend
RUN yarn install
RUN yarn workspace ui-lib build
RUN yarn workspace dashboard build
CMD yarn workspace dashboard start:prod And then you would build the docker images for those, later pushing them to the image registry, and finally pulling the image from your EC2 / DigitalOcean box, or whatever, you can use this as reference on how to automate that, you could also have a husky hook to force the developer to build the image locally and allow to push only if it succeeds. Finally I want to say that the build tool of nx itself is actually fine, you could just use it for that, building packages. Hope my comments helped, cheers. |
Beta Was this translation helpful? Give feedback.
-
In my experience, Nx works great both in terms of development and deployment. To make docker containers take up less space, I would recommend thinking about how to organize project dependencies. # NodeJS base app image.
# This image is rebuilt whenever any of the project dependencies change.
# Define image.
FROM node:16.15.1-alpine
# Set environment variables.
ENV DEBIAN_FRONTEND=noninteractive
# Define app directory.
WORKDIR /app
# Copy dist.
COPY /package.json .
COPY /yarn.lock .
# Install dependencies and create a user.
RUN npm i -g npm ; \
npm i --production --ignore-scripts --legacy-peer-deps ; \
npm cache clean --force; \
addgroup -S appgroup && \
adduser -S appuser -G appgroup Then the base image mentioned above can be used to build an API app image, e.g. # NodeJS API app image.
# Define image.
FROM rfprod/nx-ng-starter:base-latest
# Set environment variables.
ENV DEBIAN_FRONTEND=noninteractive
# Define app directory.
WORKDIR /app
# Copy sources.
COPY /tools/proto ./tools/proto
COPY /dist/apps/api ./dist
# Set user.
USER appuser
# Configure exposed port.
EXPOSE 8080 8082
# Define startup command.
CMD [ "node", "./dist/main.js" ] or a client app image, e.g. # NodeJS client app image.
# Define image.
FROM rfprod/nx-ng-starter:base-latest
# Set environment variables.
ENV DEBIAN_FRONTEND=noninteractive
# Define app directory.
WORKDIR /app
# Copy dist.
COPY /dist/apps/server-prod ./dist
COPY /dist/apps/client ./dist/assets
# Set user.
USER appuser
# Configure exposed port.
EXPOSE 8080
# Define startup command.
CMD [ "node", "./dist/main.js" ] To make client application images even lighter, instead of using NodeJS to serve client applications, Nginx can be used, something like # Nginx client app image.
# Define image.
FROM nginx:alpine
# Copy Nginx configuration.
COPY ./.docker/nginx_default.conf /etc/nginx/conf.d/default.conf
# Remove default nginx index page.
RUN rm -rf /usr/share/nginx/html/*
# Copy dist.
COPY /dist/apps/client /usr/share/nginx/html
# Expose port.
EXPOSE 8010 80
# Define entrypoint.
ENTRYPOINT ["nginx", "-g", "daemon off;"] With this approach, application distributions are built on the runner and cached, and docker uses build artifacts. Also, again in my experience, Nx works pretty well with serverless platforms like Firebase. |
Beta Was this translation helpful? Give feedback.
-
Any ideas of how to run lint+typescript checks on PR's? |
Beta Was this translation helpful? Give feedback.
-
The company I'm at isn't small and has several apps that we threw into a single Nx monorepo. Deployment was a bit tricky because of the tools we already had set up require that an app deployment happens in its own unique repository. For us, the super hacky solution we eventually came to was building a custom executor that grabs all the assets needed to deploy a specific app and then overrides the majority of the content of another git repository in the same organization on Github (a repository specifically for deployment needed to be bootstrapped for each app). Github Actions can kick off a deployment automatically when something new is pushed. It definitely works, but it feels like there should be a more effective way of doing things 😅 |
Beta Was this translation helpful? Give feedback.
-
Effectively, what's needed is functionality like this: https://turbo.build/repo/docs/reference/command-line-reference#turbo-prune---scopetarget For each application, it creates a directory containing:
It's effectively just tree-shaking. I would go a step further, though, and say I only really want the build output and a pruned package file with only the prod dependencies. With remote caching enabled, though, it shouldn't really matter. NX might have to do a bit more work to reliably determine the external dependencies that are needed, but it's definitely possible to crawl through an AST and work that out, and the library templates already seem to do this reliably. |
Beta Was this translation helpful? Give feedback.
-
I haven't setup a full pipeline this way yet, but I suspect it is possible to get a Docker/podman image of each app and push it to a container registry/elsewhere using the nx-container plugin and GitHub Actions. nx-container docs: https://github.com/gperdomor/nx-tools/blob/main/packages/nx-container/README.md
The GH Action would be similar to this from the docs, but add an affected container command to create an image for each affected app. Then you would just need to get the output from that portion and get to your container registry. https://nx.dev/recipes/ci/monorepo-ci-github-actions
|
Beta Was this translation helpful? Give feedback.
-
Have there been any updates regarding examples? |
Beta Was this translation helpful? Give feedback.
-
https://nx.dev/recipes/ci/ci-deployment#prepare-applications-for-deployment-via-ci Perhaps this is the answer? Honestly, I've already moved on at this point. The whole thing has just approached the "endless backlog syndrome" of new features that it's become more complex than the problem that it ostensibly solves for me... |
Beta Was this translation helpful? Give feedback.
-
After successfully implementing my (hacky) CI/CD with an integrated Nx repo, I am now hacking my way at another CI/CD for a package-based Nx repo. To me, it's very frustrating that Nx doesn't provide any documentation on deployments. Deploying is one, if not the most, important aspects of your application, and Docker is a pretty solid standard right now. All we want is a working example of an Nx workspace with a nest app and a next app, both with their respective Dockerfiles and a possible target to run with nx affected (ex: nx affected --target=docker-build). I love the tool, and I am really enjoying working with monorepos, but if things keep getting on the way, it gets hard to justify its use in our companies, especially when it involves working in a different way that people know and are used to (polyrepo). PS: thank you for all the work! I'd be happy to share my experience with Nx if anyone's interested. |
Beta Was this translation helpful? Give feedback.
-
Please correct me if I'm wrong (I'm still experimenting with nx). |
Beta Was this translation helpful? Give feedback.
-
It’s not the best approach, it’s just an approach. Of course NX are going
to sell it, it’s a product at the end of the day.
You have to weigh up the pros and cons yourself.
My personal opinion is that NX just has far too much overhead for monorepo
and if you are going to go down that route I would strongly recommend turbo
instead.
But I personally prefer multi repo these days anyway, just because google
use a monorepo doesn’t mean your startup has to.
Multi repo has much nicer separation of concerns, especially for
distributed systems.
It’s much harder to enforce code owners and permissions in a monorepo.
Don’t default to Monorepo, use multi repo until you find it’s slowing you
down or you would gain something from a monorepo.
Not worth the complexity - especially early on
…On Fri, 6 Oct 2023 at 17:02, Andrea Pigatto ***@***.***> wrote:
Please correct me if I'm wrong (I'm still experimenting with nx).
I think integrated repo is a great idea but I don't understand why nx want
to sell it as the best approach.
Actually I see more cons than pros to have a single package.json.
One for sure is related to CICD and deployment. Just hacking as in
previous posts is possible to run multiple pipelines one x project.
At same time having all dependencies in one package.json will make the
list grow and be hard maintainable.
I don't really see how this can scale. Any idea? Am I missing something?
—
Reply to this email directly, view it on GitHub
<#9183 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFOCQ5ZYH4V4O4FKP5X64ZLX6AMQ5AVCNFSM5SRMZLIKU5DIOJSWCZC7NNSXTOKENFZWG5LTONUW63SDN5WW2ZLOOQ5TOMRRGA3DQMA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
What kind of git branching strategies do you use? Do you just tag main for your deployments? How do you keep microservices independently deployable while using a monorepo solution? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The issue of how to deploy your Nx applications using Docker seems to crop up constantly on the Nx Discord channel, but so far there is still no up-to-date, definitive examples that illustrate all the necessary steps. I have a simple Host and Remote Angular app with some libraries and I cannot find a canonical example of deploying this using a Dockerfile. Nx is a great tool but the lack of concrete examples for everyday tasks such as dockerizing host and remote apps into a single container will inevitably lead to user frustration and abandonment in favour of something else. |
Beta Was this translation helpful? Give feedback.
-
This lack of documentation on deployment is as relevant today as it was in 2020.. We are struggling to figure out how to deploy our apps from our monorepo to digital ocean. We run tests and build locally and now we want to deploy the build but seems we cant without docker and tons of other interventions. Its really confusing. And the dude in the youtube videos about NX is so chill and makes it look so easy, its really misleading. |
Beta Was this translation helpful? Give feedback.
-
Description
Having a read though the documentation there seems to be a real lack of examples and best practices on how to deploy your shiny new project and searching around for articles is a sea of outdated or hacky looking workarounds.
I would like to discuss how the community is deploying their repos and some best practice input from the Dev team and then either help write some docs or at least curate them into an article. I am really enjoying developing with nx but I find the docs lacking.
A secondary thing would be some examples of CI/CD configs for the main providers for different configs.
Lastly, is there a NestJS version of these angular.json deployers
Suggested areas of documentation
preparing to deploy
Configuring the deployer
running your first deploy
NX CICD Pipeline by example
Beta Was this translation helpful? Give feedback.
All reactions