From 9bdd71dbf18b2e8582922801991589622bd7b8f4 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 25 Apr 2023 22:52:42 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20Docker=E6=94=AF=E6=8C=81-yudao-ui-a?= =?UTF-8?q?dmin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/.dockerignore | 3 +++ yudao-ui-admin/Dockerfile | 22 ++++++++++++++++++++++ yudao-ui-admin/nginx.conf | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 yudao-ui-admin/.dockerignore create mode 100644 yudao-ui-admin/Dockerfile create mode 100644 yudao-ui-admin/nginx.conf diff --git a/yudao-ui-admin/.dockerignore b/yudao-ui-admin/.dockerignore new file mode 100644 index 000000000..ddc40eddb --- /dev/null +++ b/yudao-ui-admin/.dockerignore @@ -0,0 +1,3 @@ +.dockerignore +dist +node_modules diff --git a/yudao-ui-admin/Dockerfile b/yudao-ui-admin/Dockerfile new file mode 100644 index 000000000..382c3eb41 --- /dev/null +++ b/yudao-ui-admin/Dockerfile @@ -0,0 +1,22 @@ +FROM node:16-alpine as DIST + +WORKDIR /admim + +COPY ./package.json . +COPY ./yarn.lock . +COPY ./.npmrc . +RUN yarn install + +COPY . . +ARG NODE_ENV="" +RUN env ${NODE_ENV} yarn build:prod + +## -- stage: dist => nginx -- +FROM nginx:alpine + +ENV TZ=Asia/Shanghai + +COPY ./nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=DIST /admim/dist /usr/share/nginx/html + +EXPOSE 80 diff --git a/yudao-ui-admin/nginx.conf b/yudao-ui-admin/nginx.conf new file mode 100644 index 000000000..93f261baf --- /dev/null +++ b/yudao-ui-admin/nginx.conf @@ -0,0 +1,26 @@ +server { + listen 80 default_server; + server_name _; ## 重要!!!修改成你的外网 IP/域名 + + gzip on; + gzip_min_length 1k; # 设置允许压缩的页面最小字节数 + gzip_buffers 4 16k; # 用来存储 gzip 的压缩结果 + gzip_http_version 1.1; # 识别 HTTP 协议版本 + gzip_comp_level 2; # 设置 gzip 的压缩比 1-9。1 压缩比最小但最快,而 9 相反 + gzip_types text/plain application/x-javascript text/css application/xml application/javascript; # 指定压缩类型 + gzip_proxied any; # 无论后端服务器的 headers 头返回什么信息,都无条件启用压缩 + + location / { ## 前端项目 + root /usr/share/nginx/html/; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location /prod-api/ { ## 后端项目 - 管理后台 + proxy_pass http://yudao-server:48080/; ## 重要!!!proxy_pass 需要设置为后端项目所在服务器的 IP + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header REMOTE-HOST $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} From c139be1966623196aae0318d3a7248798c3dfc8f Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 25 Apr 2023 22:54:11 +0800 Subject: [PATCH 2/9] =?UTF-8?q?perf:=20yudao-server/Dockerfile=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0$ARGS=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-server/Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/yudao-server/Dockerfile b/yudao-server/Dockerfile index 234081ad0..8fd95741f 100644 --- a/yudao-server/Dockerfile +++ b/yudao-server/Dockerfile @@ -9,11 +9,15 @@ WORKDIR /yudao-server COPY ./target/yudao-server.jar app.jar ## 设置 TZ 时区 +ENV TZ=Asia/Shanghai ## 设置 JAVA_OPTS 环境变量,可通过 docker run -e "JAVA_OPTS=" 进行覆盖 -ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m" +ENV JAVA_OPTS="-Xms512m -Xmx512m -Djava.security.egd=file:/dev/./urandom" + +## 应用参数 +ENV ARGS="" ## 暴露后端项目的 48080 端口 EXPOSE 48080 ## 启动后端项目 -CMD java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar +CMD java ${JAVA_OPTS} -jar app.jar $ARGS From 8e64e93d9e8e45f36ca4c60a604587abb25dcf33 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 25 Apr 2023 22:54:56 +0800 Subject: [PATCH 3/9] feat: docker-compose docker.env --- docker-compose.yml | 86 ++++++++++++++++++++++++++++++++++++++++++++++ docker.env | 25 ++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker.env diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..9f59770dc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,86 @@ +version: "3.8" + +services: + mysql: + container_name: yudao-mysql + image: mysql:8 + restart: unless-stopped + tty: true + ports: + - 3308:3306 + environment: + MYSQL_DATABASE: ${MYSQL_DATABASE:-ruoyi-vue-pro} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456} + volumes: + - mysql:/var/lib/mysql/ + networks: + - yudao-network + + redis: + container_name: yudao-redis + image: redis:6-alpine + ports: + - 6379:6379 + networks: + - yudao-network + + server: + container_name: yudao-server + build: + context: ./yudao-server/ + image: yudao-server + ports: + - 48080:48080 + environment: + # https://github.com/polovyivan/docker-pass-configs-to-container + SPRING_PROFILES_ACTIVE: local + JAVA_OPTS: + ${JAVA_OPTS:- + -Xms512m + -Xmx512m + -Djava.security.egd=file:/dev/./urandom + } + ARGS: + --spring.datasource.dynamic.datasource.master.url=${MASTER_DATASOURCE_URL:-jdbc:mysql://yudao-mysql:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true} + --spring.datasource.dynamic.datasource.master.username=${MASTER_DATASOURCE_USERNAME:-root} + --spring.datasource.dynamic.datasource.master.password=${MASTER_DATASOURCE_PASSWORD:-123456} + --spring.datasource.dynamic.datasource.slave.url=${SLAVE_DATASOURCE_URL:-jdbc:mysql://yudao-mysql:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true} + --spring.datasource.dynamic.datasource.slave.username=${SLAVE_DATASOURCE_USERNAME:-root} + --spring.datasource.dynamic.datasource.slave.password=${SLAVE_DATASOURCE_PASSWORD:-123456} + --spring.redis.host=${REDIS_HOST:-yudao-redis} + networks: + - yudao-network + depends_on: + - mysql + - redis + + admin: + container_name: yudao-admin + build: + context: ./yudao-ui-admin + args: + NODE_ENV: + ENV=${NODE_ENV:-production} + PUBLIC_PATH=${PUBLIC_PATH:-/} + VUE_APP_TITLE=${VUE_APP_TITLE:-芋道管理系统} + VUE_APP_BASE_API=${VUE_APP_BASE_API:-/prod-api} + VUE_APP_APP_NAME=${VUE_APP_APP_NAME:-/} + VUE_APP_TENANT_ENABLE=${VUE_APP_TENANT_ENABLE:-true} + VUE_APP_CAPTCHA_ENABLE=${VUE_APP_CAPTCHA_ENABLE:-true} + VUE_APP_DOC_ENABLE=${VUE_APP_DOC_ENABLE:-true} + VUE_APP_BAIDU_CODE=${VUE_APP_BAIDU_CODE:-fadc1bd5db1a1d6f581df60a1807f8ab} + image: yudao-admin + ports: + - 8080:80 + networks: + - yudao-network + depends_on: + - server + +networks: + yudao-network: + driver: bridge + +volumes: + mysql: + driver: local diff --git a/docker.env b/docker.env new file mode 100644 index 000000000..0bf6e997e --- /dev/null +++ b/docker.env @@ -0,0 +1,25 @@ +## mysql +MYSQL_DATABASE=ruoyi-vue-pro +MYSQL_ROOT_PASSWORD=123456 + +## server +JAVA_OPTS=-Xms512m -Xmx512m -Djava.security.egd=file:/dev/./urandom + +MASTER_DATASOURCE_URL=jdbc:mysql://yudao-mysql:3306/${MYSQL_DATABASE}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true +MASTER_DATASOURCE_USERNAME=root +MASTER_DATASOURCE_PASSWORD=${MYSQL_ROOT_PASSWORD} +SLAVE_DATASOURCE_URL=${MASTER_DATASOURCE_URL} +SLAVE_DATASOURCE_USERNAME=${MASTER_DATASOURCE_USERNAME} +SLAVE_DATASOURCE_PASSWORD=${MASTER_DATASOURCE_PASSWORD} +REDIS_HOST=yudao-redis + +## admin +NODE_ENV=production +PUBLIC_PATH=/ +VUE_APP_TITLE=芋道管理系统 +VUE_APP_BASE_API=/prod-api +VUE_APP_APP_NAME=/ +VUE_APP_TENANT_ENABLE=true +VUE_APP_CAPTCHA_ENABLE=true +VUE_APP_DOC_ENABLE=true +VUE_APP_BAIDU_CODE=fadc1bd5db1a1d6f581df60a1807f8ab From dbb75e1d9e23cbefd19ae30a3ee14bb2038898c5 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 25 Apr 2023 22:55:25 +0800 Subject: [PATCH 4/9] =?UTF-8?q?doc:=20=E6=B7=BB=E5=8A=A0docker/docker-comp?= =?UTF-8?q?ose=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Docker-HOWTO.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Docker-HOWTO.md diff --git a/Docker-HOWTO.md b/Docker-HOWTO.md new file mode 100644 index 000000000..87b4a4a02 --- /dev/null +++ b/Docker-HOWTO.md @@ -0,0 +1,60 @@ +# Docker Build & Up + +目标: 快速部署体验系统,帮助了解系统之间的依赖关系。 + +## 功能文件列表 + +```text +. +├── Docker-HOWTO.md +├── docker-compose.yml +├── docker.env +├── yudao-server +│ ├── Dockerfile +│ └── nginx.conf +└── yudao-ui-admin + ├── .dockerignore + └── Dockerfile +``` + +## Maven build (Optional) + +```shell +# 创建maven缓存volume +docker volume create --name yudao-maven-repo + +docker run -it --rm --name yudao-maven \ + -v yudao-maven-repo:/root/.m2 \ + -v $PWD:/usr/src/mymaven \ + -w /usr/src/mymaven \ + maven mvn clean install package '-Dmaven.test.skip=true' +``` + +## Docker Compose Build + +```shell +docker compose --env-file docker.env build +``` + +## Docker Compose Up + +```shell +docker compose --env-file docker.env up -d +``` + +第一次执行,由于数据库未初始化,因此yudao-server容器会运行失败。执行如下命令初始化数据库: + +```shell +docker exec -i yudao-mysql \ + sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD" ruoyi-vue-pro' \ + < ./sql/mysql/ruoyi-vue-pro.sql +``` + +注意:这里用docker compose exec 会出现 `the input device is not a TTY` 报错 + +## Server:Port + +- admin: http://localhost:8080 +- API: http://localhost:48080 +- mysql: root/123456, port: 3308 +- redis: port: 6379 From 97502c8b511aa8a0ff505e2d6eb6f468fe6fb1a9 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 2 May 2023 10:31:24 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix:=20docker-compose=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 9f59770dc..0d9e9754d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: redis: container_name: yudao-redis image: redis:6-alpine + restart: unless-stopped ports: - 6379:6379 networks: @@ -29,6 +30,7 @@ services: build: context: ./yudao-server/ image: yudao-server + restart: unless-stopped ports: - 48080:48080 environment: @@ -70,6 +72,7 @@ services: VUE_APP_DOC_ENABLE=${VUE_APP_DOC_ENABLE:-true} VUE_APP_BAIDU_CODE=${VUE_APP_BAIDU_CODE:-fadc1bd5db1a1d6f581df60a1807f8ab} image: yudao-admin + restart: unless-stopped ports: - 8080:80 networks: From c3d943903042d9d68c27a6ce6f58fb9ddccdf300 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Tue, 9 May 2023 23:38:39 +0800 Subject: [PATCH 6/9] =?UTF-8?q?perf:=20admin/Dockerfile=20=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E5=8C=85=E7=AE=A1=E7=90=86=E5=99=A8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/yudao-ui-admin/Dockerfile b/yudao-ui-admin/Dockerfile index 382c3eb41..6c74b4eaa 100644 --- a/yudao-ui-admin/Dockerfile +++ b/yudao-ui-admin/Dockerfile @@ -1,11 +1,10 @@ -FROM node:16-alpine as DIST +FROM node:16-alpine as build-stage WORKDIR /admim -COPY ./package.json . -COPY ./yarn.lock . -COPY ./.npmrc . -RUN yarn install +COPY .npmrc package.json yarn.lock ./ +RUN --mount=type=cache,id=yarn-store,target=/root/.yarn-store \ + yarn install COPY . . ARG NODE_ENV="" @@ -17,6 +16,6 @@ FROM nginx:alpine ENV TZ=Asia/Shanghai COPY ./nginx.conf /etc/nginx/conf.d/default.conf -COPY --from=DIST /admim/dist /usr/share/nginx/html +COPY --from=build-stage /admim/dist /usr/share/nginx/html EXPOSE 80 From d794c2c1982964291af51c4a47a48f9682373103 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Wed, 10 May 2023 23:12:12 +0800 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20bpm/task=E8=B7=AF=E7=94=B1=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/src/views/bpm/task/{done.vue => done/index.vue} | 0 yudao-ui-admin/src/views/bpm/task/{todo.vue => todo/index.vue} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename yudao-ui-admin/src/views/bpm/task/{done.vue => done/index.vue} (100%) rename yudao-ui-admin/src/views/bpm/task/{todo.vue => todo/index.vue} (100%) diff --git a/yudao-ui-admin/src/views/bpm/task/done.vue b/yudao-ui-admin/src/views/bpm/task/done/index.vue similarity index 100% rename from yudao-ui-admin/src/views/bpm/task/done.vue rename to yudao-ui-admin/src/views/bpm/task/done/index.vue diff --git a/yudao-ui-admin/src/views/bpm/task/todo.vue b/yudao-ui-admin/src/views/bpm/task/todo/index.vue similarity index 100% rename from yudao-ui-admin/src/views/bpm/task/todo.vue rename to yudao-ui-admin/src/views/bpm/task/todo/index.vue From 4891f1853848782da3e17708b6146b09ce988972 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Wed, 10 May 2023 23:39:31 +0800 Subject: [PATCH 8/9] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0docker-compose/na?= =?UTF-8?q?me=E5=AD=97=E6=AE=B5=EF=BC=8Cui/Dockerfile=20--frozen-lockfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 ++ yudao-ui-admin/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0d9e9754d..29f935367 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,7 @@ version: "3.8" +name: yudao-system + services: mysql: container_name: yudao-mysql diff --git a/yudao-ui-admin/Dockerfile b/yudao-ui-admin/Dockerfile index 6c74b4eaa..4764e741b 100644 --- a/yudao-ui-admin/Dockerfile +++ b/yudao-ui-admin/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /admim COPY .npmrc package.json yarn.lock ./ RUN --mount=type=cache,id=yarn-store,target=/root/.yarn-store \ - yarn install + yarn install --frozen-lockfile COPY . . ARG NODE_ENV="" From 7c1a4db5a9acbedb599545ae5894f4a0f4afc278 Mon Sep 17 00:00:00 2001 From: dhb52 Date: Fri, 12 May 2023 11:03:13 +0800 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0redis=E5=8D=B7,=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9host=E7=BB=91=E5=AE=9A=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 29f935367..cec84d55a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: restart: unless-stopped tty: true ports: - - 3308:3306 + - 13306:3306 environment: MYSQL_DATABASE: ${MYSQL_DATABASE:-ruoyi-vue-pro} MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456} @@ -23,7 +23,9 @@ services: image: redis:6-alpine restart: unless-stopped ports: - - 6379:6379 + - 16379:6379 + volumes: + - redis:/data networks: - yudao-network @@ -89,3 +91,5 @@ networks: volumes: mysql: driver: local + redis: + driver: local