Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

feat: Migrating to bun #52

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AnshGupta01
Copy link
Contributor

Hi there, there was some git issue with the previous PR, hence raising this new PR.

I've incorporated the requested changes, but im stuck with the dockerFile updates (Please help me out)

package.json Outdated
@@ -8,11 +8,11 @@
"test": "test"
},
"scripts": {
"test": "npm run build:ts && tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"test": "bun install && tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need these redundant bun install directives with every command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By directives you mean the command itself, or the commands that are following the bun install command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bun install commands preceding the actual command

prod.Dockerfile Outdated
COPY --from=builder /app/dist ./dist

CMD ["yarn", "fastify", "start", "-a", "::", "-l", "info", "dist/app.js"]

CMD ["bun", "fastify", "start", "-a", "::", "-l", "info", "dist/app.js"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try running this command (without Docker), you're likely to find this won't work.

  • We're no longer transpiling ts -> js
  • Once you replace this app.js with app.ts, I expect you'll find that the fastify CLI does not support TypeScript files.

Possible solution: remove dependence on Fastify CLI by using fastify eject, then try and see if it works out of the box, if not we might need some more adjustments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use bun build:ts first then let the command work normally, cause then it will be able to find dist/app.js?

Yes the fastify CLi does not support typescript files, by using fastify eject-ts there is a new server.ts file generated to let it function as a standalone app, Im figuring it out still.

Will update soon

@AnshGupta01
Copy link
Contributor Author

Okay, will look into this and get back

@AnshGupta01
Copy link
Contributor Author

AnshGupta01 commented Oct 25, 2023

@ditsuke This was the way console looked with fastify CLI
Screenshot

Now it looks like this:
Screenshot 1
I know this can be perfected with fastify's logger customization, but that needs addition of pino-pretty package, which will make things complex unnecessarily.

Copy link
Member

@ditsuke ditsuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AnshGupta01, thanks for your patience with the review. Overall the PR is really solid, only a few low hanging changes and it'll be good to merge :)

@@ -8,12 +8,11 @@
"test": "test"
},
"scripts": {
"test": "npm run build:ts && tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"test": "bun server.ts && tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"test": "bun server.ts && tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",
"test": "tsc -p test/tsconfig.json && tap --ts \"test/**/*.test.ts\"",

@@ -1,21 +1,19 @@
FROM node:18-alpine as builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove builder build stage, instead:

  1. Start from oven/bun:alpine as before
  2. Copy first the manifest and lockfile
  3. Bun install like below
  4. Copy all assets
  5. ✔️

COPY --from=builder /app/package.json /app/yarn.lock ./
RUN yarn install --frozen-lockfile --production
COPY --from=builder /app/package.json /app/bun.lockb ./
RUN bun install --frozen-lockfile --production
COPY --from=builder /app/dist ./dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy all files (COPY . .) since we're not building JS assets anymore

// Register your application as a normal plugin.
app.register(import("./src/app"));

// delay is the number of milliseconds for the graceful close to finish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up commented out code

@AnshGupta01
Copy link
Contributor Author

Hi, I was on a break since November, I will get back to you soon with the requested changes!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants