ojkelly/yarn.build

Add option to just output bundle to directory (skip zip)

Closed this issue · 6 comments

Is your feature request related to a problem? Please describe.
I am using yarn bundle during my Docker build step to create a bundle that I copy into the run step container. I currently have to wait for the zip compression and then uncompress immediately anyway to copy the contents into the run container. There should be an option to skip the zip creation and JUST output to a directory.

Describe the solution you'd like
Add yarn bundle option to skip zip creation and output contents to a directory.

Ooh interesting. Yeah this could be done.

We copy to a tmp directory, do the work, zip and copy the zip back.

So this would just be a mv of the folder instead of zipping. It would need to be moved to a location outside the repo though.

Yea that wouldn't be an issue, right now I unzip to a /tmp directory anyway, then copy from that in the run container. Usually goes something like:

...

# build step
FROM base AS builder
WORKDIR /usr/src/app/${WORKSPACE_DIR}
RUN CI=true yarn build
RUN yarn bundle && unzip -q -d /tmp bundle.zip

...

# run step
FROM base AS runner
WORKDIR /usr/src/app
COPY --from=builder /tmp/bundle ./
RUN chown -R node ./
USER node
CMD yarn workspace ${WORKSPACE} run start:production

I've almost finished a PR for this, and removing the zip with --no-compress takes about 90% off the bundle time.

Awesome! Combined with #97 this should make deployments much simpler/smaller.

You can try this out now with by updating with

yarn plugin import https://yarn.build/latest

And then following the following instructions (also in the readme https://github.com/ojkelly/yarn.build#bundle)

Output bundle.zip to a specific folder

# or any path you want to put it in
yarn bundle --output-directory ../tmp

Bundle but don't zip

This is useful when you're building inside a docker container.

Choose an output directory outside your project and pass --no-compress. It needs to be outside, because in some cases it could put you in a state that could take a long time to fix.

The output dir doesn't have to exist, but it must be empty as we're just wholesale overwriting it.

# or any path you want to put it in that's outside your project root
yarn bundle --no-compress --output-directory /srv/app

seems to work great, thanks for the super quick update!