diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/build-docker/README.md b/build-docker/README.md new file mode 100644 index 0000000..d483960 --- /dev/null +++ b/build-docker/README.md @@ -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 +``` diff --git a/build-docker/client.dockerfile b/build-docker/client.dockerfile new file mode 100644 index 0000000..193fa95 --- /dev/null +++ b/build-docker/client.dockerfile @@ -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;'" diff --git a/build-docker/compose.yml b/build-docker/compose.yml new file mode 100644 index 0000000..c775dc1 --- /dev/null +++ b/build-docker/compose.yml @@ -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 diff --git a/build-docker/mongo.dockerfile b/build-docker/mongo.dockerfile new file mode 100644 index 0000000..74ac46d --- /dev/null +++ b/build-docker/mongo.dockerfile @@ -0,0 +1,7 @@ +FROM mongo:latest + +CMD mkdir -f /data/db + +EXPOSE 27017 + +CMD "mongod" diff --git a/build-docker/nginx.conf b/build-docker/nginx.conf new file mode 100644 index 0000000..2f487f3 --- /dev/null +++ b/build-docker/nginx.conf @@ -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/; + } + + + } +} diff --git a/build-docker/server.dockerfile b/build-docker/server.dockerfile new file mode 100644 index 0000000..ed81abf --- /dev/null +++ b/build-docker/server.dockerfile @@ -0,0 +1,10 @@ +from node:alpine + +COPY ./server /server + +RUN cd /server && \ + npm install + +WORKDIR /server + +CMD "npm" "start" diff --git a/package.json b/package.json new file mode 100644 index 0000000..02b7218 --- /dev/null +++ b/package.json @@ -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" +}