Skip to content

Commit

Permalink
build(docker): update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadNews committed Oct 3, 2023
1 parent 63f6083 commit 8d9fd21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
FROM oven/bun:1.0.3@sha256:4b3393b507e40a1a6a4b8d3c47c59a5a733a9f96eb0f61b397d0789ef7660e72 as base
FROM oven/bun:1.0.4-alpine@sha256:07343bd778e11bad4c6b434737e4cafc843cefcf69523b3868c4443e564f38b9 as base
LABEL maintainer "DeadNews <aurczpbgr@mozmail.com>"

WORKDIR /app

FROM base as runtime

ENV NODE_ENV=production
ENV NODE_PORT=3000 \
NODE_HOSTNAME=0.0.0.0 \
NODE_ENV=production

COPY package.json bun.lockb ./
COPY src/ ./src/
RUN bun install --production --frozen-lockfile

USER bun:bun
EXPOSE 1271
HEALTHCHECK --interval=60s --timeout=3s CMD curl --fail http://127.0.0.1:1271/health || exit 1
EXPOSE ${NODE_PORT}
HEALTHCHECK --interval=60s --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${NODE_PORT}/health || exit 1

CMD ["bun", "start"]
7 changes: 4 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
// If the request path is "/health", it responds with "OK".
// For any other request path, it responds with "404!".
export function start() {
let port = process.env.PORT || 1271;
console.log(`Starting HTTP server at http://127.0.0.1:${port}.`);
console.log(
`Starting HTTP server at`,
`http://${Bun.env.NODE_HOSTNAME}:${Bun.env.NODE_PORT}.`,
);

Bun.serve({
port: port,
fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/") return new Response("Hello, World!");
Expand Down

0 comments on commit 8d9fd21

Please sign in to comment.