├── package.json ├── server.js ├── Jenkinsfile └── README.md /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker_web_app", 3 | "version": "1.0.0", 4 | "description": "Node.js on Docker", 5 | "author": "First Last ", 6 | "main": "server.js", 7 | "scripts": { 8 | "start": "node server.js" 9 | }, 10 | "dependencies": { 11 | "express": "^4.16.1" 12 | } 13 | } -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | const express = require('express'); 5 | 6 | // Constants 7 | const PORT = 8080; 8 | const HOST = '0.0.0.0'; 9 | 10 | // App 11 | const app = express(); 12 | app.get('/', (req, res) => { 13 | res.send('Hello World'); 14 | }); 15 | 16 | app.listen(PORT, HOST); 17 | console.log(`Running on http://${HOST}:${PORT}`); 18 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | 3 | agent any 4 | 5 | stages { 6 | 7 | stage('Install Dependencies') { 8 | steps { 9 | sh 'npm install' 10 | } 11 | } 12 | 13 | stage('Test') { 14 | steps { 15 | sh 'echo "testing application..."' 16 | } 17 | } 18 | 19 | stage("Deploy application") { 20 | steps { 21 | sh 'echo "deploying application..."' 22 | } 23 | 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Build and Deploy nodejs application on EC2 instance - Freestyle 2 | 3 | # Pre-requisites 4 | 5 | 1. A Jenkins server 6 | 1. A EC2 instance (Application server) and deploy node.js 7 | 8 | ### Setup nodejs packages on jenkins (needed for build) and application server (needed to deploy) 9 | 1. Enable nodejs packages on Linux server 10 | ```sh 11 | curl -sL https://rpm.nodesource.com/setup_15.x | bash - 12 | ``` 13 | 1. install development tools. 14 | ```sh 15 | yum groupinstall 'Development Tools' 16 | ``` 17 | 18 | 1. Install nodejs 19 | ```sh 20 | yum -y install nodejs 21 | ``` 22 | 23 | Setup Jenkins job 24 | 25 | ## Fork nodejs applicaton onto your repository 26 | 27 | Github URL: https://github.com/ravdy/nodejs.git 28 | 29 | Using simple "hello world" application from the [nodejs.org](https://nodejs.org/en/docs/guides/getting-started-guide/) website 30 | 31 | ## On Jenkins GUI 32 | 33 | 1. Create the new FreeStyle Project 34 | ```sh 35 | Git URL - https://github.com/ravdy/nodejs.git 36 | ``` 37 | BUILD --> Execute Shell npm install 38 | ```sh 39 | npm install 40 | tar czf easyio.tar-$BUILD_NUMBER.gz node_modules main.js package.json public LICENSE 41 | ``` 42 | 43 | ## To Deploy on nodejs application server 44 | --------------------------------------------------------------------------------