gitlab-CI作业-yml (setsid命令) JAVA Tomcat NetCore 自动部署
.gitlab-ci.yml(net core&all&linux&docker-build-run)
1 stages: 2 - build 3 - deploy 4 5 build_job: 6 stage: build 7 image: docker.tidebuy.net/dotnet/core/sdk:3.1 8 script: 9 - echo "Restore NuGet Packages..." 10 - echo "dotnet restore TLZ.COM.NetCore.Demo.sln ..." 11 - dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln 12 - echo "Release easyui publish ..." 13 - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj -c Release -o $CI_PROJECT_DIR/publish/easyui/ 14 - echo "Release sso publish ..." 15 - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj -c Release -o $CI_PROJECT_DIR/publish/sso/ 16 - echo "Release image publish ..." 17 - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj -c Release -o $CI_PROJECT_DIR/publish/image/ 18 artifacts: 19 name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME" 20 paths: 21 - publish/ 22 expire_in: 1 days 23 only: 24 - master 25 - dev 26 27 deploy_job: 28 stage: deploy 29 image: "docker:19.03.5" 30 dependencies: 31 - build_job 32 services: 33 - docker:19.03.5-dind 34 script: 35 - echo "Release easyui deploy ..." 36 - for PID in `ps -ef |grep TLZ.COM.NeatCore.View.EasyUIDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done 37 - cp -rf $CI_PROJECT_DIR/publish/easyui/* /data/web/easyui/deploy/ 38 - cd /data/web/easyui/deploy/ 39 - rm -rf *.pdb 40 - echo "Run easyui deploy ..." 41 - setsid '/data/web/easyui/easyui-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 42 - echo "Release sso deploy ..." 43 - for PID in `ps -ef |grep TLZ.COM.NetCore.View.SSODemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done 44 - cp -rf $CI_PROJECT_DIR/publish/sso/* /data/web/sso/deploy/ 45 - cd /data/web/sso/deploy/ 46 - rm -rf *.pdb 47 - echo "Run sso deploy ..." 48 - setsid '/data/web/sso/sso-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 49 - echo "Release image deploy ..." 50 - for PID in `ps -ef |grep TLZ.COM.NetCore.View.ImageSharpImageDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done 51 - cp -rf $CI_PROJECT_DIR/publish/image/* /data/web/image/deploy/ 52 - cd /data/web/image/deploy/ 53 - rm -rf *.pdb 54 - echo "Run image deploy ..." 55 - setsid '/data/web/image/image-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 56 - echo "Run docker-compose deploy ..." 57 - cd $CI_PROJECT_DIR/ 58 - chmod +x docker-compose.sh 59 - sh docker-compose.sh 60 61 - echo "Run docker build ..." 62 - image_version="${CI_APPLICATION_TAG:-${CI_COMMIT_SHA:0:8}}" 63 - easyui_image="dotnetcore31easyui" 64 - sso_image="dotnetcore31sso" 65 - image_image="dotnetcore31image" 66 - cd $CI_PROJECT_DIR 67 - docker build -f rancher-pipeline/Dockerfile 68 --build-arg APP_PATH="publish/easyui/" 69 --build-arg MAIN_DLL="TLZ.COM.NetCore.View.EasyUIDemo.dll" 70 --build-arg PORT="7777" 71 --build-arg MAIN_ENV="--environment=Docker" 72 --tag "$easyui_image:$image_version" 73 --tag "$easyui_image:latest" 74 . 75 - docker build -f rancher-pipeline/Dockerfile 76 --build-arg APP_PATH="publish/sso/" 77 --build-arg MAIN_DLL="TLZ.COM.NetCore.View.SSODemo.dll" 78 --build-arg PORT="1234" 79 --build-arg MAIN_ENV="--environment=Docker" 80 --tag "$sso_image:$image_version" 81 --tag "$sso_image:latest" 82 . 83 - docker build -f rancher-pipeline/Dockerfile 84 --build-arg APP_PATH="publish/image/" 85 --build-arg MAIN_DLL="TLZ.COM.NetCore.View.ImageSharpImageDemo.dll" 86 --build-arg PORT="5050" 87 --build-arg MAIN_ENV="" 88 --tag "$image_image:$image_version" 89 --tag "$image_image:latest" 90 . 91 92 - echo "Run docker run ..." 93 - for container_id in $(docker ps -a --filter="name=$easyui_image" -q);do docker rm -f $container_id;done 94 - docker run -d -p 27777:7777 --link trusting_euclid --network bridge --workdir /app --name $easyui_image $easyui_image:$image_version 95 - for container_id in $(docker ps -a --filter="name=$sso_image" -q);do docker rm -f $container_id;done 96 - docker run -d -p 21234:1234 --link trusting_euclid --network bridge --workdir /app --name $sso_image $sso_image:$image_version 97 - for container_id in $(docker ps -a --filter="name=$image_image" -q);do docker rm -f $container_id;done 98 - docker run -d -p 25050:5050 --volume /data/web/image/docker:/app/wwwroot/image-cache --workdir /app --name $image_image $image_image:$image_version 99 - exit 100 only: 101 - master 102 - dev 103 - tags 104 when: on_success
rancher-pipeline/Dockerfile
FROM docker.tidebuy.net/dotnet/core/aspnet:3.1 WORKDIR /app RUN echo "Asia/Shanghai" > /etc/timezone; \ sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf; ARG APP_PATH ARG MAIN_DLL ARG MAIN_ENV COPY ${APP_PATH} . ENV MAIN_DLL=${MAIN_DLL} ENV MAIN_ENV=${MAIN_ENV} EXPOSE ${PORT} CMD ["sh", "-c","/usr/bin/dotnet /app/$MAIN_DLL $MAIN_ENV"]
------------------------------------------------------------------------
.gitlab-ci.yml(net core&all&linux&docker-compose)
stages: - build - deploy before_script: - echo "Restore NuGet Packages..." - echo "dotnet restore TLZ.COM.NetCore.Demo.sln ..." - dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln build_job: stage: build script: - echo "Release easyui publish ..." - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj -c Release -o /data/web/easyui/publish - echo "Release sso publish ..." - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj -c Release -o /data/web/sso/publish - echo "Release image publish ..." - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj -c Release -o /data/web/image/publish only: - master - dev deploy_job: stage: deploy script: - echo "Release easyui deploy ..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.EasyUIDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/easyui/publish/* /data/web/easyui/deploy/ - cd /data/web/easyui/deploy/ - rm -rf *.pdb - echo "Run easyui deploy ..." - setsid '/data/web/easyui/easyui-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - echo "Release sso deploy ..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.SSODemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/sso/publish/* /data/web/sso/deploy/ - cd /data/web/sso/deploy/ - rm -rf *.pdb - echo "Run sso deploy ..." - setsid '/data/web/sso/sso-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - echo "Release image deploy ..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.ImageSharpImageDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/image/publish/* /data/web/image/deploy/ - cd /data/web/image/deploy/ - rm -rf *.pdb - echo "Run image deploy ..." - setsid '/data/web/image/image-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - echo "Run docker deploy ..." - cd $CI_PROJECT_DIR/ - chmod +x docker-compose.sh - sh docker-compose.sh - exit only: - master - dev - tags when: on_success
.gitlab-ci.yml(net core&easyui&linux)
stages: - build - deploy before_script: - echo "Restore NuGet Packages..." - echo "dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln" - dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln build_job: stage: build script: - echo "Release publish..." - echo "dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj -c Release -o /data/web/easyui/publish" - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj -c Release -o /data/web/easyui/publish only: - master - dev deploy_job: stage: deploy script: - echo "Release deploy..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.EasyUIDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/easyui/publish/* /data/web/easyui/deploy/ - cd /data/web/easyui/deploy/ - rm -rf *.pdb - echo "run deploy..." - setsid '/data/web/easyui/easyui-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - exit only: - master when: on_success
/data/web/easyui/easyui-run-linux.sh
nohup dotnet /data/web/easyui/deploy/TLZ.COM.NetCore.View.EasyUIDemo.dll 1>wwwroot/nohup.log 2>&1 &
.gitlab-ci.yml(net core&image&linux)
stages: - build - deploy before_script: - echo "Restore NuGet Packages..." - echo "dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln" - dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln build_job: stage: build script: - echo "Release publish..." - echo "dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj -c Release -o /data/web/image/publish" - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj -c Release -o /data/web/image/publish only: - master - dev deploy_job: stage: deploy script: - echo "Release deploy..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.ImageSharpImageDemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/image/publish/* /data/web/image/deploy/ - cd /data/web/image/deploy/ - rm -rf *.pdb - echo "run deploy..." - setsid '/data/web/image/image-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - exit only: - master - tags when: on_success
/data/web/image/image-run-linux.sh
nohup dotnet /data/web/image/deploy/TLZ.COM.NetCore.View.ImageSharpImageDemo.dll 1>wwwroot/nohup.log 2>&1 &
.gitlab-ci.yml(net core&sso&linux)
stages: - build - deploy before_script: - echo "Restore NuGet Packages..." - echo "dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln" - dotnet restore $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.Demo.sln build_job: stage: build script: - echo "Release publish..." - echo "dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj -c Release -o /data/web/sso/publish" - dotnet publish $CI_PROJECT_DIR/TLZ.COM.NetCore.Demo/TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj -c Release -o /data/web/sso/publish only: - master - dev deploy_job: stage: deploy script: - echo "Release deploy..." - for PID in `ps -ef |grep TLZ.COM.NetCore.View.SSODemo.dll|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done - cp -rf /data/web/sso/publish/* /data/web/sso/deploy/ - cd /data/web/sso/deploy/ - rm -rf *.pdb - echo "run deploy..." - setsid '/data/web/sso/sso-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 - exit only: - master - tags when: on_success
/data/web/sso/sso-run-linux.sh
nohup dotnet /data/web/sso/deploy/TLZ.COM.NetCore.View.SSODemo.dll 1>wwwroot/nohup.log 2>&1 &
docker-compose.yml(net core&all)
version: '3.4' services: TLZ.COM.NetCore.View.EasyUIDemo: image: tlz.netcore.easyuidemo:1.0 build: context: ./TLZ.COM.NetCore.Demo dockerfile: ./TLZ.COM.NetCore.View.EasyUIDemo/Dockerfile environment: - ASPNETCORE_ENVIRONMENT=Development ports: - 17777:7777 TLZ.COM.NetCore.View.ImageSharpImageDemo: image: tlz.netcore.imagesharpimagedemo:1.0 build: context: ./TLZ.COM.NetCore.Demo dockerfile: ./TLZ.COM.NetCore.View.ImageSharpImageDemo/Dockerfile ports: - 15050:5050 volumes: - type: bind source: /data/web/image/docker target: /app/wwwroot/image-cache TLZ.COM.NetCore.View.SSODemo: image: tlz.netcore.ssodemo:1.0 build: context: ./TLZ.COM.NetCore.Demo dockerfile: ./TLZ.COM.NetCore.View.SSODemo/Dockerfile environment: - ASPNETCORE_ENVIRONMENT=Docker ports: - 11234:1234 external_links: - trusting_euclid:trusting_euclid network_mode: bridge
docker-compose.sh
docker-compose build --no-cache && docker-compose up -d
TLZ.COM.NetCore.View.EasyUIDemo(DockerFile)
FROM dotnet/core/aspnet:3.1 AS base WORKDIR /app EXPOSE 7777 FROM dotnet/core/sdk:3.1 AS build WORKDIR /src COPY ["TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj", "TLZ.COM.NetCore.View.EasyUIDemo/"] COPY ["TLZ.DapperEx/TLZ.DapperEx.csproj", "TLZ.DapperEx/"] COPY ["TLZ.ExpressionToSql/TLZ.ExpressionToSql.csproj", "TLZ.ExpressionToSql/"] COPY ["TLZ.WebMvc/TLZ.WebMvc.csproj", "TLZ.WebMvc/"] COPY ["TLZ.Web/TLZ.Web.csproj", "TLZ.Web/"] COPY ["TLZ.Helper/TLZ.Helper.csproj", "TLZ.Helper/"] COPY ["TLZ.Model/TLZ.Model.csproj", "TLZ.Model/"] COPY ["TLZ.UrlRule/TLZ.UrlRule.csproj", "TLZ.UrlRule/"] COPY ["TLZ.COM.Module.WebSite.Enum/TLZ.COM.Module.WebSite.Enum.csproj", "TLZ.COM.Module.WebSite.Enum/"] COPY ["TLZ.COM.DB.Entity/TLZ.COM.DB.Entity.csproj", "TLZ.COM.DB.Entity/"] COPY ["TLZ.COM.DB.SqlServerDAL/TLZ.COM.DB.SqlServerDAL.csproj", "TLZ.COM.DB.SqlServerDAL/"] COPY ["TLZ.DBCore/TLZ.DBCore.csproj", "TLZ.DBCore/"] COPY ["TLZ.COM.DB.IDAL/TLZ.COM.DB.IDAL.csproj", "TLZ.COM.DB.IDAL/"] COPY ["TLZ.Redis/TLZ.Redis.csproj", "TLZ.Redis/"] COPY ["TLZ.COM.DB.BLL/TLZ.COM.DB.BLL.csproj", "TLZ.COM.DB.BLL/"] COPY ["TLZ.COM.DB.BIZ/TLZ.COM.DB.BIZ.csproj", "TLZ.COM.DB.BIZ/"] COPY ["TLZ.CacheManager/TLZ.CacheManager.csproj", "TLZ.CacheManager/"] COPY ["TLZ.CacheCore/TLZ.CacheCore.csproj", "TLZ.CacheCore/"] COPY ["TLZ.FilterExpression/TLZ.FilterExpression.csproj", "TLZ.FilterExpression/"] COPY ["TLZ.COM.DB.MySqlDAL/TLZ.COM.DB.MySqlDAL.csproj", "TLZ.COM.DB.MySqlDAL/"] COPY ["TLZ.COM.DB.DataFilter/TLZ.COM.DB.DataFilter.csproj", "TLZ.COM.DB.DataFilter/"] RUN dotnet restore "TLZ.COM.NetCore.View.EasyUIDemo/TLZ.COM.NetCore.View.EasyUIDemo.csproj" COPY . . WORKDIR "/src/TLZ.COM.NetCore.View.EasyUIDemo" RUN dotnet build "TLZ.COM.NetCore.View.EasyUIDemo.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "TLZ.COM.NetCore.View.EasyUIDemo.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf ENTRYPOINT ["dotnet", "TLZ.COM.NetCore.View.EasyUIDemo.dll", "--environment=Docker"]
TLZ.COM.NetCore.View.ImageSharpImageDemo(DockerFile)
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base WORKDIR /app EXPOSE 5050 FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /src COPY ["TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj", "TLZ.COM.NetCore.View.ImageSharpImageDemo/"] COPY ["SixLabors.ImageSharp.WebEx/SixLabors.ImageSharp.WebEx.csproj", "SixLabors.ImageSharp.WebEx/"] RUN dotnet restore "TLZ.COM.NetCore.View.ImageSharpImageDemo/TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj" COPY . . WORKDIR "/src/TLZ.COM.NetCore.View.ImageSharpImageDemo" RUN dotnet build "TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "TLZ.COM.NetCore.View.ImageSharpImageDemo.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app VOLUME /app/wwwroot/image-cache COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "TLZ.COM.NetCore.View.ImageSharpImageDemo.dll"]
TLZ.COM.NetCore.View.SSODemo(DockerFile)
FROM dotnet/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 1234 FROM dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj", "TLZ.COM.NetCore.View.SSODemo/"] COPY ["TLZ.DapperEx/TLZ.DapperEx.csproj", "TLZ.DapperEx/"] COPY ["TLZ.ExpressionToSql/TLZ.ExpressionToSql.csproj", "TLZ.ExpressionToSql/"] COPY ["TLZ.WebMvc/TLZ.WebMvc.csproj", "TLZ.WebMvc/"] COPY ["TLZ.Web/TLZ.Web.csproj", "TLZ.Web/"] COPY ["TLZ.Helper/TLZ.Helper.csproj", "TLZ.Helper/"] COPY ["TLZ.Model/TLZ.Model.csproj", "TLZ.Model/"] COPY ["TLZ.COM.Module.WebSite.Enum/TLZ.COM.Module.WebSite.Enum.csproj", "TLZ.COM.Module.WebSite.Enum/"] COPY ["TLZ.QrCodeEx/TLZ.QrCodeEx.csproj", "TLZ.QrCodeEx/"] COPY ["TLZ.COM.DB.Entity/TLZ.COM.DB.Entity.csproj", "TLZ.COM.DB.Entity/"] COPY ["TLZ.COM.DB.SqlServerDAL/TLZ.COM.DB.SqlServerDAL.csproj", "TLZ.COM.DB.SqlServerDAL/"] COPY ["TLZ.DBCore/TLZ.DBCore.csproj", "TLZ.DBCore/"] COPY ["TLZ.COM.DB.IDAL/TLZ.COM.DB.IDAL.csproj", "TLZ.COM.DB.IDAL/"] COPY ["TLZ.Redis/TLZ.Redis.csproj", "TLZ.Redis/"] COPY ["TLZ.COM.DB.BLL/TLZ.COM.DB.BLL.csproj", "TLZ.COM.DB.BLL/"] COPY ["TLZ.SSO/TLZ.SSO.csproj", "TLZ.SSO/"] COPY ["TLZ.COM.DB.BIZ/TLZ.COM.DB.BIZ.csproj", "TLZ.COM.DB.BIZ/"] COPY ["TLZ.CacheManager/TLZ.CacheManager.csproj", "TLZ.CacheManager/"] COPY ["TLZ.CacheCore/TLZ.CacheCore.csproj", "TLZ.CacheCore/"] COPY ["TLZ.COM.DB.MySqlDAL/TLZ.COM.DB.MySqlDAL.csproj", "TLZ.COM.DB.MySqlDAL/"] COPY ["TLZ.COM.DB.DataFilter/TLZ.COM.DB.DataFilter.csproj", "TLZ.COM.DB.DataFilter/"] COPY ["TLZ.FilterExpression/TLZ.FilterExpression.csproj", "TLZ.FilterExpression/"] RUN dotnet restore "TLZ.COM.NetCore.View.SSODemo/TLZ.COM.NetCore.View.SSODemo.csproj" COPY . . WORKDIR "/src/TLZ.COM.NetCore.View.SSODemo" RUN dotnet build "TLZ.COM.NetCore.View.SSODemo.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "TLZ.COM.NetCore.View.SSODemo.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . RUN sed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf ENTRYPOINT ["dotnet", "TLZ.COM.NetCore.View.SSODemo.dll", "--environment=Docker"]
-----------------------------------------------------
.gitlab-ci.yml(java&springmvc)
stages: - pull - build - deploy pull_job: stage: pull script: - echo "Restoring Git..." - cd /data/git/run/com.common - git pull - cd /data/git/run/com.sem.sdk - git pull - cd /data/git/run/com.sem.db - git pull - cd /data/git/run/com.sem.api - git pull build_job: stage: build script: - echo "Maven build..." - cd /data/git/run/com.common/com.common.bus - mvn clean install - cd /data/git/run/com.sem.sdk/com.sem.sdk.bus - mvn clean install - cd /data/git/run/com.sem.api/com.sem.api.bus - mvn clean install - cd /data/git/run/com.sem.db/com.sem.db.bus - mvn clean install - cd $CI_PROJECT_DIR/com.sem.view.market - mvn clean package - cp $CI_PROJECT_DIR/com.sem.view.market/target/com.sem.view.market-1.0.0.war /data/war/com.sem.view.market.war only: - master deploy_job: stage: deploy script: - echo "重启 Tomcat..." - setsid '/root/restart.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 only: - master
/root/restart.sh
#!/bin/bash /data/tomcat/bin/shutdown.sh for PID in `ps -ef |grep tomcat|grep -v grep|awk '{print $2}'`; do kill -9 $PID; done /data/tomcat/bin/startup.sh
/root/restartTomcat.sh (带sleep 2s)
1 #!/bin/bash 2 echo "old pid:" 3 ps -ef | grep tomcat | grep -v grep | awk '{print $2}' 4 ps -ef | grep tomcat | grep -v grep | awk '{print $2}' | sed -e "s/^/kill -9 /g" | sh - 5 sleep 2s 6 /data/tomcat/bin/startup.sh 7 echo "new pid:" 8 ps -ef | grep tomcat | grep -v grep | awk '{print $2}' 9 10 11 12 #!/bin/bash 13 echo "old pid:" && ps -ef | grep tomcat | grep -v grep | awk '{print $2}' 14 echo "关闭 tomcat" && /data/tomcat/bin/shutdown.sh 15 sleep 2s 16 export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/data/elastic-amp-agent/elastic-apm-agent-1.9.0.jar 17 -Delastic.apm.service_name=tomcat-tbdress-solr-1-service 18 -Delastic.apm.application_packages=org.example,org.another.example 19 -Delastic.apm.server_urls=https://apm-server-sample-elastic.tidebuy.net/ 20 -Delastic.apm.secret_token=xsl8x8zn85sfvnhkldwv75wd 21 -Dcom.sun.management.jmxremote 22 -Dcom.sun.management.jmxremote.authenticate=false 23 -Dcom.sun.management.jmxremote.ssl=false 24 -Dcom.sun.management.jmxremote.port=12345 25 -Djava.rmi.server.hostname=192.168.3.59 26 " 27 echo "启动 tomcat" && /data/tomcat/bin/startup.sh 28 echo "new pid:" 29 ps -ef | grep tomcat | grep -v grep | awk '{print $2}'
tomcat server.xml
1 <?xml version='1.0' encoding='utf-8'?> 2 <Server port="8005" shutdown="SHUTDOWN"> 3 <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 4 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" /> 5 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 6 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 7 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 8 9 <GlobalNamingResources> 10 <Resource name="UserDatabase" auth="Container" 11 type="org.apache.catalina.UserDatabase" 12 description="User database that can be updated and saved" 13 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 14 pathname="conf/tomcat-users.xml" /> 15 </GlobalNamingResources> 16 17 <Service name="Catalina"> 18 <Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol" 19 connectionTimeout="20000000" 20 maxThreads="600" minSpareThreads="100" maxSpareThreads="500" 21 maxProcessors="75" minProcessors="5" acceptCount="700" enableLookups="false" URIEncoding="UTF-8" 22 compression="on" disableUploadTimeout="true" noCompressionUserAgents="gozilla,traviata" useSendfile="false" 23 compressableMimeType="text/html,text/xml,text/javascript,application/javascript,application/json,text/css,text/plain" 24 /> 25 26 <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" 27 maxThreads="150" SSLEnabled="true" scheme="https" secure="true" 28 clientAuth="false" sslProtocol="TLS" keystoreFile="/data/cert/tomcat.keystore" keystorePass="qwe123" 29 ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" 30 URIEncoding="UTF-8" 31 /> 32 33 34 <Engine name="Catalina" defaultHost="run.tidebuy.net"> 35 <Realm className="org.apache.catalina.realm.LockOutRealm"> 36 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> 37 </Realm> 38 <Host name="tomcat.run.tidebuy.net" appBase="webapps" unpackWARs="true" autoDeploy="true"></Host> 39 <Host name="run.tidebuy.net" appBase="/data/web/com.sem.view.market" unpackWARs="true" autoDeploy="true"> 40 <Alias>run.tidebuy.net</Alias> 41 <Context path="/" docBase="/data/war/com.sem.view.market.war" privileged="true" antiResourceLocking="false" antiJARLocking="false" crossContext="true" caseSensitive="false" reloadable="false"/> 42 </Host> 43 </Engine> 44 </Service> 45 </Server>
------------------------------------------------------------------------------
.gitlab-ci.yml(java&springboot&linux&docker-build-run)
1 stages: 2 - build 3 - deploy 4 5 build_job: 6 stage: build 7 image: docker.tidebuy.net/maven:3-jdk-8 8 script: 9 - echo "Maven build..." 10 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.common 11 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 12 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.db 13 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 14 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo 15 - mvn clean package -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 16 - if [ ! -d "$CI_PROJECT_DIR/publish/springboot" ]; then mkdir -p "$CI_PROJECT_DIR/publish/springboot"; fi 17 - cp -rf $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo/target/tb.easyuidemo.jar $CI_PROJECT_DIR/publish/springboot/tb.easyuidemo.jar 18 artifacts: 19 name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME" 20 paths: 21 - publish/ 22 expire_in: 1 days 23 only: 24 - master 25 26 deploy_job: 27 stage: deploy 28 image: "docker:19.03.5" 29 dependencies: 30 - build_job 31 services: 32 - docker:19.03.5-dind 33 script: 34 - echo "Release deploy..." 35 - for PID in `ps -ef |grep tb.easyuidemo.jar|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done 36 - cp -rf $CI_PROJECT_DIR/publish/springboot/* /data/web/springboot/deploy/ 37 - cd /data/web/springboot/deploy/ 38 - echo "run deploy..." 39 - setsid '/data/web/springboot/springboot-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 40 - echo "Run docker deploy ..." 41 - cd $CI_PROJECT_DIR/ 42 - chmod +x docker-compose.sh 43 - sh docker-compose.sh 44 45 - echo "Run docker build ..." 46 - image_version="${CI_APPLICATION_TAG:-${CI_COMMIT_SHA:0:8}}" 47 - easyui_image="springboot22easyui" 48 - cd $CI_PROJECT_DIR 49 - docker build -f rancher-pipeline/Dockerfile 50 --build-arg APP_PATH="publish/springboot/" 51 --build-arg MAIN_DLL="tb.easyuidemo.jar" 52 --build-arg PORT="8090" 53 --build-arg MAIN_ENV="--spring.profiles.active=docker" 54 --tag "$easyui_image:$image_version" 55 --tag "$easyui_image:latest" 56 . 57 58 - echo "Run docker run ..." 59 - for container_id in $(docker ps -a --filter="name=$easyui_image" -q);do docker rm -f $container_id;done 60 - docker run -d -p 28090:8090 --link heuristic_stallman --network bridge --workdir /app --name $easyui_image $easyui_image:$image_version 61 62 - exit 63 only: 64 - master 65 when: on_success
rancher-pipeline\Dockerfile
1 from docker.tidebuy.net/openjdk:8 2 WORKDIR app 3 4 ARG APP_PATH 5 ARG MAIN_DLL 6 ARG MAIN_ENV 7 8 COPY ${APP_PATH} . 9 ENV MAIN_DLL=${MAIN_DLL} 10 ENV MAIN_ENV=${MAIN_ENV} 11 EXPOSE ${PORT} 12 13 CMD ["sh", "-c","java -jar /app/$MAIN_DLL $MAIN_ENV"]
rancher-pipeline\settings.xml
1 <settings> 2 <mirrors> 3 <mirror> 4 <id>rancher</id> 5 <mirrorOf>*</mirrorOf> 6 <name>Rancher Repository</name> 7 <url>http://192.168.0.112/repository/maven-public/</url> 8 </mirror> 9 </mirrors> 10 </settings>
------------------------------------------------------------------------
.gitlab-ci.yml(java&springboot&linux&docker-compose)
1 stages: 2 - build 3 - deploy 4 5 build_job: 6 stage: build 7 script: 8 - echo "Maven build..." 9 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.common 10 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 11 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.db 12 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 13 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo 14 - mvn clean package -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml 15 - cp $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo/target/tb.easyuidemo.jar /data/web/springboot/publish/tb.easyuidemo.jar 16 only: 17 - master 18 19 deploy_job: 20 stage: deploy 21 script: 22 - echo "Release deploy..." 23 - for PID in `ps -ef |grep tb.easyuidemo.jar|grep -v grep|awk '{print $2}'`;do kill -9 $PID; done 24 - cp -rf /data/web/springboot/publish/* /data/web/springboot/deploy/ 25 - cd /data/web/springboot/deploy/ 26 - echo "run deploy..." 27 - setsid '/data/web/springboot/springboot-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/2231 28 - echo "Run docker deploy ..." 29 - cd $CI_PROJECT_DIR/ 30 - chmod +x docker-compose.sh 31 - sh docker-compose.sh 32 - exit 33 only: 34 - master
/data/web/springboot/springboot-run-linux.sh
nohup java -jar /data/web/springboot/deploy/tb.easyuidemo.jar --spring.profiles.active=sharding 1>nohup.log 2>&1 &
maven_install&package.bat (windows)
cd ./tb.common call mvn clean install -Dmaven.test.skip=true cd ../tb.db call mvn clean install -Dmaven.test.skip=true cd ../tb.view.sbmsm.easyuidemo call mvn clean package -Dmaven.test.skip=true cd .. echo Success !!! Thank you, Mr.WangYunPeng !!! Good Luck my friend !!! pause
docker-compose.yml
version: '3.4' services: tb.com.sbmsm.demo: image: tb.com.sbmsm.demo:1.0 build: context: ./tb.com.sbmsm.demo dockerfile: ./tb.view.sbmsm.easyuidemo/Dockerfile ports: - 18090:8090 external_links: - heuristic_stallman:heuristic_stallman network_mode: bridge
docker-compose.sh
docker-compose build --no-cache && docker-compose up -d
tb.view.sbmsm.easyuidemo\Dockerfile(DockerFile)
FROM openjdk:8 AS base WORKDIR /app EXPOSE 8090 FROM maven:3-jdk-8 AS build WORKDIR /app COPY . . RUN mvn clean install -Dmaven.test.skip=true -f tb.common/pom.xml -s settings.xml; \ mvn clean install -Dmaven.test.skip=true -f tb.db/pom.xml -s settings.xml; \ mvn clean package -Dmaven.test.skip=true -f tb.view.sbmsm.easyuidemo/pom.xml -s settings.xml FROM base AS final WORKDIR /app COPY --from=build /app/tb.view.sbmsm.easyuidemo/target/tb.easyuidemo.jar . ENTRYPOINT ["java", "-jar", "tb.easyuidemo.jar", "--spring.profiles.active=docker"]
settings.xml
<settings> <mirrors> <mirror> <id>rancher</id> <mirrorOf>*</mirrorOf> <name>Rancher Repository</name> <url>http://192.168.0.112/repository/maven-public/</url> </mirror> </mirrors> </settings>