Giter Club home page Giter Club logo

icp-nodejs-sample's Introduction

Node.js sample Helm Chart

This sample is for demonstrative purposes only and is NOT for production use.

Introduction

This Helm Chart deploys a sample Node.js web application hosting its own documentation which guides you through the process of creating and deploying your own Node.js applications into IBM Cloud Private.

This sample was created using idt create and more information can be found within the application itself.

  • This example uses appmetrics and appmetrics-dash: the endpoint being /appmetrics-dash.
  • This example features the "scrape" annotation in the <chart directory>/templates/service.yaml file. In combination with the appmetrics-prometheus module inclusion and usage, this enables the sample to be automatically scraped by a deployed instance of Prometheus in order for metrics to be gathered and displayed using the Prometheus web UI. You can view the raw data that will be available to Prometheus at the /metrics endpoint. This allows developers to quickly determine how the application is performing across potentially many Kubernetes pods.
  • This example uses appmetrics-zipkin. If Zipkin is deployed (e.g. with the Microservice Builder fabric), trace information will be available under the service name "icp-nodejs-sample". To enable this feature, modify Dockerfile and set USE_ZIPKIN. You can dynamically modify applications as well using the IBM CLoud Private web UI - this includes the setting of environment variables and it's recommended you restart the pod for the change to take effect.
  • This example can be deployed using the IBM Cloud Developer Tools.

Prerequisites

There is only one optional requirement to make the most out of this sample: you should have Prometheus deployed into your IBM Cloud Private cluster where this sample will be installed. This is not a mandatory step and can be done after deployment, happy installing!

Installing the Chart

The Helm chart can be installed from the app center by finding the nodejs-sample and following the installation steps.

If you prefer to use the command line instead, run the following command from the directory containing Chart.yaml:

helm install --name tester . where tester can be anything: this is the desired name of the release so it won't be an automatically generated one.

You can find more information about deployment methods in the IBM Cloud Private documentation.

Verifying the Chart

You can view the deployed sample in your web browser, for all features to be available the sample application is best viewed in Google Chrome or Safari.

To retrieve the IP and port of this deployed application: export SAMPLE_NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")

export SAMPLE_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})

Open your web browser at http://${SAMPLE_NODE_IP}:${SAMPLE_NODE_PORT} to view the sample.

Uninstalling the Chart

If you installed it with helm install --name tester . you'd remove the sample with helm delete --purge tester. You can find the deployment with helm list --all and searching for an entry with the chart name "ibm-nodejs-sample".

Testing the Chart with Helm

You can programatically run the test in the following ways.

  • cd chart/ibm-nodejs-sample then do ./test-chart.sh OR
  • helm test tester: assuming you've deployed it with the release name sample.

Configuration

The following table lists the configurable parameters of the ibm-nodejs-sample chart and their default values.

Parameter Description Default
image.repository image repository ibmcom/icp-nodejs-sample
image.tag Image tag latest
image.pullPolicy Image pull policy Always
livenessProbe.initialDelaySeconds How long to wait before beginning the checks our pod(s) are up 30
livenessProbe.periodSeconds The interval at which we'll check if a pod is running OK before being restarted 10
service.name k8s service name Node
service.type k8s service type exposing port NodePort
service.port TCP Port for this service 3000
resources.limits.memory Memory resource limits 128m
resources.limits.cpu CPU resource limits 100m

Configuring Node.js applications

See the Node.js @ IBM developer center for all things Node.js - including more samples, tutorials and blog posts. For configuring Node.js itself, consult the official Node.js community documentation.

Deploying on platforms other than x86-64

  • Multiarch images are used so the correct Node.js Docker image will be pulled based on your platform. Supported platforms for this sample include ppc64le, x86-64 and s390x.
  • Note that the IBM Cloud Developer Tools are not available for every platform: consult the CLI docs to find out more.

Disclaimers

Node.js is an official trademark of Joyent. Images are used according to the Node.js visual guidelines - no copyright claims are made. You can view the guidelines here.

This sample is not formally related to or endorsed by the official Node.js open source or commercial project.

icp-nodejs-sample's People

Contributors

a-roberts avatar bethgriggs avatar tomleah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

icp-nodejs-sample's Issues

Suggestions to improve your Dockerfile

Hi,

The Dockerfile can be improved in a couple of areas:

  1. Implement the best practice for writing Dockerfiles for running apt-get. The best practice says to always combine RUN apt-get update with apt-get install in the same RUN statement. For the full explanation see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
    For example:
RUN apt-get update && apt-get install -y  \
		wget \
	&& rm -rf /var/lib/apt/lists/*
  1. Add node_modules to .dockerignore. If you do the instruction RUN rm -rf ./node_modules; can be removed.
  2. Remove the instruction RUN cd /app;, you already used WORKDIR "/app" so you are already in /app
  3. Don't use semi-colons at the end of an instruction
  4. I wouldn't use COPY . /app, it copies everything in the current directory to /app (except what is in .dockerignore of course). The contents of /app with the current Dockerfile looks like this:
root@fa0fc7257bd6:/app# ls -latr
total 384
drwxr-xr-x   3 root root   4096 Feb 23 07:45 views
drwxr-xr-x   2 root root   4096 Feb 23 07:45 test
drwxr-xr-x   5 root root   4096 Feb 23 07:45 server
drwxr-xr-x   5 root root   4096 Feb 23 07:45 public
-rw-r--r--   1 root root   1135 Feb 23 07:45 package.json
-rw-r--r--   1 root root 266356 Feb 23 07:45 package-lock.json
drwxr-xr-x   4 root root   4096 Feb 23 07:45 multiarch-manifests
-rw-r--r--   1 root root    155 Feb 23 07:45 manifest.yml
-rw-r--r--   1 root root   2752 Feb 23 07:45 idt.js
-rw-r--r--   1 root root    672 Feb 23 07:45 gulpfile.js
drwxr-xr-x   2 root root   4096 Feb 23 07:45 docker-8
drwxr-xr-x   2 root root   4096 Feb 23 07:45 docker-6
-rw-r--r--   1 root root    556 Feb 23 07:45 cli-config.yml
drwxr-xr-x   3 root root   4096 Feb 23 07:45 chart
-rw-r--r--   1 root root   6712 Feb 23 07:45 README.md
-rw-r--r--   1 root root  13317 Feb 23 07:45 NOTICES
-rw-r--r--   1 root root  11351 Feb 23 07:45 LICENSE
-rw-r--r--   1 root root    147 Feb 23 07:45 Jenkinsfile
-rw-r--r--   1 root root    394 Feb 23 07:45 Dockerfile
-rw-r--r--   1 root root    109 Feb 23 07:45 .gitignore
drwxr-xr-x   7 root root   4096 Feb 23 07:45 .git
-rw-r--r--   1 root root      5 Feb 23 07:45 .dockerignore
drwxr-xr-x 133 root root   4096 Feb 23 07:48 node_modules
drwxr-xr-x   1 root root   4096 Feb 23 07:48 .
drwxr-xr-x   1 root root   4096 Feb 23 07:48 ..

In my view a lot of stuff that should not be in the /app directory. Of course you can update .dockerignore but it might be a better idea to create a separate folder for your code and copy that folder and individual files to /app instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.