danger-js icon indicating copy to clipboard operation
danger-js copied to clipboard

Refactor Dockerfile to reduce image size

Open drawks opened this issue 2 years ago • 3 comments

  • resolves #1274
  • refactors Dockerfile to optimize for size
    • converts to use a two stage build with only the minimum in the final stage
    • applies yarn-audit-fix during build stage setup to automatically upgrade to latest patch version of dependencies
    • converts final build step to use the --production flag to prevent development dependencies from being present in final image

In addition to reducing the overall size of the container (reduced from over 1gb to under 200MB) this change results in container with far fewer known vulnerable node module.

before   latest                 2ab391c36636   23 minutes ago       1.17GB
after      latest                 91697973ff7b   About a minute ago   182MB

drawks avatar Apr 25 '22 17:04 drawks

Yeah, this is good - I expect this might end up dropping TypeScript support for folks - any chance that dependency can be added manually to the build process. Then I'm good to merge

orta avatar Apr 26 '22 08:04 orta

Yeah, this is good - I expect this might end up dropping TypeScript support for folks - any chance that dependency can be added manually to the build process. Then I'm good to merge

Apart from having a Dockerfile that demonstrates how to build it into someone elses own image, I'm still not even convinced of the benefit of have a dangerjs docker image.

Most things will require people to bring in other packages anyway, the most obvious is Typescript. Which then illustrates where this becomes a slippery slope: how many packages will you start including in the docker image?

airtonix avatar Aug 09 '22 23:08 airtonix

I'm not here to debate whether it makes sense to make a Danger dockerfile, enough people have asked and eventually added it themselves. I don't think it makes sense, but that doesn't mean folks in esoteric build/CI systems have the same constraints as me.

Having this PR break someones docker setup because you can't run a dangerfile.ts isn't a slippery slope argument, for me that's the baseline with respect for danger to run in a project. Which I think is pretty reasonable as a constraint.

orta avatar Aug 10 '22 11:08 orta

There is definitely a benefit. Upstream official docker image always nice to have. Everyone could beald an image FROM an official one.

probably worth to add .dockerignore too

node_modules/
.git/
env/
.github/
.vscode/

ivankatliarchuk avatar Oct 02 '22 08:10 ivankatliarchuk

Yeah, this is good - I expect this might end up dropping TypeScript support for folks - any chance that dependency can be added manually to the build process. Then I'm good to merge

As I mentioned above i'm not really a node/js dev, if it is expected that Typescript is always needed alongside danger would it make sense to add it to packages.json so it is always pulled as a dependency?

edit: I've added a commit that does this. I think the PR as it stands addresses all the issues discussed in reviews up to this point.

drawks avatar Feb 13 '23 19:02 drawks

Perhaps it can be added inside the dockerfile?

Gotcha, I can do that

drawks avatar Feb 14 '23 23:02 drawks

Cool, this seems reasonable to me 👍🏻

orta avatar Feb 15 '23 05:02 orta

@drawks your git rebase totally messed up, some dependabot updates pulled in:

  • https://github.com/danger/danger-js/pull/1275/commits

@orta why you have merged these? pull request doesn't even mention updating dependencies. should have been separate pr

glensc avatar Feb 15 '23 11:02 glensc

I read the lockfile changes, they were harmless and only affected this repo

orta avatar Feb 15 '23 12:02 orta

I wonder where the dependabot changes came. from it's not enabled in https://github.com/danger/danger-js repo... at least no open pr's here.

glensc avatar Feb 15 '23 16:02 glensc

That was my fault, I switched computers on my last update and accidentally rebased on my own fork which has dependabot enabled.

Apologies.

drawks avatar Feb 15 '23 16:02 drawks