Code files

This commit is contained in:
Akhil
2017-07-31 11:33:31 +05:30
parent 073a63ebdd
commit b9ae409ec0
801 changed files with 17535 additions and 0 deletions
@@ -0,0 +1,4 @@
.git
.gitignore
node_modules
npm-debug.log
@@ -0,0 +1,7 @@
FROM node:slim
RUN mkdir -p /home/node/service
WORKDIR /home/node/service
COPY package.json /home/node/service
RUN npm install
COPY . /home/node/service
CMD [ "node", "index.js" ]
@@ -0,0 +1,32 @@
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'source ~/.bashrc && cd adderservice && npm install'
}
}
stage('Test'){
steps {
sh 'source ~/.bashrc && cd adderservice && npm test'
}
}
stage('Container'){
steps {
sh 'source ~/.bashrc && cd adderservice && sh build.sh container'
}
}
stage('Deploy'){
steps {
sh 'source ~/.bashrc && cd adderservice && sh build.sh deploy'
}
}
}
}
@@ -0,0 +1,23 @@
#!/bin/bash
source ~/.bashrc
GITSHA=$(git rev-parse --short HEAD)
case "$1" in
container)
sudo -u pelger docker build -t adderservice:$GITSHA .
sudo -u pelger docker tag adderservice:$GITSHA pelger/adderservice:$GITSHA
sudo -i -u pelger docker push pelger/adderservice:$GITSHA
;;
deploy)
sed -e s/_NAME_/adderservice/ -e s/_PORT_/8080/ < ../deployment/service-template.yml > svc.yml
sed -e s/_NAME_/adderservice/ -e s/_PORT_/8080/ -e s/_IMAGE_/pelger\\/adderservice:$GITSHA/ < ../deployment/deployment-template.yml > dep.yml
sudo -i -u pelger kubectl apply -f $(pwd)/svc.yml
sudo -i -u pelger kubectl apply -f $(pwd)/dep.yml
;;
*)
echo 'invalid build command'
exit 1
;;
esac
@@ -0,0 +1,7 @@
'use strict'
const wiring = require('./wiring')
const service = require('./service')()
wiring(service)
@@ -0,0 +1,15 @@
{
"name": "adder-service",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"no test specified\" && exit 0"
},
"keywords": [],
"author": "Peter Elger <peter.elger@nearform.com>",
"license": "ISC",
"dependencies": {
"restify": "^4.3.0"
}
}
@@ -0,0 +1,13 @@
'use strict'
module.exports = service
function service () {
function add (args, cb) {
const {first, second} = args
const result = (parseInt(first, 10) + parseInt(second, 10))
cb(null, {result: result.toString()})
}
return { add }
}
@@ -0,0 +1,27 @@
'use strict'
const restify = require('restify')
const { ADDERSERVICE_SERVICE_PORT } = process.env
module.exports = wiring
function wiring (service) {
const server = restify.createServer()
server.get('/add/:first/:second', (req, res, next) => {
service.add(req.params, (err, result) => {
if (err) {
res.send(err)
next()
return
}
res.send(200, result)
next()
})
})
server.listen(ADDERSERVICE_SERVICE_PORT, '0.0.0.0', () => {
console.log('%s listening at %s', server.name, server.url)
})
}