Sign inSign up

jxadro/hellonode

By jxadro

•Updated almost 3 years ago

Image
0

10K+

jxadro/hellonode repository overview

var express = require('express');
var log4js = require('log4js');
var http = require('http');
var app = express();
var logger = log4js.getLogger('HelloKube');
var isHealthy = true;

var istioError = "false";
var istioDelay = 0;

logger.info("Starting...");


setInterval(function() {
	if (isHealthy) {
		logger.info("lalala....");
	} else {
		logger.info("cough...");
	}
}, 3000);


app.get("/istio/error", function(req, res, next) {
	logger.info("operation /istio/error invoked...");
	istioError = req.query.error;
	logger.info("istioError: " + istioError);
	res.send("istioError set to: "  + istioError);
});


app.get("/istio/delay", function(req, res, next) {
	logger.info("operation /istio/delay invoked...");
	istioDelay = req.query.delay;
	logger.info("delay: " + istioDelay);
	res.send("Delay set to: "  + istioDelay);
});

app.get("/istio/op", function(req, res, next) {
	logger.info("operation /istio/op invoked...");
	setTimeout(function() {
    		if (istioError === "false") {
			logger.info("returning GREEN");
			res.send("Istio GREEN");
		} else {
			logger.info("returning RED");
			res.status(500).send("Istio RED");
		}
	}, istioDelay);
	
});


app.get("/", function(req, res, next) {
	logger.info("operation / invoked...");
	res.send("I'm alive 8!!!");
});

app.get("/env", function(req, res, next) {
	res.json(process.env);
});

app.get("/pod", function(req, res, next) {
	var pod = process.env['HOSTNAME'];
	res.send("Pod serving request: " + pod);
});

app.get("/health", function(req, res, next) {
	if (isHealthy) {
		logger.info("operation /health invoked... returning GREEN");
		res.send("GREEN");
	} else {
		logger.info("operation /health invoked... returning RED");
		res.status(500).send("RED");
	}
});

app.get("/infect", function(req, res, next) {
	logger.info("operation /infect invoked...");
	isHealthy = false;
	res.send("I don't feel that good...");
});

app.get("/kill", function(req, res, next) {
	res.send("You are dead...");
	process.exit();
});

var port = process.env.PORT || 8080;

app.listen(port, function() {
	logger.info('HelloKube listening on port ' + port);
});



{
        "name": "HelloKube",
        "main": "app.js",
        "description": "Listeneint API Connect API Events",
        "version": "1.0.0",
        "private": false,
        "scripts": {
                "start": "node app.js"
        },
        "dependencies": {
                "express": "~4.2.0",
                "log4js": "~0.6.15"
        }
}

Dockerfile original:

FROM debian:8.7

RUN apt-get -y update && apt-get install -y curl

RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

RUN mkdir /app
ADD ./node/app.js /app
ADD ./node/package.json /app
RUN cd /app && npm install

ENV PORT 8080
EXPOSE 8080
WORKDIR "/app"
CMD ["npm", "start"]

Dockerfile tag 4.0:

FROM ubuntu:18.04

RUN apt-get -y update && apt-get install -y curl

#RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN apt-get install -y curl
RUN apt-get install -y wget
RUN apt-get install -y iputils-ping
RUN apt-get install -y dnsutils

RUN mkdir /app
ADD ./node/app.js /app
ADD ./node/package.json /app
RUN cd /app && npm install

RUN apt-get install -y ssh
RUN wget https://public.dhe.ibm.com/cloud/bluemix/cli/bluemix-cli/0.15.1/IBM_Cloud_CLI_0.15.1_amd64.tar.gz
RUN tar -xvf IBM_Cloud_CLI_0.15.1_amd64.tar.gz
RUN cd Bluemix_CLI/bin && ./ibmcloud plugin install kubernetes-service
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl


RUN mv /Bluemix_CLI/bin/ibmcloud /usr/local/bin/ && chmod +x /kubectl && mv /kubectl ./usr/local/bin
RUN echo "ibmcloud login -a https://cloud.ibm.com --sso" >> script.txt && echo "ibmcloud ks region-set us-south" >> script.txt && echo "ibmcloud ks cluster-config mycluster-dev" >> script.txt

ENV PORT 8080
EXPOSE 8080
WORKDIR "/app"
CMD ["npm", "start"]

Tag summary

Content type

Image

Digest

sha256:4f7579011…

Size

65.9 MB

Last updated

almost 3 years ago

docker pull jxadro/hellonode:6.1