1.1.7 • Published 3 years ago

holy-cow-nodejs v1.1.7

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 years ago

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:

  • Build
    • Use Kaniko
    • One process per container
    • Small images
  • CI/CD
    • Gitlab CI
  • Healthchecks
    • Format
      • Readiness /ready
      • Liveness /healthy
  • Logging
    • Format
      • JSON
      • Fields
  • Monitoring
    • Expose a /metrics endpoint
    • Use existing libraries to expose your metrics
    • Use your application port for your metrics endpoint if possible
    • Follow the default prometheus naming conventions for your metrics
  • API Docs
    • Use OpenAPI
    • Provide endpoint for swagger.json
    • Provide swagger ui at /api-docs
  • Requests & Limits
  • Scaling
  • Security
    • Use Helmet
  • Startup and Shutdown
  • Statelessness
  • Versioning

Steps used to create this project

  1. Create Repo in Gitlab & Clone

    git clone git@gitlab.open-xchange.com:holycow/node.js.git

  2. Initialize package.json

    yarn init

  3. Add .gitignore and .editorconfig.

  4. Add ESlint for Linting

    yarn add eslint eslint-config-standard@"^17.0.0-1" eslint-plugin-promise eslint-plugin-import eslint-plugin-n --dev

  5. 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"
      ]
    }
  6. Add lint-staged and husky for linting in pre-commit hooks

    npx mrm@2 lint-staged

  7. Add following dependencies:

    yarn add express helmet pino-http dotenv-defaults @cloudnative/health-connect prometheus-api-metrics prom-client swagger-ui-express js-yaml

  8. Create .env.defaults file. Note: Only add safe to commit env defaults.

  9. Write the actual code in index.js. See comments in index.js to follow along.

Kubernetes

  1. Create own namespace (replace yournamespace with your namespace name)
kubectl create namespace yournamespace
  1. Set current namespace
kubectl config set-context --current --namespace=yournamespace
  1. 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 -
  1. Create helm chart and amend templates
mkdir helm
helm create helm/nodejs

Gitlab CI

See comments in .gitlab-ci.yml.