GithubHelp home page GithubHelp logo

NextJs e nx-tools-docker about nx-tools HOT 13 OPEN

gperdomor avatar gperdomor commented on August 10, 2024 1
NextJs e nx-tools-docker

from nx-tools.

Comments (13)

wSedlacek avatar wSedlacek commented on August 10, 2024 2

In that case, can I use "executor": "nx:run-commands" to run these new/updated images?

After you have the image, getting it running is another story.
I have been creating my own executors using dockerode, perhaps I will create a library with that work some day.
As a simple alternative you can use the run-commands executor as you mentioned to either use docker or docker-compose to start up the image locally.

The current scope of this library ends at building the image and pushing it to a registry.

There is an open feature request for a executor for running images.
#12

If you have further comments or ideas about that feature you may add those there.

from nx-tools.

gperdomor avatar gperdomor commented on August 10, 2024 1

@gilvaju Please check this repository, it's a sandbox with nest, react, next and angular application and all of them use the nx-docker plugin to generate the docker images

from nx-tools.

gperdomor avatar gperdomor commented on August 10, 2024 1

@kodeine yes... you can run npx nx affected --target=docker (or the target which you created in the project.json)

from nx-tools.

wSedlacek avatar wSedlacek commented on August 10, 2024 1

image

I noticed that this package is a peer here.
https://github.com/nx-tools/nx-tools/blob/efec6c8d3fa1946f69941c4eddadc99aa6a18bbd/packages/docker-metadata/package.json#L24

This was introduced in this commit.
27b73cc

I wonder if there is an expectation of another package providing the deposit for @swc/helpers that does not exist in your stack? Maybe @nrwl/angular or @nrwl/web or something like that?

Perhaps this should be moved to a dependency OR perhaps the readme should include @swc/helpers as a required peer along side tslib and @nrwl/devkit

Perhaps this package manager specific?
I know nom has automatic peers, but others (yarn 1) may not.

from nx-tools.

corbinday avatar corbinday commented on August 10, 2024 1

+1
I would also like to know how to use docker compose with nx-container!

from nx-tools.

wSedlacek avatar wSedlacek commented on August 10, 2024

@gilvaju So what we do at work is we first build the application completely outside of Docker using the standard Nx build system. This allows reusing library builds and computational caching. And as part of the build step we put the Dockerfile in the dist via the assets option.

After we have everything in assets we use nx-docker copy the compiled Javascript into a docker image.
As part of that we do an npm install inside the Docker image using the generated package.json that came from the @nrwl/node:webpack executor which only list modules that we actually used.

The one gotcha is we have to use "buildLibsFromSource": true, to inline the library modules into the bundle of the server.
So we aren't really getting the benefit of the libraries being cached and built separately right now, but we have plans to change the webpack config to cover that case.

Overview:

  1. Configure a Docker file and add it to the assets
  2. Build nestjs project with @nrwl/node:webpack
  3. Point @nx-tools/nx-docker:build at the dist location of the Docker file
  4. Build the docker image from the compiled server
  5. Run npm install inside the image using the package.json generated from generatePackageJson

from nx-tools.

kodeine avatar kodeine commented on August 10, 2024

@gperdomor so if we have multiple nest apps and a common library. If we modify common lib would docker rebuild all apps?

from nx-tools.

gilvaju avatar gilvaju commented on August 10, 2024

@gilvaju Please check this repository, it's a sandbox with nest, react, next and angular application and all of them use the nx-docker plugin to generate the docker images

I'll see the example and then give feedback

from nx-tools.

gilvaju avatar gilvaju commented on August 10, 2024

@gilvaju Please check this repository, it's a sandbox with nest, react, next and angular application and all of them use the nx-docker plugin to generate the docker images

Hello, now that we had time to study the repository you indicated.

Anyway thanks for the link

from nx-tools.

gilvaju avatar gilvaju commented on August 10, 2024

image

I was only able to run the command after installing @swr

image

It built perfectly and so I have the image to be used as I want

In that case, can I use "executor": "nx:run-commands" to run these new/updated images?

from nx-tools.

gilvaju avatar gilvaju commented on August 10, 2024

After you have the image, getting it running is another story. I have been creating my own executors using dockerode, perhaps I will create a library with that work some day. As a simple alternative you can use the run-commands executor as you mentioned to either use docker or docker-compose to start up the image locally.

The current scope of this library ends at building the image and pushing it to a registry.

Hmm, I understand

We currently have an ecosystem of about 20 containers, some apps on nx and other services like postgres and mongo.

I believe if it is a way to play these other services for apps tb and use nx-tools to build the images and also use run-commands to run the images (for postgres and mongo for example I would create apps containing only project. json and the Docker file).

It will also be used with github actions

All these images are now served all on just one EC2 with haproxy as a reverse proxy. In the future we have plans to migrate to the container manager or something more complex like kubernets.

Would it be a good way?

There is an open feature request for a executor for running images. #12

If you have further comments or ideas about that feature you may add those there.

Cool, I would like to help, what would be the way? I think I can contribute something.

from nx-tools.

wSedlacek avatar wSedlacek commented on August 10, 2024

Im sure PRs are welcome. Maybe tag @gperdomor with a comment in issue #12 with your initial ideas and then create a draft PR?
I would think we would add a run executor or something, but I am sure there are a few ways to solve the problem.

from nx-tools.

danyhiol avatar danyhiol commented on August 10, 2024

Is there an example of how to use this with docker-compose?
After running a docker-compose file I got the following error: Error: Cannot find module '/usr/src/app/main.js'

from nx-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.