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

Update CMD to serve instead of run; remove deps.ts in favor of deno.json #440

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ WORKDIR /app
# Prefer not to run as root.
USER deno

# Cache the dependencies as a layer (the following two steps are re-run only when deps.ts is modified).
# Ideally cache deps.ts will download and compile _all_ external files used in main.ts.
COPY deps.ts .
RUN deno install --entrypoint deps.ts
# Cache the dependencies as a layer (the following two steps are re-run only when deno.json is modified).
# Ideally cache deno.json will download and compile _all_ external files used in main.ts.
Copy link
Member

Choose a reason for hiding this comment

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

This is not preferable. With deno cache on like 62, we are going to install only dependencies that are actually used. Here all deps are installed, even if they are unused. We should wait for denoland/deno#27229

Copy link
Author

Choose a reason for hiding this comment

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

I agree. The dependency install and the caching of it should be sorted first.

The main reason I made this PR was to overcome an issue around the CMD and how the webserver was running, which would throw an error thanks to the approach it was using.

The deps.ts -> deno.json blurb got caught up in this since that also appears to be a remnant from Deno 1.

I'll try to keep an eye on your PR, and once it's merged, I'll alter this one to reflect your approach.

COPY deno.json .
RUN deno install

# These steps will be re-run upon each file change in your working directory:
COPY . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache main.ts

CMD ["run", "--allow-net", "main.ts"]
CMD ["serve", "--port", "1993", "main.ts"]
```

and build and run this locally:
Expand Down
10 changes: 5 additions & 5 deletions example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ WORKDIR /app
# Prefer not to run as root.
USER deno

# Cache the dependencies as a layer (the following two steps are re-run only when deps.ts is modified).
# Ideally cache deps.ts will download and compile _all_ external files used in main.ts.
COPY deps.ts .
RUN deno install --entrypoint deps.ts
# Cache the dependencies as a layer (the following two steps are re-run only when deno.json is modified).
# Ideally cache deno.json will download and compile _all_ external files used in main.ts.
COPY deno.json .
RUN deno install

# These steps will be re-run upon each file change in your working directory:
COPY . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache main.ts

CMD ["run", "--allow-net", "main.ts"]
CMD ["serve", "--port", "1993", "main.ts"]
1 change: 1 addition & 0 deletions example/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 0 additions & 1 deletion example/deps.ts

This file was deleted.

14 changes: 5 additions & 9 deletions example/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { serve } from "./deps.ts";
export default {
async fetch(request) {
return new Response("Hello world!");
},
};

const PORT = 1993;
const s = serve(`0.0.0.0:${PORT}`);
const body = new TextEncoder().encode("Hello World\n");

console.log(`Server started on port ${PORT}`);
for await (const req of s) {
req.respond({ body });
}
Loading