Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 3f2cf38

Browse files
authored
nodejs-loopback: upgrade LoopBack stack to latest releases (#863)
* nodejs-loopback: upgrade LoopBack stack to latest releases Signed-off-by: Raymond Feng <[email protected]> * feat: use node as the non-root user for the container Signed-off-by: Raymond Feng <[email protected]>
1 parent 8d8aebc commit 3f2cf38

File tree

18 files changed

+4122
-3594
lines changed

18 files changed

+4122
-3594
lines changed

incubator/nodejs-loopback/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ based on [LoopBack 4](https://github.com/strongloop/loopback-next).
1010
The image contains the main code that loads the user application and configures
1111
with the following components to help the application become cloud native:
1212

13-
- `@loopback/extension-health`: exposes `/health` endpoint for health checks
13+
- `@loopback/health`: exposes `/health` endpoint for health checks
1414
including with `/ready` for readiness and `/live` for liveness checks.
1515

16-
- `@loopback/extension-metrics`: exposes `/metrics` endpoint for metrics data
16+
- `@loopback/metrics`: exposes `/metrics` endpoint for metrics data
1717
that can be scraped by (Prometheus)[https://prometheus.io/].
1818

1919
The project layout is structured as follows:

incubator/nodejs-loopback/image/Dockerfile-stack

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
FROM appsody/nodejs:0.3
1+
FROM appsody/nodejs:0.4
22

3+
ENV APPSODY_PROJECT_DIR=/project
34
ENV APPSODY_MOUNTS=/:/project/user-app
45
ENV APPSODY_DEPS=/project/user-app/node_modules
56

@@ -17,6 +18,7 @@ ENV APPSODY_RUN_KILL=true
1718
ENV APPSODY_DEBUG="npm run debug"
1819
ENV APPSODY_DEBUG_ON_CHANGE="npm run pretest --prefix user-app && npm run debug"
1920
ENV APPSODY_DEBUG_KILL=true
21+
ENV APPSODY_DEBUG_PORT=9229
2022

2123
ENV APPSODY_TEST="npm test && npm test --prefix user-app"
2224
ENV APPSODY_TEST_ON_CHANGE=""
@@ -25,6 +27,7 @@ ENV APPSODY_TEST_KILL=false
2527
COPY ./LICENSE /licenses/
2628
COPY ./project /project
2729
COPY ./config /config
30+
2831
WORKDIR /project
2932
RUN npm install && npm run pretest
3033

incubator/nodejs-loopback/image/project/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM node:12
33

44
# Copying individual files/folders as buildah 1.9.0 does not honour .dockerignore
55
COPY *.json /project/
6-
COPY *.ts /project/
76
COPY user-app /project/user-app
87
COPY src /project/src
98

@@ -20,7 +19,7 @@ WORKDIR /project/user-app
2019
RUN npm install
2120

2221
# Creating a tar to work around poor copy performance when using buildah 1.9.0
23-
RUN cd / && tar czf project.tgz project
22+
RUN cd / && tar czf /project.tgz project
2423

2524
# Copy the dependencies into a slim Node docker image
2625
FROM node:12-slim
@@ -38,4 +37,4 @@ ENV PORT 3000
3837

3938
USER node
4039

41-
CMD ["npm", "start"]
40+
CMD ["npm", "start"]

incubator/nodejs-loopback/image/project/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

incubator/nodejs-loopback/image/project/package-lock.json

Lines changed: 1971 additions & 1734 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

incubator/nodejs-loopback/image/project/package.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"directory": "incubator/nodejs-loopback/image/project"
1010
},
1111
"main": "dist/index.js",
12+
"type": "dist/index.d.ts",
1213
"scripts": {
1314
"build": "lb-tsc",
1415
"clean": "lb-clean dist *.tsbuildinfo",
@@ -18,29 +19,29 @@
1819
"test": "lb-mocha --allow-console-logs \"dist/__tests__\""
1920
},
2021
"dependencies": {
21-
"@loopback/boot": "^2.0.2",
22-
"@loopback/context": "^3.2.0",
23-
"@loopback/core": "^2.2.0",
24-
"@loopback/extension-health": "^0.3.2",
25-
"@loopback/extension-metrics": "^0.2.2",
26-
"@loopback/openapi-v3": "^3.1.1",
27-
"@loopback/repository": "^2.0.2",
28-
"@loopback/rest": "^3.1.0",
29-
"@loopback/rest-explorer": "^2.0.2",
30-
"@loopback/service-proxy": "^2.0.2"
22+
"@loopback/boot": "^3.1.1",
23+
"@loopback/context": "^3.13.1",
24+
"@loopback/core": "^2.13.0",
25+
"@loopback/health": "^0.6.1",
26+
"@loopback/metrics": "^0.5.1",
27+
"@loopback/openapi-v3": "^5.1.1",
28+
"@loopback/repository": "^3.2.1",
29+
"@loopback/rest": "^9.1.0",
30+
"@loopback/rest-explorer": "^3.0.4",
31+
"@loopback/service-proxy": "^3.0.4"
3132
},
3233
"devDependencies": {
33-
"@loopback/build": "^5.0.0",
34-
"@loopback/eslint-config": "^6.0.2",
35-
"@loopback/testlab": "^2.0.2",
36-
"@types/node": "^10.17.17",
37-
"@typescript-eslint/eslint-plugin": "^2.25.0",
38-
"@typescript-eslint/parser": "^2.25.0",
39-
"eslint": "^6.8.0",
40-
"eslint-config-prettier": "^6.10.1",
41-
"eslint-plugin-eslint-plugin": "^2.2.1",
42-
"eslint-plugin-mocha": "^6.3.0",
43-
"source-map-support": "^0.5.16",
44-
"typescript": "~3.8.3"
34+
"@loopback/build": "^6.2.7",
35+
"@loopback/eslint-config": "^10.0.3",
36+
"@loopback/testlab": "^3.2.9",
37+
"@types/node": "^10.17.45",
38+
"@typescript-eslint/eslint-plugin": "^4.8.1",
39+
"@typescript-eslint/parser": "^4.8.1",
40+
"eslint": "^7.13.0",
41+
"eslint-config-prettier": "^6.15.0",
42+
"eslint-plugin-eslint-plugin": "^2.3.0",
43+
"eslint-plugin-mocha": "^8.0.0",
44+
"source-map-support": "^0.5.19",
45+
"typescript": "~4.0.5"
4546
}
4647
}

incubator/nodejs-loopback/image/project/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import {ApplicationConfig, Constructor} from '@loopback/core';
66
import {Bootable} from '@loopback/boot';
77
import {RestApplication} from '@loopback/rest';
8-
import {HealthComponent} from '@loopback/extension-health';
9-
import {MetricsComponent} from '@loopback/extension-metrics';
10-
import * as path from 'path';
8+
import {HealthComponent} from '@loopback/health';
9+
import {MetricsComponent} from '@loopback/metrics';
10+
import path from 'path';
1111

1212
// The user-app is mounted from the template
1313
const userAppModule = '../user-app';

incubator/nodejs-loopback/stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: LoopBack 4
2-
version: 0.3.0
2+
version: 0.4.0
33
description: LoopBack 4 API Framework for Node.js
44
maintainers:
55
- name: Raymond Feng
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/
33
coverage/
4+
.eslintrc.js
Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,79 @@
11
# nodejs-loopback-scaffold
22

3-
This project is originally generated using `lb4` command from `@loopback/cli`. See [Getting started with LoopBack 4](https://loopback.io/doc/en/lb4/Getting-started.html) for more details.
3+
This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the
4+
[initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html).
45

5-
It has been slightly tailored as a template for `appsody`.
6+
## Install dependencies
67

7-
[![LoopBack](https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)[email protected])](http://loopback.io/)
8+
By default, dependencies were installed when this application was generated.
9+
Whenever dependencies in `package.json` are changed, run the following command:
10+
11+
```sh
12+
npm install
13+
```
14+
15+
To only install resolved dependencies in `package-lock.json`:
16+
17+
```sh
18+
npm ci
19+
```
20+
21+
## Run the application
22+
23+
```sh
24+
npm start
25+
```
26+
27+
You can also run `node .` to skip the build step.
28+
29+
Open http://127.0.0.1:3000 in your browser.
30+
31+
## Rebuild the project
32+
33+
To incrementally build the project:
34+
35+
```sh
36+
npm run build
37+
```
38+
39+
To force a full build by cleaning up cached artifacts:
40+
41+
```sh
42+
npm run clean
43+
npm run build
44+
```
45+
46+
## Fix code style and formatting issues
47+
48+
If `eslint` and `prettier` are enabled for this project, you can use the
49+
following commands to check code style and formatting issues.
50+
51+
```sh
52+
npm run lint
53+
```
54+
55+
To automatically fix such issues:
56+
57+
```sh
58+
npm run lint:fix
59+
```
60+
61+
## Other useful commands
62+
63+
- `npm run migrate`: Migrate database schemas for models
64+
- `npm run openapi-spec`: Generate OpenAPI spec into a file
65+
- `npm run docker:build`: Build a Docker image for this application
66+
- `npm run docker:run`: Run this application inside a Docker container
67+
68+
## Tests
69+
70+
```sh
71+
npm test
72+
```
73+
74+
## What's next
75+
76+
Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to
77+
understand how you can continue to add features to this application.
78+
79+
[![LoopBack](<https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)[email protected]>)](http://loopback.io/)

0 commit comments

Comments
 (0)