-
Notifications
You must be signed in to change notification settings - Fork 1
yarn: migrate sample-nodejs-app example #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .git | ||
| node_modules | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
|
|
||
| [*.{js,json,yml}] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /.yarn/** linguist-vendored | ||
| /.yarn/releases/* binary | ||
| /.yarn/plugins/**/* binary | ||
| /.pnp.* binary linguist-generated |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| FROM docker.io/node:20 | ||
|
|
||
| COPY . /src | ||
| WORKDIR /src | ||
|
|
||
| RUN yarn install | ||
|
|
||
| EXPOSE 9000 | ||
|
|
||
| CMD ["yarn", "run", "start"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| # Repo of examples for Hermeto docs | ||
| # Sample NodeJS App | ||
|
|
||
| Individual examples each live in their own branch (e.g. the basic `pip` example is in | ||
| the 'pip-basic' branch) | ||
| This is a simple web application based on [Express](https://expressjs.com) used to test container | ||
| builds that rely on the yarn ecossystem. | ||
|
|
||
| ## How to run it | ||
| ``` | ||
| yarn install | ||
| yarn start | ||
| ``` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| const express = require("express"); | ||||||
|
|
||||||
| const port = 9000; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the port number makes the application less flexible. It's a good practice to read the port from an environment variable (e.g.,
Suggested change
|
||||||
| const app = express(); | ||||||
|
|
||||||
| app.get("/", (req, res) => res.send("Hello world!")); | ||||||
|
|
||||||
| app.listen(port, () => console.log(`App started on port ${port}...`)); | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "yarn-basic-example", | ||
| "packageManager": "yarn@3.6.2", | ||
| "version": "1.0.0", | ||
| "description": "A sample NodeJS app", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "start": "node index.js", | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, | ||
| "author": "", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "license": "ISC", | ||
| "dependencies": { | ||
| "express": "^4.18.2" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve Docker build performance, it's better to copy only
package.json,yarn.lockand the.yarndirectory first, runyarn install, and then copy the rest of the application source code. This allows Docker to cache the dependencies layer and avoid reinstalling them on every code change. For example: