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

Commit

Permalink
nodejs-loopback: upgrade LoopBack stack to latest releases (#863)
Browse files Browse the repository at this point in the history
* nodejs-loopback: upgrade LoopBack stack to latest releases

Signed-off-by: Raymond Feng <enjoyjava@gmail.com>

* feat: use node as the non-root user for the container

Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
  • Loading branch information
raymondfeng committed Nov 30, 2020
1 parent 8d8aebc commit 3f2cf38
Show file tree
Hide file tree
Showing 18 changed files with 4,122 additions and 3,594 deletions.
4 changes: 2 additions & 2 deletions incubator/nodejs-loopback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ based on [LoopBack 4](https://github.com/strongloop/loopback-next).
The image contains the main code that loads the user application and configures
with the following components to help the application become cloud native:

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

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

The project layout is structured as follows:
Expand Down
5 changes: 4 additions & 1 deletion incubator/nodejs-loopback/image/Dockerfile-stack
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM appsody/nodejs:0.3
FROM appsody/nodejs:0.4

ENV APPSODY_PROJECT_DIR=/project
ENV APPSODY_MOUNTS=/:/project/user-app
ENV APPSODY_DEPS=/project/user-app/node_modules

Expand All @@ -17,6 +18,7 @@ ENV APPSODY_RUN_KILL=true
ENV APPSODY_DEBUG="npm run debug"
ENV APPSODY_DEBUG_ON_CHANGE="npm run pretest --prefix user-app && npm run debug"
ENV APPSODY_DEBUG_KILL=true
ENV APPSODY_DEBUG_PORT=9229

ENV APPSODY_TEST="npm test && npm test --prefix user-app"
ENV APPSODY_TEST_ON_CHANGE=""
Expand All @@ -25,6 +27,7 @@ ENV APPSODY_TEST_KILL=false
COPY ./LICENSE /licenses/
COPY ./project /project
COPY ./config /config

WORKDIR /project
RUN npm install && npm run pretest

Expand Down
5 changes: 2 additions & 3 deletions incubator/nodejs-loopback/image/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM node:12

# Copying individual files/folders as buildah 1.9.0 does not honour .dockerignore
COPY *.json /project/
COPY *.ts /project/
COPY user-app /project/user-app
COPY src /project/src

Expand All @@ -20,7 +19,7 @@ WORKDIR /project/user-app
RUN npm install

# Creating a tar to work around poor copy performance when using buildah 1.9.0
RUN cd / && tar czf project.tgz project
RUN cd / && tar czf /project.tgz project

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

USER node

CMD ["npm", "start"]
CMD ["npm", "start"]
1 change: 0 additions & 1 deletion incubator/nodejs-loopback/image/project/index.ts

This file was deleted.

3,705 changes: 1,971 additions & 1,734 deletions incubator/nodejs-loopback/image/project/package-lock.json

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions incubator/nodejs-loopback/image/project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"directory": "incubator/nodejs-loopback/image/project"
},
"main": "dist/index.js",
"type": "dist/index.d.ts",
"scripts": {
"build": "lb-tsc",
"clean": "lb-clean dist *.tsbuildinfo",
Expand All @@ -18,29 +19,29 @@
"test": "lb-mocha --allow-console-logs \"dist/__tests__\""
},
"dependencies": {
"@loopback/boot": "^2.0.2",
"@loopback/context": "^3.2.0",
"@loopback/core": "^2.2.0",
"@loopback/extension-health": "^0.3.2",
"@loopback/extension-metrics": "^0.2.2",
"@loopback/openapi-v3": "^3.1.1",
"@loopback/repository": "^2.0.2",
"@loopback/rest": "^3.1.0",
"@loopback/rest-explorer": "^2.0.2",
"@loopback/service-proxy": "^2.0.2"
"@loopback/boot": "^3.1.1",
"@loopback/context": "^3.13.1",
"@loopback/core": "^2.13.0",
"@loopback/health": "^0.6.1",
"@loopback/metrics": "^0.5.1",
"@loopback/openapi-v3": "^5.1.1",
"@loopback/repository": "^3.2.1",
"@loopback/rest": "^9.1.0",
"@loopback/rest-explorer": "^3.0.4",
"@loopback/service-proxy": "^3.0.4"
},
"devDependencies": {
"@loopback/build": "^5.0.0",
"@loopback/eslint-config": "^6.0.2",
"@loopback/testlab": "^2.0.2",
"@types/node": "^10.17.17",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-mocha": "^6.3.0",
"source-map-support": "^0.5.16",
"typescript": "~3.8.3"
"@loopback/build": "^6.2.7",
"@loopback/eslint-config": "^10.0.3",
"@loopback/testlab": "^3.2.9",
"@types/node": "^10.17.45",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-eslint-plugin": "^2.3.0",
"eslint-plugin-mocha": "^8.0.0",
"source-map-support": "^0.5.19",
"typescript": "~4.0.5"
}
}
6 changes: 3 additions & 3 deletions incubator/nodejs-loopback/image/project/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import {ApplicationConfig, Constructor} from '@loopback/core';
import {Bootable} from '@loopback/boot';
import {RestApplication} from '@loopback/rest';
import {HealthComponent} from '@loopback/extension-health';
import {MetricsComponent} from '@loopback/extension-metrics';
import * as path from 'path';
import {HealthComponent} from '@loopback/health';
import {MetricsComponent} from '@loopback/metrics';
import path from 'path';

// The user-app is mounted from the template
const userAppModule = '../user-app';
Expand Down
2 changes: 1 addition & 1 deletion incubator/nodejs-loopback/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: LoopBack 4
version: 0.3.0
version: 0.4.0
description: LoopBack 4 API Framework for Node.js
maintainers:
- name: Raymond Feng
Expand Down
1 change: 1 addition & 0 deletions incubator/nodejs-loopback/templates/scaffold/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
coverage/
.eslintrc.js
78 changes: 75 additions & 3 deletions incubator/nodejs-loopback/templates/scaffold/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
# nodejs-loopback-scaffold

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.
This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the
[initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html).

It has been slightly tailored as a template for `appsody`.
## Install dependencies

[![LoopBack](https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/)
By default, dependencies were installed when this application was generated.
Whenever dependencies in `package.json` are changed, run the following command:

```sh
npm install
```

To only install resolved dependencies in `package-lock.json`:

```sh
npm ci
```

## Run the application

```sh
npm start
```

You can also run `node .` to skip the build step.

Open http://127.0.0.1:3000 in your browser.

## Rebuild the project

To incrementally build the project:

```sh
npm run build
```

To force a full build by cleaning up cached artifacts:

```sh
npm run clean
npm run build
```

## Fix code style and formatting issues

If `eslint` and `prettier` are enabled for this project, you can use the
following commands to check code style and formatting issues.

```sh
npm run lint
```

To automatically fix such issues:

```sh
npm run lint:fix
```

## Other useful commands

- `npm run migrate`: Migrate database schemas for models
- `npm run openapi-spec`: Generate OpenAPI spec into a file
- `npm run docker:build`: Build a Docker image for this application
- `npm run docker:run`: Run this application inside a Docker container

## Tests

```sh
npm test
```

## What's next

Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to
understand how you can continue to add features to this application.

[![LoopBack](<https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png>)](http://loopback.io/)
27 changes: 0 additions & 27 deletions incubator/nodejs-loopback/templates/scaffold/index.js

This file was deleted.

1 change: 0 additions & 1 deletion incubator/nodejs-loopback/templates/scaffold/index.ts

This file was deleted.

Loading

0 comments on commit 3f2cf38

Please sign in to comment.