Commit e8f6b04a authored by Andres Toomsalu's avatar Andres Toomsalu
Browse files

Initial commit

parents
FROM centos:centos7
MAINTAINER OpenNode LLC <info@opennodecloud.com>
# Install epel-release
RUN yum install -y http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# install pre-requisites
RUN yum install -y npm net-tools
# add health check script
ADD nf-demo-app-check /usr/bin/nf-demo-app-check
# make the nodejs src folder available in the docker image
ADD nodejs/ /srv/nodejs
WORKDIR /srv/nodejs
# install the dependencies from the package.json file
RUN npm install
# make port 80 available outside of the image
EXPOSE 80
# start node with the index.js file of our hello-world application
CMD ["node", "index.js"]
NFDIR = /etc/nodefabric
build:
docker build -t docker.io/opennode/nf-demo-app .
push:
docker push docker.io/opennode/nf-demo-app
dev-install:
install -m 644 nodefabric/nf-demo-app.conf ${NFDIR}/conf.d/nf-demo-app.conf
install -m 644 nodefabric/nf-demo-app-haproxy.json ${NFDIR}/files.d/haproxy/consul.tpl.d/nf-demo-app-haproxy.json
install -m 644 nodefabric/nf-demo-app-haproxy.tpl ${NFDIR}/files.d/haproxy/haproxy.tpl.d/nf-demo-app-haproxy.tpl
install -m 644 nodefabric/nf-demo-app.service /usr/lib/systemd/system/nf-demo-app.service
docker exec -t nf-haproxy /haproxy-hup.sh
systemctl daemon-reload
# NodeFabric Demo App
## Building
```bash
# cloning
git clone git@code.opennodecloud.com:nodefabric/nf-demo-app.git
# building
cd nf-demo-app
make build
# tagging
IMAGE_ID=$( docker images | awk '/^opennode\/nf-demo-app/' | awk '/latest/ { print $3 }' )
echo $IMAGE_ID
IMAGE_VERSION=0.0.1
docker tag $IMAGE_ID docker.io/opennode/nf-demo-app:${IMAGE_VERSION}
# pushing all tags
make push
```
## Running
```bash
# pulling
docker pull opennode/nf-demo-app:latest
```
## Debugging
```bash
```
#!/bin/bash
if test -n "$( netstat -ln | awk '/:80 /' )"; then
# report success
exit 0
else
# report failure
exit 2
fi
template {
source = "/etc/haproxy/haproxy.tpl.d/nf-demo-app-haproxy.tpl"
destination = "/etc/haproxy/haproxy.cfg.d/nf-demo-app.cfg"
command = "/haproxy-hup.sh || true"
}
listen nf-demo-app
bind *:8010
balance source
mode tcp
option tcpka
{{range service "nf-demo-app"}}
server {{.Node}} {{.Address}}:{{.Port}} check{{end}}
DEMOAPP_INSTANCE="nf-demo-app"
DEMOAPP_IMAGE="opennode/nf-demo-app"
DEMOAPP_BIND_ADDR="$HOST_PUBLIC_IP"
DEMOAPP_DATADIR="/var/lib/nf-demo-app"
DEMOAPP_HELLOWORLD="Im here!"
[Unit]
Description=NodeFabric Demo App Service
Requires=docker.service
Wants=nf-consul.service
Wants=nf-haproxy.service
After=nf-haproxy.service
[Service]
EnvironmentFile=/etc/nodefabric/conf.d/nf-demo-app.conf
TimeoutStartSec=0
ExecStartPre=/usr/bin/mkdir -p $DEMOAPP_DATADIR
ExecStartPre=-/usr/bin/docker kill $DEMOAPP_INSTANCE
ExecStartPre=-/usr/bin/docker rm $DEMOAPP_INSTANCE
ExecStart=/usr/bin/bash -c "source /etc/nodefabric/nodefabric.conf && \
docker run --name=$DEMOAPP_INSTANCE -h $HOSTNAME \
-p $DEMOAPP_BIND_ADDR:8010:80 \
-e SERVICE_80_CHECK_CMD=/usr/bin/nf-demo-app-check \
-e DEMOAPP_HELLOWORLD=\"$DEMOAPP_HELLOWORLD\" \
-v $DEMOAPP_DATADIR:/var/lib/nf-demo-app \
$DEMOAPP_IMAGE"
ExecStop=-/usr/bin/docker stop $DEMOAPP_INSTANCE
[Install]
WantedBy=multi-user.target
var express = require('express');
var os = require("os");
var app = express();
var hostname = os.hostname();
app.get('/', function (req, res) {
res.send('<html><body>Hello from Node.js container ' + hostname + '</body></html>');
});
app.listen(80);
console.log('Running on http://localhost');
{
"name": "nodefabric-hello-world",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello world app on NodeFabric",
"author": "opennodecloud.com",
"dependencies": {
"express": "4.12.0"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment