# This dockerfile builds an image for the backend package. # It should be executed with the root of the repo as docker context. # # Before building this image, be sure to have run the following commands in the repo root: # # yarn install # yarn tsc # yarn build # # Once the commands have been run, you can build the image using `yarn build-image` FROM node:16-bullseye-slim # Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image, # in which case you should also move better-sqlite3 to "devDependencies" in package.json. RUN apt-get update && \ apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \ rm -rf /var/lib/apt/lists/* && \ yarn config set python /usr/bin/python3 # From here on we use the least-privileged `node` user to run the backend. WORKDIR /app RUN chown node:node /app USER node # This switches many Node.js dependencies to production mode. ENV NODE_ENV production # Copy over Yarn 3 configuration, release, and plugins COPY --chown=node:node .yarn ./.yarn COPY --chown=node:node .yarnrc.yml ./ # Copy repo skeleton first, to avoid unnecessary docker cache invalidation. # The skeleton contains the package.json of each package in the monorepo, # and along with yarn.lock and the root package.json, that's enough to run yarn install. COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar.gz ./ RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz # Note that this install is not immutable, which is one of the reasons we don't recommend Yarn 3 yet RUN yarn workspaces focus --all --production && rm -rf "$(yarn cache clean)" # Then copy the rest of the backend bundle, along with any other files we might want. COPY --chown=node:node packages/backend/dist/bundle.tar.gz app-config*.yaml ./ RUN tar xzf bundle.tar.gz && rm bundle.tar.gz CMD ["node", "packages/backend", "--config", "app-config.yaml"]