Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle inc root deps and --temporary-directory #184

Merged
merged 2 commits into from
Mar 1, 2022
Merged

Conversation

ojkelly
Copy link
Owner

@ojkelly ojkelly commented Mar 1, 2022

Include root dependencies when bundling and add --temporary-directory to enable building a docker image right from the result of the bundle.

As an example, the following script makes a temporary directory, bundles the @app/web (change to suit) workspace, then creates a Docker image of the resulting directory, and finally cleans up.

#!/usr/bin/env bash
# set -eo pipefail

set -x

# Make a tmp directory to extract out bundle to
# this helps removes everything thats not needed before
# we even send stuff over to the docker build context
dirName="${SERVICE_NAME}-${GIT_COMMIT_HASH}"
tmpDir=$(mktemp -d -t $dirName-XXXXXXX)

NODE_OPTIONS=--trace-warnings

# Run bundle with our tmp directory, and ask it not to zip up the result
yarn bundle --temporary-directory $tmpDir --ignore-file .bundleignore

set -e
# Build our container
docker build \
  -t ${SERVICE_NAME}:${GIT_COMMIT_HASH} `# tag with known variables` \
  --compress   `# compress the build context before sending to docker` \
  --build-arg PACKAGE_PATH=${PACKAGE_PATH}   `# let the dockerfile know where in the packge to go` \
  -f $tmpDir$PACKAGE_PATH/Dockerfile  `# our packages Dockerfile` \
  $tmpDir  `# temp dir build context`

set +e

# Remove our temporary directory
rm -rf $tmpDir

Using the following Dockerfile in a package called @app/web

FROM node:17-alpine
WORKDIR /app

ARG PACKAGE_PATH

ENV NODE_ENV production

RUN corepack enable

COPY ./ /app

# For nextjs
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["yarn", "workspace", "@app/web", "start"]

@ojkelly ojkelly merged commit 6f59d7e into main Mar 1, 2022
@ojkelly ojkelly deleted the bundle-inc-root-deps branch March 1, 2022 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant