Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加Docker支持 #37

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
39 changes: 39 additions & 0 deletions build-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 生成Docker镜像

使用Docker运行有下面两种方式, 推荐使用第一种

## 使用docker-compose启动

```
> cd ../
> npm run docker:build
> npm run docker:start
# client: 8888 # server: 7001
```

## 单独Build启动

### client

```
> cd ..
> docker build -t api-client -f build-docker/client.dockerfile .
> docker run --rm api-client
```

### server

```
# 启动mongo
> cd ..
> docker build -t api-mongo -f build-docker/mongo.dockerfile .
> docker create --name api-mongo-container api-mongo
> docker start -p 8080:80 api-mongo-container

> cd ..

# 启动server
> cd ..
> docker build -t api-server -f build-docker/server.dockerfile .
> docker run --rm --net="container:api-mongo-container" api-server
```
12 changes: 12 additions & 0 deletions build-docker/client.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM nginx:alpine

## Clone Source
COPY ./client/dist /www
COPY ./build-docker/nginx.conf /etc/nginx/nginx.conf

WORKDIR /www

## Expost ports
EXPOSE 80

CMD "nginx" "-g 'daemon off;'"
28 changes: 28 additions & 0 deletions build-docker/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3"

services:
mongod:
build:
context: '../'
dockerfile: 'build-docker/mongo.dockerfile'
ports:
- "7001:7001"
entrypoint: mongod --bind_ip 127.0.0.1

server:
build:
context: '../'
dockerfile: 'build-docker/server.dockerfile'
network_mode: "service:mongod"
depends_on:
- mongod

client:
build:
context: '../'
dockerfile: build-docker/client.dockerfile
entrypoint: nginx -g "daemon off;"
ports:
- "8888:80"
depends_on:
- server
7 changes: 7 additions & 0 deletions build-docker/mongo.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM mongo:latest

CMD mkdir -f /data/db

EXPOSE 27017

CMD "mongod"
25 changes: 25 additions & 0 deletions build-docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
worker_processes 4;

events { worker_connections 1024; }

http {
server {
listen 80;

location /mock/ {
alias /www/;
gzip_static on;
expires max;
}

location /mock-api/ {
proxy_pass http://192.168.99.100:7001/;
}

location / {
alias /www/;
}


}
}
10 changes: 10 additions & 0 deletions build-docker/server.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from node:alpine

COPY ./server /server

RUN cd /server && \
npm install

WORKDIR /server

CMD "npm" "start"
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "api-mocker",
"version": "1.0.0",
"description": "> API Mocker,不仅仅是Mocker,它致力于解决前后端开发协作过程中出现的各类问题,提高开发效率,对接口做统一管理,同时也能为后续的迭代维护提供更便捷的方式。",
"main": "index.js",
"directories": {
"doc": "docs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docker:build": "cd client && npm run build && cd .. && docker-compose -f build-docker/compose.yml build",
"docker:start": "docker-compose -f build-docker/compose.yml up"
},
"repository": {
"type": "git",
"url": "git@github.com:DXY-F2E/api-mocker.git"
},
"keywords": [],
"author": "",
"license": "ISC"
}