holy-cow-nodejs
v1.1.7
Published
*Note: Cluster bindings are missing for the holy cow group in gitlab so gitlab ci will fail to deploy, until this is resolved.* test
Downloads
2
Readme
Holycow node.js example project
Note: Cluster bindings are missing for the holy cow group in gitlab so gitlab ci will fail to deploy, until this is resolved. test
great contribution
Status of project:
- [x] Build
- [x] Use Kaniko
- [x] One process per container
- [x] Small images
- [x] CI/CD
- [x] Gitlab CI
- [x] Healthchecks
- [x] Format
- [x] Readiness /ready
- [x] Liveness /healthy
- [x] Format
- [x] Logging
- [x] Format
- [x] JSON
- [x] Fields
- [x] Format
- [x] Monitoring
- [x] Expose a
/metrics
endpoint - [x] Use existing libraries to expose your metrics
- [x] Use your application port for your metrics endpoint if possible
- [x] Follow the default prometheus naming conventions for your metrics
- [x] Expose a
- [x] API Docs
- [x] Use OpenAPI
- [x] Provide endpoint for swagger.json
- [x] Provide swagger ui at /api-docs
- [ ] Requests & Limits
- [ ] Scaling
- [ ] Security
- [x] Use Helmet
- [ ] Startup and Shutdown
- [ ] Statelessness
- [ ] Versioning
Steps used to create this project
Create Repo in Gitlab & Clone
git clone [email protected]:holycow/node.js.git
Initialize package.json
yarn init
Add .gitignore and .editorconfig.
Add ESlint for Linting
yarn add eslint eslint-config-standard@"^17.0.0-1" eslint-plugin-promise eslint-plugin-import eslint-plugin-n --dev
Define style guide for eslint by creating .eslintrc.json. We are using standard to save time by avoiding bikeshedding about code style.
{ "root": true, "env": { "node": true, "es2022": true }, "extends": [ "standard" ] }
Add lint-staged and husky for linting in pre-commit hooks
npx mrm@2 lint-staged
Add following dependencies:
- express as our web framework
- @open-xchange/logging for logging
- @open-xchange/metrics for prometheus based metrics
- helmet for security
- dotenv-defaults for easy env handling
- cloud health connect for readiness/liveness checks
- swagger-ui-express for swagger ui
yarn add express helmet pino-http dotenv-defaults @cloudnative/health-connect prometheus-api-metrics prom-client swagger-ui-express js-yaml
Create .env.defaults file. Note: Only add safe to commit env defaults.
Write the actual code in index.js. See comments in index.js to follow along.
Kubernetes
- Create own namespace (replace yournamespace with your namespace name)
kubectl create namespace yournamespace
- Set current namespace
kubectl config set-context --current --namespace=yournamespace
- Create registry secret
kubectl create secret docker-registry gitlab-registry-credentials --docker-server=registry.gitlab.open-xchange.com --docker-username=$GITLAB_USERNAME --docker-password=$GITLAB_TOKEN --dry-run=client -o yaml | kubectl apply -f -
- Create helm chart and amend templates
mkdir helm
helm create helm/nodejs
Gitlab CI
See comments in .gitlab-ci.yml.