Shopify / shopify-app-template-remix

346 stars 145 forks source link

Dockerfile including the everything - Filter out node_modules not necessary for deploy #378

Closed owlyowl closed 11 months ago

owlyowl commented 1 year ago

Issue summary

When packaging up in Docker. I can see it is simply copying everything over including around 554mb of node_modules content.

For deploying in to other environments I was wondering if there were any plans to tree shake/filter out unused node_modules - e.g. Shopify cli and others and establish a list of dependencies just required to host/deploy the application.

image

Here was a cutdown node_modules output I managed to get the application building with:

@babel
@remix-run
@shopify
@web3-storage
abort-controller
buffer
buffer-crc32
buffer-from
compare-versions
cookie
cookie-es
cookie-signature
data-uri-to-buffer
dom-helpers
event-target-shim
isbot
jose
mime
mime-db
mime-types
mrmime
object-assign
object-inspect
object-is
object-keys
object-to-human-string
object-treeify
object.assign
object.entries
object.fromentries
object.groupby
object.hasown
object.values
prop-types
react
react-dom
react-fast-compare
react-is
react-reconciler
react-refresh
react-router
react-router-dom
react-transition-group
scheduler
semver
semver-regex
set-cookie-parser
source-map
source-map-js
source-map-support
stream-shift
stream-slice
tslib
uuid
web-encoding
web-streams-polyfill
lizkenyon commented 11 months ago

Hi 👋

Thank you for your feedback! This is something we are going to work towards resolving.

owlyowl commented 11 months ago

Thanks Liz Most appreciated!

It would be great for a prod build to output only what is needed to run the entire apl in an output directory or a standard remix style server client split

On Thu, Nov 2, 2023, 3:10 AM Liz Kenyon @.***> wrote:

Hi 👋

Thank you for your feedback! This is something we are going to work towards resolving.

— Reply to this email directly, view it on GitHub https://github.com/Shopify/shopify-app-template-remix/issues/378#issuecomment-1789236112, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOT4CW2HZN4XVUTZQVQGUDYCJX6XAVCNFSM6AAAAAA6BOR4FWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBZGIZTMMJRGI . You are receiving this because you authored the thread.Message ID: @.***>

fire015 commented 11 months ago

You should at least prune the dev dependencies in your Dockerfile. Here is what I am using to get a smaller image:

FROM node:18-alpine as build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
ENV NODE_ENV=production
RUN npm run build
RUN npm prune --omit=dev

FROM node:18-alpine
WORKDIR /usr/src/app
COPY --from=build /usr/src/app .
EXPOSE 3000
USER node
CMD ["npm", "run", "docker-start"]
owlyowl commented 11 months ago

I would have thought things like shopify-cli should be devDependencies as well..

On Thu, Nov 2, 2023 at 10:44 PM Jason @.***> wrote:

You should at least prune the dev dependencies in your Dockerfile. Here is what I am using to get a smaller image:

FROM node:18-alpine as build WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . ENV NODE_ENV=production RUN npm run build RUN npm prune --omit=dev

FROM node:18-alpine WORKDIR /usr/src/app COPY --from=build /usr/src/app . EXPOSE 3000 USER node CMD ["npm", "start"]

— Reply to this email directly, view it on GitHub https://github.com/Shopify/shopify-app-template-remix/issues/378#issuecomment-1790570971, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOT4CWL5RGG27G7HMPPDQ3YCOBQDAVCNFSM6AAAAAA6BOR4FWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJQGU3TAOJXGE . You are receiving this because you authored the thread.Message ID: @.***>

fire015 commented 11 months ago

Yeh they really should, though some people may still want access to the CLI within Docker (might just be running it locally instead of installing Node/NPM on their machines).

paulomarg commented 11 months ago

Thanks for your comments, folks. I quite like the approach of using a separate image to build the app and then just using the built files, I'll look into updating it to something close to that.

As for the CLI, unfortunately, it needs to be a dependency (as in, not a dev dep) because it has some automations that use the actual dependencies.

We can always just npm remove the CLI packages as part of the build step, and any apps that want to run CLI commands could just remove those lines from their Dockerfile. That seems to shake off 100MB+ from node_modules, bringing it just under 300MB.

owlyowl commented 11 months ago

Thanks Paulo! Really appreciate it

On Thu, Nov 16, 2023, 2:24 AM Paulo Margarido @.***> wrote:

Closed #378 https://github.com/Shopify/shopify-app-template-remix/issues/378 as completed via #418 https://github.com/Shopify/shopify-app-template-remix/pull/418.

— Reply to this email directly, view it on GitHub https://github.com/Shopify/shopify-app-template-remix/issues/378#event-10968831359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOT4CXZMPSOMMP5DCEBHRLYETNCXAVCNFSM6AAAAAA6BOR4FWVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJQHE3DQOBTGEZTKOI . You are receiving this because you authored the thread.Message ID: <Shopify/shopify-app-template-remix/issue/378/issue_event/10968831359@ github.com>