keystone icon indicating copy to clipboard operation
keystone copied to clipboard

add canonical Dockerfile to examples/basic

Open dcousens opened this issue 4 years ago • 10 comments

This is a draft.

I am open to community thoughts on where this example should live? We want to encourage test deployments of our examples in different environments for users trial Keystonejs. However, as is, we'll end up copying a Dockerfile to every example.

We might also want to promote different environments, arm64, x86_64 et al; files for each of those (and other deployment examples) does not scale, and would add noise to the examples as documentation.

  • [ ] Add USER
  • [x] Fix the SESSION_SECRET keystone build problems
  • [x] migrate deploy shouldn't need keystone.ts

dcousens avatar Nov 25 '21 00:11 dcousens

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/7jHpz9gtX6E2SQjrkDwjREAm5YCn
✅ Preview: https://keystone-next-docs-git-docker-example-keystonejs.vercel.app

vercel[bot] avatar Nov 25 '21 00:11 vercel[bot]

⚠️ No Changeset found

Latest commit: d7de88f8c1573e63e1587fc16c14af11cad335a9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Nov 25 '21 00:11 changeset-bot[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d7de88f8c1573e63e1587fc16c14af11cad335a9:

Sandbox Source
@keystone-6/sandbox Configuration

codesandbox-ci[bot] avatar Nov 25 '21 00:11 codesandbox-ci[bot]

SESSION_SECRET and DATABASE_URL complicate this horribly. Since npm run build imports the program, those values need to be set even at build time!

tv42 avatar Mar 31 '22 21:03 tv42

Using a separate build image and COPY --from=build /app / means that the final image cannot reuse layers that didn't change; that flattens the whole ~1 GB node_modules pile into one layer, which must be transferred over the network on every change.

tv42 avatar Apr 19 '22 19:04 tv42

@tv42 you mentioned

those values need to be set even at build time

You shouldn't need to configure DATABASE_URL for build, and SESSION_SECRET can be configured to be randomly generated if no env variable is provided.

dcousens avatar Apr 27 '22 03:04 dcousens

It seems I am required to provide a DatabaseConfig with a url: https://github.com/keystonejs/keystone/blob/c396f16a77798852208e93c2a8bb4a07c04c3af5/packages/core/src/types/config/index.ts#L24 https://github.com/keystonejs/keystone/blob/c396f16a77798852208e93c2a8bb4a07c04c3af5/packages/core/src/types/config/index.ts#L56

Providing a dummy value if the environment variable is set is not desirable to me; I want to check that the environment is configured correctly and give an error message if not.

For example:

const databaseUrl = (function () {
  const fromEnv = process.env.DATABASE_URL;
  if (fromEnv !== undefined) {
    return fromEnv;
  }
  if (isDev) {
    // Default convenience value during development.
    return "postgres://postgres:pgdev@localhost:5432/postgres?application_name=keystone&schema=cms";
  }
  throw new Error("missing environment variable DATABASE_URL");
})();
let sessionSecret = process.env.SESSION_SECRET;
if (!sessionSecret) {
  if (process.env.NODE_ENV === "production") {
    throw new Error(
      "The SESSION_SECRET environment variable must be set in production"
    );
  } else {
    sessionSecret = "dev-notReallySecret-session-key-dummy";
  }
}

The way the API has been structured prevents me from doing this.

tv42 avatar Apr 29 '22 01:04 tv42

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
keystone-next-docs ✅ Ready (Inspect) Visit Preview Nov 22, 2022 at 7:29AM (UTC)

vercel[bot] avatar May 11 '22 03:05 vercel[bot]

I tried with the basic example. some observations not sure if that is problem with keystone or due to prisma/nextjs

  1. docker image size when pushed to registry is almost 900MB with node alpine
  2. memory footprint with basic example with not lot of lists is ~200mb

I am not too much worried about the image size as in private registry, it says 264 mb total size. but the memory footprint should be optimized.

gautamsi avatar Sep 25 '22 19:09 gautamsi

@gautamsi neat metrics! I think the memory requirements could be tracked in a different issue, but I wonder if we could CI that graphed it over time.

dcousens avatar Sep 25 '22 23:09 dcousens