From a829365d6ba30585cd494c28e7d7ad856cb07c06 Mon Sep 17 00:00:00 2001 From: wuwendi <646907729@qq.com> Date: Sat, 4 Mar 2023 13:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=97=E5=90=91=E7=9C=8B=E6=9D=BF=E7=B3=BB?= =?UTF-8?q?=E7=B5=B1-dockercompose=E5=AE=89=E8=A3=85=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 南向看板系統-dockercompose安装部署修改 Dockerfile构建语句合并 去除密码值 --- tools/southbound/docker-compose.yaml | 4 +-- .../southbound-service/DockerAppFile | 31 ++++++++++++++++++- .../southbound/southbound-service/Dockerfile | 31 +------------------ .../resources/application-prod.properties | 4 +-- .../southbound/southbound-view/DockerAppFile | 10 +++--- tools/southbound/southbound-view/Dockerfile | 18 +++++------ 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/tools/southbound/docker-compose.yaml b/tools/southbound/docker-compose.yaml index a5159f5..47df194 100644 --- a/tools/southbound/docker-compose.yaml +++ b/tools/southbound/docker-compose.yaml @@ -7,7 +7,7 @@ services: # 服务名称 container_name: southbound-nginx # 指定上下文目录以及docker配置文件的相对路径 - build: ./southbound-view/DockerAppFile + build: ./southbound-view/ # 自动重启,如果服务启动不成功会一直尝试。 restart: always # 对外开放的端口。这里主机的端口映射到nginx容器端口,和expose的区别是,expose不会将端口暴露给主机。 @@ -46,7 +46,7 @@ services: app: container_name: southbound-server - build: ./southbound-service/DockerAppFile + build: ./southbound-service/ restart: always #设置工作目录为容器内的app文件夹 working_dir: /app diff --git a/tools/southbound/southbound-service/DockerAppFile b/tools/southbound/southbound-service/DockerAppFile index 97ad5f4..5bc2fcd 100644 --- a/tools/southbound/southbound-service/DockerAppFile +++ b/tools/southbound/southbound-service/DockerAppFile @@ -1 +1,30 @@ -FROM maven:3.6-jdk-8 \ No newline at end of file +# AS builder 起别名 +FROM maven:3.6.3-openjdk-8 AS builder +# 创建临时文件 +RUN mkdir /build +# 将src目录复制到临时目录 +ADD src /build/src +# 将pom文件复制到临时目录 +ADD pom.xml /build + +# 设置变量 +ENV username="" +ENV password="" +ENV url="" +# 打包 +RUN cd /build && mvn -B -ntp package -DskipTests + +# 获取jre +FROM openjdk:8-jre-alpine + +# 解决时区问题、修改容器的时区为东八区 +ENV TZ Asia/Shanghai + +# 公开端口 +EXPOSE 8099 + +# 从标记点 拷贝jar包 并改名 +COPY --from=builder /build/target/SouthboundDashBoard-0.0.1-SNAPSHOT.jar /app.jar + +#设置启动命令 +ENTRYPOINT ["sh","-c","java -jar /app.jar --spring.datasource.username=$username --spring.datasource.url=$url --spring.datasource.password=$password"] \ No newline at end of file diff --git a/tools/southbound/southbound-service/Dockerfile b/tools/southbound/southbound-service/Dockerfile index 5bc2fcd..d4395ea 100644 --- a/tools/southbound/southbound-service/Dockerfile +++ b/tools/southbound/southbound-service/Dockerfile @@ -1,30 +1 @@ -# AS builder 起别名 -FROM maven:3.6.3-openjdk-8 AS builder -# 创建临时文件 -RUN mkdir /build -# 将src目录复制到临时目录 -ADD src /build/src -# 将pom文件复制到临时目录 -ADD pom.xml /build - -# 设置变量 -ENV username="" -ENV password="" -ENV url="" -# 打包 -RUN cd /build && mvn -B -ntp package -DskipTests - -# 获取jre -FROM openjdk:8-jre-alpine - -# 解决时区问题、修改容器的时区为东八区 -ENV TZ Asia/Shanghai - -# 公开端口 -EXPOSE 8099 - -# 从标记点 拷贝jar包 并改名 -COPY --from=builder /build/target/SouthboundDashBoard-0.0.1-SNAPSHOT.jar /app.jar - -#设置启动命令 -ENTRYPOINT ["sh","-c","java -jar /app.jar --spring.datasource.username=$username --spring.datasource.url=$url --spring.datasource.password=$password"] \ No newline at end of file +FROM maven:3.6.3-openjdk-15 \ No newline at end of file diff --git a/tools/southbound/southbound-service/src/main/resources/application-prod.properties b/tools/southbound/southbound-service/src/main/resources/application-prod.properties index 4f63dd3..970b4cf 100644 --- a/tools/southbound/southbound-service/src/main/resources/application-prod.properties +++ b/tools/southbound/southbound-service/src/main/resources/application-prod.properties @@ -1,5 +1,5 @@ # 数据库连接-生产数据库 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url= +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/south_dash_board?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true spring.datasource.username= -spring.datasource.password= +spring.datasource.password= \ No newline at end of file diff --git a/tools/southbound/southbound-view/DockerAppFile b/tools/southbound/southbound-view/DockerAppFile index 0e29017..03c49a7 100644 --- a/tools/southbound/southbound-view/DockerAppFile +++ b/tools/southbound/southbound-view/DockerAppFile @@ -13,8 +13,10 @@ RUN mkdir -p /app WORKDIR /app COPY --from=Builder /app/dist /app RUN chmod -R 755 /app -COPY --from=Builder /app/nginx.conf /etc/nginx/conf.d/ -ENV RUN_USER nginx -ENV RUN_GROUP nginx +# 这里nginx配置复制过去 +ADD nginx.template /etc/nginx/conf.d EXPOSE 80 -ENTRYPOINT ["nginx", "-g", "daemon off;"] +EXPOSE 443 +WORKDIR /etc/nginx/conf.d +ENTRYPOINT envsubst '$URL' < nginx.template > default.conf && cat default.conf && nginx -g 'daemon off;' + diff --git a/tools/southbound/southbound-view/Dockerfile b/tools/southbound/southbound-view/Dockerfile index f76e55c..7b9e2e8 100644 --- a/tools/southbound/southbound-view/Dockerfile +++ b/tools/southbound/southbound-view/Dockerfile @@ -1,21 +1,17 @@ -FROM node:14.17.3-alpine as Builder +FROM node:14 as Builder RUN mkdir -p /app WORKDIR /app COPY . /app -RUN npm install -g cnpm -registry=https://registry.npm.taobao.org -RUN cnpm install -g vue && \ - cnpm install && \ - cnpm run build +RUN cnpm install && npm run build -FROM nginx:1.20.0 +FROM nginx:alpine RUN mkdir -p /app WORKDIR /app COPY --from=Builder /app/dist /app RUN chmod -R 755 /app -# 这里nginx配置复制过去 -ADD nginx.template /etc/nginx/conf.d +COPY --from=Builder /app/nginx.conf /etc/nginx/conf.d/ +ENV RUN_USER nginx +ENV RUN_GROUP nginx EXPOSE 80 -EXPOSE 443 -WORKDIR /etc/nginx/conf.d -ENTRYPOINT envsubst '$URL' < nginx.template > default.conf && cat default.conf && nginx -g 'daemon off;' \ No newline at end of file +ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file -- Gitee