https://github.com/aicore/deploymentservice
This service would be used to orchestate deployment of services to cloud
https://github.com/aicore/deploymentservice
Last synced: 2 months ago
JSON representation
This service would be used to orchestate deployment of services to cloud
- Host: GitHub
- URL: https://github.com/aicore/deploymentservice
- Owner: aicore
- License: agpl-3.0
- Created: 2023-03-05T14:52:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-09T11:08:36.000Z (3 months ago)
- Last Synced: 2025-02-09T12:19:45.694Z (3 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# template-nodejs-server
A template project for nodejs server using fastify. Has integrated linting, testing,
coverage, reporting, GitHub actions for publishing to npm repository, dependency updates and other goodies.Easily use this template to quick start a production ready nodejs project template.
```shell
# do this to start server
cp ./src/a.json ./src/app.json
npm install
npm run serve# To hit end point, go to browser url http://127.0.0.1:5000/hello?name=rambo
# or to hit the authenticated url, do the curl command below
curl -X GET 'http://127.0.0.1:5000/helloAuth?name=rambo' -H 'authorization: Basic 123' -H 'Content-Type: application/json' -v```
```shell
# use this for continuous reload while development
npm run serve:dev
```
## Code Guardian[](https://github.com/aicore/template-nodejs/actions/workflows/build_verify.yml)
# TODOs after template use
## !!!Please see all issues in the generated repository as an issue will be generated tracking the fix of each of the below items.
1. Update package.json with your app defaults
2. Check Build actions on pull requests.
3. create a home page in wiki by going to wiki link https://github.com///wiki
4. Goto github `repository` > `settings`> and uncheck `Allow merge commits`. this is usually automatically done by code
guardian bots in core.ai org. so you may just need to verify it.
5. In sonar cloud, enable Automatic analysis from `Administration
Analysis Method` for the first time before a pull request is
raised: 
6. Check codacy runs on pull requests, set codacy defaults. You may remove codacy if sonar cloud is only needed.
7. Update the above Code Guardian badges; change all `id=aicore_template-nodejs-ts` to the sonar id of your project
fields. see this PR: https://github.com/aicore/libcache/pull/13# Commands available
## Building
Since this is a pure JS template project, build command just runs test with coverage.
```shell
> npm install // do this only once.
> npm run build
```## Linting
To lint the files in the project, run the following command:
```shell
> npm run lint
```To Automatically fix lint errors:
```shell
> npm run lint:fix
```## Testing
### Run unit tests
```shell
> npm run test:unit
```### Running integration tests locally
```shell
> npm run test:integ
```
You can edit `src/testConfig.json` to change app config for tests after running the above command.### Running integration tests in GitHub actions
You have to set a repository secret `APP_CONFIG_FOR_INTEG_TESTS` with
content of the text config.
* Goto your repository settings https://github.com///settings/secrets/actions
* Create a new `Repository secret` with name `APP_CONFIG_FOR_INTEG_TESTS` and the secret as the config file contents.
* The build verify action should now be able to use the secret.
* Note that pull requests cannot read repository secrets and subsequently cannot run integration tests.### To run all tests:
```shell
> npm run test
Hello world Tests
✔ should return Hello World
#indexOf()
✔ should return -1 when the value is not present
```Additionally, to run unit/integration tests only, use the commands:
```shell
> npm run test:unit
> npm run test:integ
```## Coverage Reports
To run all tests with coverage:
```shell
> npm run cover
Hello world Tests
✔ should return Hello World
#indexOf()
✔ should return -1 when the value is not present2 passing (6ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------=============================== Coverage summary ===============================
Statements : 100% ( 5/5 )
Branches : 100% ( 2/2 )
Functions : 100% ( 1/1 )
Lines : 100% ( 5/5 )
================================================================================
Detailed unit test coverage report: file:///template-nodejs/coverage-unit/index.html
Detailed integration test coverage report: file:///template-nodejs/coverage-integration/index.html
```After running coverage, detailed reports can be found in the coverage folder listed in the output of coverage command.
Open the file in browser to view detailed reports.To run unit/integration tests only with coverage
```shell
> npm run cover:unit
> npm run cover:integ
```Sample coverage report:
### Unit and Integration coverage configs
Unit and integration test coverage settings can be updated by configs `.nycrc.unit.json` and `.nycrc.integration.json`.
See https://github.com/istanbuljs/nyc for config options.
# Publishing packages to NPM
## Preparing for release
Please run `npm run release` on the `main` branch and push the changes to main. The release command will bump the npm
version.!NB: NPM publish will faill if there is another release with the same version.
## Publishing
To publish a package to npm, push contents to `npm` branch in
this repository.## Publishing `@aicore/package*`
If you are looking to publish to package owned by core.ai, you will need access to the GitHub Organization
secret `NPM_TOKEN`.For repos managed by [aicore](https://github.com/aicore) org in GitHub, Please contact your Admin to get access to
core.ai's NPM tokens.## Publishing to your own npm account
Alternatively, if you want to publish the package to your own npm account, please follow these docs:
1. Create an automation access token by following
this [link](https://docs.npmjs.com/creating-and-viewing-access-tokens).
2. Add NPM_TOKEN to your repository secret by following
this [link](https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow)To edit the publishing workflow, please see file: `.github/workflows/npm-publish.yml`
# Dependency updates
We use Rennovate for dependency updates: https://blog.logrocket.com/renovate-dependency-updates-on-steroids/
* By default, dep updates happen on sunday every week.
* The status of dependency updates can be viewed here if you have this repo permissions in
github: https://app.renovatebot.com/dashboard#github/aicore/template-nodejs
* To edit rennovate options, edit the rennovate.json file in root,
see https://docs.renovatebot.com/configuration-options/
Refer# Code Guardian
Several automated workflows that check code integrity are integrated into this template.
These include:1. GitHub actions that runs build/test/coverage flows when a contributor raises a pull request
2. [Sonar cloud](https://sonarcloud.io/) integration using `.sonarcloud.properties`
1. In sonar cloud, enable Automatic analysis from `Administration
Analysis Method` for the first
time ## IDE setup
SonarLint is currently available as a free plugin for jetbrains, eclipse, vscode and visual studio IDEs.
Use sonarLint plugin for webstorm or any of the available
IDEs from this link before raising a pull request: https://www.sonarlint.org/ .SonarLint static code analysis checker is not yet available as a Brackets
extension.## Internals
### Testing framework: Mocha , assertion style: chai
See https://mochajs.org/#getting-started on how to write tests
Use chai for BDD style assertions (expect, should etc..). See move here: https://www.chaijs.com/guide/styles/#expect### Mocks and spies:
Since it is not that straight forward to mock es6 module imports, use the follow pull request as reference to mock
imported libs:* sample pull request: https://github.com/aicore/libcache/pull/6/files
* [setting up mocks](https://github.com/aicore/libcache/blob/485b1b6244f7022eb0a83d9f72d897fe712badbe/test/unit/setup-mocks.js)
* [using the mocks](https://github.com/aicore/libcache/pull/6/files#diff-8ea7ccf28b28a0ae7b43e468abd3e9a8bb411bb329ad5cb45eb9a93709ed8dc5R2)
ensure to import `setup-mocks.js` as the first import of all files in tests.#### using sinon lib if the above method doesn't fit your case
if you want to mock/spy on fn() for unit tests, use sinon. refer docs: https://sinonjs.org/
### Note on coverage suite used here:
we use c8 for coverage https://github.com/bcoe/c8. Its reporting is based on nyc, so detailed docs can be found
here: https://github.com/istanbuljs/nyc ; We didn't use nyc as it do not yet have ES module support
see: https://github.com/digitalbazaar/bedrock-test/issues/16 . c8 is drop replacement for nyc coverage reporting tool