Go Lang Docker Image with Dependencies on Node JS Code/Generators

Issue

Hi I am having a GoLang application that needs to be packaged in to a docker image. Now, this application depends on Node JS Packages that are to be run locally after npm installs on same docker instance. These packages/generators are maintained in a different git repository but have to be available when we create GoLang Docker image. Right now we include these Node Files in a zip format as part of Golang Code and have included the required installations instructions as part of docker file to include these NPM dependencies.

But, we are now looking to automate the docker(Golang) image creation and looking at best way to include these nodejs dependencies dynamically while creating Golang image and not duplicate them as a zip file. What is the best way to address. Any information will be helpful.

thanks,
Aakash

Solution

If your final image does not need Git itself, you could use a multi-stage build in which:

  • you clone the Node repository (using a node-based image with git installed) and do your RUN ["npm", "install"] there
  • you COPY --from=builder /root/ ./ (copy from the first image) the result of that build to your second image (based on Go)

The idea is to get a final image with only what you need.

Answered By – VonC

Answer Checked By – Pedro (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.