Skip to content

Commit d2511aa

Browse files
committed
Initial version
1 parent d8c678e commit d2511aa

17 files changed

+245
-36
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.git
3+
.gitignore
4+
TEST-RESULTS.xml

.gitignore

+6-36
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,30 @@
22
logs
33
*.log
44
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
75

86
# Runtime data
97
pids
108
*.pid
119
*.seed
12-
*.pid.lock
1310

1411
# Directory for instrumented libs generated by jscoverage/JSCover
1512
lib-cov
1613

1714
# Coverage directory used by tools like istanbul
1815
coverage
1916

20-
# nyc test coverage
21-
.nyc_output
22-
2317
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2418
.grunt
2519

26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
2920
# node-waf configuration
3021
.lock-wscript
3122

32-
# Compiled binary addons (https://nodejs.org/api/addons.html)
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
3324
build/Release
3425

35-
# Dependency directories
36-
node_modules/
37-
jspm_packages/
38-
39-
# TypeScript v1 declaration files
40-
typings/
41-
42-
# Optional npm cache directory
43-
.npm
44-
45-
# Optional eslint cache
46-
.eslintcache
47-
48-
# Optional REPL history
49-
.node_repl_history
50-
51-
# Output of 'npm pack'
52-
*.tgz
53-
54-
# Yarn Integrity file
55-
.yarn-integrity
56-
57-
# dotenv environment variables file
58-
.env
26+
# Dependency directory
27+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
28+
node_modules
29+
/package-lock.json
5930

60-
# next.js build output
61-
.next
31+
TEST-RESULTS.xml

.vsts-ci.acr.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build Docker image for this app
2+
# https://docs.microsoft.com/vsts/pipelines/languages/docker?view=vsts
3+
4+
queue: 'Hosted Linux Preview'
5+
6+
variables:
7+
imageName: '$(Build.DefinitionName):$(Build.BuildId)'
8+
# define two more variables dockerId and dockerPassword in the build pipeline in UI
9+
10+
steps:
11+
- script: |
12+
npm install
13+
npm test
14+
docker build -t $(dockerId).azurecr.io/$(imageName) .
15+
docker login -u $(dockerId).azurecr.io -p $pswd $(dockerId).azurecr.io
16+
docker push $(dockerId).azurecr.io/$(imageName)
17+
env:
18+
pswd: $(dockerPassword)
19+
20+
- task: PublishTestResults@2
21+
inputs:
22+
testRunner: JUnit
23+
testResultsFiles: '**/TEST-RESULTS.xml'

.vsts-ci.docker.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build Docker image for this app
2+
# https://docs.microsoft.com/vsts/pipelines/languages/docker?view=vsts
3+
4+
queue: 'Hosted Linux Preview'
5+
6+
variables:
7+
imageName: '$(Build.DefinitionName):$(Build.BuildId)'
8+
# define two more variables dockerId and dockerPassword in the build pipeline in UI
9+
10+
steps:
11+
- script: |
12+
npm install
13+
npm test
14+
docker build -t $(dockerId)/$(imageName) .
15+
docker login -u $(dockerId) -p $pswd
16+
docker push $(dockerId)/$(imageName)
17+
env:
18+
pswd: $(dockerPassword)
19+
20+
- task: PublishTestResults@2
21+
inputs:
22+
testRunner: JUnit
23+
testResultsFiles: '**/TEST-RESULTS.xml'

.vsts-ci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build NodeJS Express app using VSTS
2+
# https://docs.microsoft.com/vsts/pipelines/languages/javascript?view=vsts
3+
4+
queue: 'Hosted Linux Preview'
5+
6+
steps:
7+
- script: |
8+
npm install
9+
npm test
10+
11+
- task: PublishTestResults@2
12+
inputs:
13+
testRunner: JUnit
14+
testResultsFiles: '**/TEST-RESULTS.xml'
15+
16+
- task: ArchiveFiles@2
17+
inputs:
18+
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
19+
includeRootFolder: false
20+
21+
- task: PublishBuildArtifacts@1

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Create a container image for the NodeJS sample app
2+
# See http://docs.microsoft.com/vsts/pipelines/languages/docker for more information
3+
FROM node:boron
4+
5+
# Create app directory
6+
WORKDIR /app
7+
8+
# Copy files
9+
COPY . .
10+
11+
# Install app dependencies
12+
RUN npm install
13+
14+
EXPOSE 3000 80
15+
CMD ["npm", "start"]

docs/.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.sh text eol=lf

