From 69845a76389f8726fa5cc2521563af75f35d897d Mon Sep 17 00:00:00 2001 From: xiwa Date: Wed, 21 Feb 2024 23:06:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0Dockerfile=E5=92=8Cdocke?= =?UTF-8?q?r=E5=90=AF=E5=8A=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- Dockerfile | 33 ++++++++++++++++++++++++++++++++ README.md | 10 ++++++++-- data/nginx.conf | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 data/nginx.conf diff --git a/.gitignore b/.gitignore index 2c4fed2c..852d4fa6 100755 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ data/elasticsearch .DS_Store dependency-reduced-pom.xml -/data/plugins \ No newline at end of file +/data/plugins +/data/dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6e6f97cf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# 操作步骤: +# 1. 打包前端项目,复制dis到data目录 +# 2. 打包java项目 +# 3. docker build -t iot-iita . +# 4. docker tag iot-iita iotkits/iot-iita +# 5. docker push iotkits/iot-iita + +# 使用包含Java的基础镜像 +FROM adoptopenjdk:11-jre-hotspot +# 设置工作目录 +WORKDIR /app + +# 复制后端Java应用的JAR文件 +COPY ./iot-starter/target/iot-starter-0.5.2-SNAPSHOT.jar app.jar +COPY ./data/init/* data/init/ + +# 安装Nginx +RUN apt-get update && apt-get install -y nginx + +# 复制Nginx配置文件 +COPY ./data/nginx.conf /etc/nginx/nginx.conf + +# 复制静态资源 +COPY ./data/dist/ /usr/share/nginx/html + +# 暴露端口 +EXPOSE 8082 8086 1883 1884 +# 插件预留端口 +EXPOSE 8130-8140 + +# 设置容器启动命令 +CMD ["/bin/bash", "-c", "java -jar /app/app.jar & nginx -g 'daemon off;'"] + diff --git a/README.md b/README.md index 1e727c00..e74bcb49 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

- +

@@ -94,8 +94,14 @@ Vertx event-bus(内置)、RocketMQ,通过扩展模块可接入其它任意 2、application.xml中打开rocketmq配置 +#### Docker运行 +docker pull iotkits/iot-iita:latest -#### 运行步骤 +docker run -p 8082:8082 -p 8086:8086 -p 8130-8140:8130-8140 iotkits/iot-iita:latest + +启动后访问 http://localhost:8082/ + +#### 源码运行步骤 1、安装jdk11 2、clone代码([核心库](https://gitee.com/open-iita/iot-iita-core),[主项目库](https://gitee.com/open-iita/iotkit-parent),[插件库](https://gitee.com/open-iita/iot-iita-plugins)),在idea中导入项目 diff --git a/data/nginx.conf b/data/nginx.conf new file mode 100644 index 00000000..7b8b9084 --- /dev/null +++ b/data/nginx.conf @@ -0,0 +1,50 @@ +user root; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 4096; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server + { + listen 8082; + server_name localhost; + client_max_body_size 100m; + index index.html; + root /usr/share/nginx/html; + + location /prod-api/ + { + rewrite /api(.*) $1 break; + proxy_pass http://127.0.0.1:8086/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header REMOTE-HOST $remote_addr; + proxy_http_version 1.1; + } + } + +} +