Code Monkey home page Code Monkey logo

app1's Introduction

#App1 This is a sample web application which has written in Nodejs, using express framework.The app just will say Hello World! . The intention is to show how we can implement immutable deployment using docker based container. we will configure jenkis to pull the code and build and deploy new docker images each time we ask the jenkins to build the app.

you will need mesos-cicd project to setup dokcer, jenkins and mesos tools just simply using the Vagrant.So go and check it out this project first : https://github.com/farshi/mesos-cicd

#Tutorial

This section describes the source codes and shows you how it works.

$mkdir app1
$cd app1
$vim app.js
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World");
});

// Listen on port 8000, IP defaults to "0.0.0.0"
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

We need to defing pacakge.json to define which version of express framework we are going to use in this app.

  $vim package.json
{
  "name": "hello-world",
  "description": "hello world",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "3.x"
  },
  "scripts": {"start": "node app.js"}
}

We are going to do immutable deployment, so every time we want to change the code , we will create new container and put our application inside that container. Here is the Dockerfile code for creating our app docker image.

$vim Dockefile
FROM google/nodejs

WORKDIR /app
ADD package.json /app/
RUN npm install
ADD . /app

EXPOSE 8000
CMD []
ENTRYPOINT ["/nodejs/bin/npm", "start"]

for creating and pushing the docker image to the local docker registry run this command

$ docker build -t localhost:5000/reza/nodejs_app .
$ docker push localhost:5000/reza/nodejs_app

don't have local docker registry ? it's so simple ,containerizatoin made it simple. docker repositor inisde the docek :D, it's cool is'nt it , just run this command:

Run registry First

docker run -p 5000:5000 -v ./registry-stuff:/registry -e STORAGE_PATH=/registry registry

if you have jenkins server you can automate building docker images for each build and push the images to your local docker registry

go to jenkins console and define these two build steps and put each of these lines to corresponding build scripts

####Script for building : go to jenkins config and add a new build step to run shell script

sh build.sh $BUILD_NUMBER

and add another one and put these lines for

####script for deploying :

sh push.sh $BUILD_NUMBER

app1's People

Contributors

farshi avatar

Watchers

James Cloos avatar  avatar

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.