docs/Dockerfile.multistage

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# First stage of multi-stage build
2+
FROM node:boron
3+
WORKDIR /app
4+
5+
# copy the contents of agent working directory on host to workdir in container
6+
COPY . .
7+
8+
# dotnet commands to build, test, and publish
9+
RUN npm install
10+
RUN npm test
11+
12+
# Second stage - Build runtime image
13+
FROM node:boron
14+
WORKDIR /app
15+
COPY . .
16+
RUN npm install
17+
EXPOSE 3000 80
18+
CMD ["npm", "start"]

docs/Dockerfile.test

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This Dockerfile is for a test container to demonstrate use of docker-compose with VSTS or TFS
2+
# See http://docs.microsoft.com/vsts/pipelines/languages/docker for more information
3+
4+
FROM ubuntu:trusty
5+
RUN apt-get update && apt-get install -yq curl && apt-get clean
6+
WORKDIR /app
7+
ADD docs/test.sh /app/test.sh
8+
CMD ["bash", "test.sh"]

docs/deploy.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Script to deploy the app
2+
# This file is needed only when you want to deploy the app to a Linux VM
3+
4+
# install node
5+
pushd .
6+
cd ~
7+
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
8+
sudo bash nodesource_setup.sh
9+
sudo apt-get install nodejs -y
10+
sudo apt-get install build-essential -y
11+
12+
# install express
13+
sudo npm install express -y -g
14+
popd
15+
16+
# configure nginx
17+
sudo rm -f /etc/nginx/sites-enabled/default
18+
sudo cp -f ./nginx-config /etc/nginx/sites-available/example
19+
sudo ln -fs /etc/nginx/sites-available/example /etc/nginx/sites-enabled
20+
sudo service nginx reload
21+
22+
# install pm2 and start the node server as a daemon
23+
cd ..
24+
sudo npm install pm2 -g -y
25+
pm2 delete example -s
26+
pm2 start server.js -n example

docs/docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Docker compose file to bring up app and test containers
2+
# See http://docs.microsoft.com/vsts/pipelines/languages/docker for more information
3+
sut:
4+
build: .
5+
dockerfile: docs/Dockerfile.test
6+
links:
7+
- web
8+
web:
9+
build: .
10+
dockerfile: Dockerfile

docs/nginx-config

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server {
2+
server_name your.domain.com;
3+
listen 80;
4+
5+
location / {
6+
proxy_set_header X-Real-IP $remote_addr;
7+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
8+
proxy_set_header Host $http_host;
9+
proxy_set_header X-NginX-Proxy true;
10+
proxy_pass http://127.0.0.1:3000;
11+
proxy_redirect off;
12+
}
13+
}

docs/test.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test driver script to be used in a container
2+
# See http://docs.microsoft.com/vsts/pipelines/languages/docker for more information
3+
sleep 5
4+
if curl web | grep -q 'Hello world'; then
5+
echo "Tests passed!"
6+
exit 0
7+
else
8+
echo "Tests failed!"
9+
exit 1
10+
fi
11+

gulpfile.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var gulp = require('gulp');
2+
var mocha = require('gulp-mocha');
3+
var fs = require('fs');
4+
5+
gulp.task('default', function () {
6+
gulp.src('tests/**/*.js')
7+
.pipe(mocha({
8+
reporter: 'mocha-junit-reporter',
9+
reporterOptions{
10+
         mochaFile'./TEST-RESULTS.xml'
11+
}
12+
}));
13+
});

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "HelloWorld",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Hello World",
6+
"main": "server.js",
7+
"author": {
8+
"name": "",
9+
"email": ""
10+
},
11+
"dependencies": {
12+
"express": "^4.13.3",
13+
"mocha": "^3.0.0"
14+
},
15+
"devDependencies": {
16+
"gulp": "^3.9.0",
17+
"gulp-mocha": "^2.2.0",
18+
"mocha-junit-reporter": "^1.12.0"
19+
},
20+
"scripts": {
21+
"test": "./node_modules/.bin/mocha tests/**/*.js --reporter mocha-junit-reporter --reporter-options mochaFile=./TEST-RESULTS.xml"
22+
}
23+
}

server.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const express = require('express');
4+
5+
// Constants
6+
const PORT = 3000;
7+
const HOST = '0.0.0.0';
8+
9+
// App
10+
const app = express();
11+
app.get('/', (req, res) => {
12+
res.send('Hello Node.js Sample!\n');
13+
});
14+
15+
var port = process.env.PORT||PORT;
16+
app.listen(port);
17+
console.log(`Running on http://${HOST}:${PORT}`);

tests/test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var assert = require('assert');
2+
3+
describe('String', function () {
4+
describe('#indexOf', function () {
5+
it('should return -1 when the substring is not present', function () {
6+
var myString = 'test';
7+
8+
assert.equal(-1, myString.indexOf('x'));
9+
assert.equal(-1, myString.indexOf('y'));
10+
});
11+
});
12+
});

0 commit comments

Comments
 (0)