From 4bb826818cb9a4e10479183502c156342a23e33b Mon Sep 17 00:00:00 2001 From: diven Date: Thu, 9 Jul 2026 22:13:52 +0800 Subject: [PATCH] init --- pom.xml | 18 ++++++++++++++++++ scripts/docker/Dockerfile | 10 ++++++++++ scripts/docker/entrypoint.sh | 29 +++++++++++++++++++++++++++++ scripts/docker_build.sh | 20 ++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 scripts/docker/Dockerfile create mode 100644 scripts/docker/entrypoint.sh create mode 100644 scripts/docker_build.sh diff --git a/pom.xml b/pom.xml index 299529e..264a42b 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,25 @@ + + + docker + + + + true + src/main/resources + + application** + + + + + + + + lyxh-api-docking org.springframework.boot diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile new file mode 100644 index 0000000..9f7f796 --- /dev/null +++ b/scripts/docker/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:17.0.2-slim +WORKDIR /app + +COPY scripts/docker/entrypoint.sh /app +RUN ln -snf /usr/share/zoneinfo/Hongkong /etc/localtime && chmod +x /app/entrypoint.sh && mkdir -p /app/conf/ +COPY src/main/resources/application.yml /app/conf/ +COPY target/*.jar app.jar + +EXPOSE 80 +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh new file mode 100644 index 0000000..58d73da --- /dev/null +++ b/scripts/docker/entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +SPRING_CUSTOM_CONFIG="" + +################################################## active config start ################################################# +if [ "${SPRING_PROFILE_ACTIVE}" ];then + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Dspring.profiles.active='$SPRING_PROFILE_ACTIVE'" +else + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Dspring.profiles.active='docker'" +fi +################################################## active config end ################################################### + +################################################## spring config location start ######################################## +if [ "${SPRING_CONFIG_LOCATION}" ];then + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Dspring.config.additional-location='$SPRING_CONFIG_LOCATION'" +else + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Dspring.config.additional-location='/app/conf/'" +fi +################################################## spring config location end ######################################### + +################################################## timezone config start ################################################# +if [ "${SPRING_USER_TIMEZONE}" ];then + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Duser.timezone='$SPRING_USER_TIMEZONE'" +else + SPRING_CUSTOM_CONFIG="${SPRING_CUSTOM_CONFIG} -Duser.timezone='GMT+08'" +fi +################################################## timezone config end ################################################### + +sh -c "java -server ${SPRING_CUSTOM_CONFIG} ${SPRING_OPTS} ${JAVA_OPTS} -jar /app/app.jar" diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh new file mode 100644 index 0000000..6129330 --- /dev/null +++ b/scripts/docker_build.sh @@ -0,0 +1,20 @@ +version='v1.0.0' +current_date=$(date "+%Y%m%d") +SHELL_FOLDER=$(cd "$(dirname "$0")";pwd) +cd ${SHELL_FOLDER} + +#编译项目 +cd ../ +mvn clean package -DskipTests -Pdocker + +#编译 +docker build -f scripts/docker/Dockerfile -t xmodel/third-futong-api:${version} . + +#仓库地址 +model_registry=registry.cn-hangzhou.aliyuncs.com/xmodel/third-futong-api:${version}-"${current_date}"-release + +#重命名镜像 +docker tag xmodel/third-futong-api:${version} "${model_registry}" + +#打印 +echo "docker push ${model_registry}" \ No newline at end of file