Skip to content

Commit

Permalink
added Dockerfile and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Xu committed Nov 23, 2018
1 parent f5a085d commit e9a321d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:8

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json and package-lock.json are copied
# where available (npm@5+)

COPY package*.json ./

RUN npm install
# if youa re building your code for production
# RUN npm install --only=production

# Bundle app source
COPY . .

# Expose 8080 port on container
EXPOSE 3000

# Start up your application
CMD ["npm", "start"]
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
Calculator.js: a node.js Demonstration Project
==============================================
An example node.js project, including tests with mocha, that behaves like
a pocket calculator.
# Calculator.js: node.js 演示项目

The project contains a simple node.js application that exposes REST APIs
to perform arithmetic on integers, and provides a test suite with mocha
and chai. The `mocha-junit-reporters` package is included to provide XML
output that can be presented in a continuous integration tool like
[Azure DevOps](https://azure.com/devops).
本应用使用node.js创建,并包含了试用mocha的单元测试代码。本应用的运行状态为网页中的计算机,如下图:

To build, simply:
![](calculator-ui.png)

1. Runs `npm install` to install dependencies.
2. Runs `npm test` to run Mocha and execute the unit tests.
代码中使用node.js代码提供了REST APIs,其中提供各种数学计算功能单元。

使用mocah编写的测试代码可以完成所有以上API内部运算运算逻辑的验证,最终使用 `mocha-junit-reports` 来生成XML格式的测试结果文件以便 [Azure DevOps](https://azure.com/devops) 可以读取测试结果提供DevOps流水线的测试集成。

本地构建本项目的方式:

1. 运行 `npm install` 安装所有依赖包
2. 运行 `npm test` 运行所有测试
3. 运行 `npm start` 启动应用,并打开 http://localhost:3000

使用Docker构建和运行项目的方式:

1. 运行以下命令完成 `calculator` 容器构建打包

```shell
docker build -t calculator .
```

2. 运行 `calculator` 容器

```shell
docker run -itd -p 8080:3000 calculator
```

打开 http://localhost:8080

应用启动后的状态如上图。
Binary file added calculator-ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e9a321d

Please sign in to comment.