From bfdcb9949324d1d5e894ef87a08eb686a77763a2 Mon Sep 17 00:00:00 2001 From: Igor <29488070+igormisiorny@users.noreply.github.com> Date: Sat, 23 Nov 2019 17:38:53 +0100 Subject: [PATCH] Add Jenkinsfile and Project --- Dockerfile | 13 +++++++++++++ Jenkinsfile | 25 +++++++++++++++++++++++++ main.js | 12 ++++++++++++ package.json | 19 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 main.js create mode 100644 package.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec4c987 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# use a node base image +FROM node:7-onbuild + +# set maintainer +LABEL maintainer "miiro@getintodevops.com" + +# set a health check +HEALTHCHECK --interval=5s \ + --timeout=5s \ + CMD curl -f http://127.0.0.1:8000 || exit 1 + +# tell docker what port to expose +EXPOSE 8000 \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7a62cec --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,25 @@ +node { + def app + + stage('Clone repository') { + /* Let's make sure we have the repository cloned to our workspace */ + + checkout scm + } + + stage('Build image') { + /* This builds the actual image; synonymous to + * docker build on the command line */ + + app = docker.build("getintodevops/hellonode") + } + + stage('Test image') { + /* Ideally, we would run a test framework against our image. + * For this example, we're using a Volkswagen-type approach ;-) */ + + app.inside { + sh 'echo "Tests passed"' + } + } +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..43054a5 --- /dev/null +++ b/main.js @@ -0,0 +1,12 @@ +// load the http module +var http = require('http'); + +// configure our HTTP server +var server = http.createServer(function (request, response) { + response.writeHead(200, {"Content-Type": "text/plain"}); + response.end("Hello getintodevops.com\n"); +}); + +// listen on localhost:8000 +server.listen(8000); +console.log("Server listening at http://127.0.0.1:8000/"); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..3132814 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "getintodevops-hellonode", + "version": "1.0.0", + "description": "A Hello World HTTP server", + "main": "main.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node main.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/getintodevops/hellonode/" + }, + "keywords": [ + "node", + "docker", + "dockerfile" + ] +} \ No newline at end of file