git ci自动打包java_gitlab-CI作业-yml (setsid命令) JAVA Tomcat NetCore 自动部署

git ci自动打包java_gitlab-CI作业-yml (setsid命令) JAVA Tomcat NetCore 自动部署_第1张图片

.gitlab-ci.yml(net core&all&linux&docker-build-run)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 stages:2 -build3 -deploy4

5 build_job:6 stage: build7 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.sln12 - 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: 1days23 only:24 -master25 -dev26

27 deploy_job:28 stage: deploy29 image: "docker:19.03.5"

30 dependencies:31 -build_job32 services:33 - docker:19.03.5-dind34 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 *.pdb40 - echo "Run easyui deploy ..."41 - setsid '/data/web/easyui/easyui-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/223142 - 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; done44 - cp -rf $CI_PROJECT_DIR/publish/sso/* /data/web/sso/deploy/45 - cd /data/web/sso/deploy/46 - rm -rf *.pdb47 - echo "Run sso deploy ..."48 - setsid '/data/web/sso/sso-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/223149 - 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; done51 - cp -rf $CI_PROJECT_DIR/publish/image/* /data/web/image/deploy/52 - cd /data/web/image/deploy/53 - rm -rf *.pdb54 - echo "Run image deploy ..."55 - setsid '/data/web/image/image-run-linux.sh' #直接从CI作业开始的任何进程都将在作业结束时终止https://gitlab.com/gitlab-org/gitlab-runner/issues/223156 - echo "Run docker-compose deploy ..."57 - cd $CI_PROJECT_DIR/58 - chmod +x docker-compose.sh59 - sh docker-compose.sh60

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_DIR67 - docker build -f rancher-pipeline/Dockerfile68 --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/Dockerfile76 --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/Dockerfile84 --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;done94 - docker run -d -p 27777:7777 --link trusting_euclid --network bridge --workdir /app --name $easyui_image $easyui_image:$image_version95 - for container_id in $(docker ps -a --filter="name=$sso_image" -q);do docker rm -f $container_id;done96 - docker run -d -p 21234:1234 --link trusting_euclid --network bridge --workdir /app --name $sso_image $sso_image:$image_version97 - for container_id in $(docker ps -a --filter="name=$image_image" -q);do docker rm -f $container_id;done98 - docker run -d -p 25050:5050 --volume /data/web/image/docker:/app/wwwroot/image-cache --workdir /app --name $image_image $image_image:$image_version99 - exit100 only:101 - master102 - dev103 - tags104 when: on_success

.gitlab-ci.yml(net core&all&linux&docker-build-run)

rancher-pipeline/Dockerfile

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

FROM docker.tidebuy.net/dotnet/core/aspnet:3.1WORKDIR/app

RUNecho "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"]

rancher-pipeline/Dockerfile

------------------------------------------------------------------------

.gitlab-ci.yml(net core&all&linux&docker-compose)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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&linux&docker-compose)

.gitlab-ci.yml(net core&easyui&linux)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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

.gitlab-ci.yml(net core&easyui)

/data/web/easyui/easyui-run-linux.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

nohup dotnet /data/web/easyui/deploy/TLZ.COM.NetCore.View.EasyUIDemo.dll 1>wwwroot/nohup.log 2>&1 &

easyui-run-linux.sh

.gitlab-ci.yml(net core&image&linux)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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

.gitlab-ci.yml(net core&image)

/data/web/image/image-run-linux.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

nohup dotnet /data/web/image/deploy/TLZ.COM.NetCore.View.ImageSharpImageDemo.dll 1>wwwroot/nohup.log 2>&1 &

image-run-linux.sh

.gitlab-ci.yml(net core&sso&linux)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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

.gitlab-ci.yml(net core&sso)

/data/web/sso/sso-run-linux.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

nohup dotnet /data/web/sso/deploy/TLZ.COM.NetCore.View.SSODemo.dll 1>wwwroot/nohup.log 2>&1 &

sso-run-linux.sh

docker-compose.yml(net core&all)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

version: '3.4'services:

TLZ.COM.NetCore.View.EasyUIDemo:

image: tlz.netcore.easyuidemo:1.0build:

context: ./TLZ.COM.NetCore.Demo

dockerfile: ./TLZ.COM.NetCore.View.EasyUIDemo/Dockerfile

environment:- ASPNETCORE_ENVIRONMENT=Development

ports:- 17777:7777TLZ.COM.NetCore.View.ImageSharpImageDemo:

image: tlz.netcore.imagesharpimagedemo:1.0build:

context: ./TLZ.COM.NetCore.Demo

dockerfile: ./TLZ.COM.NetCore.View.ImageSharpImageDemo/Dockerfile

ports:- 15050:5050volumes:-type: bind

source:/data/web/image/docker

target:/app/wwwroot/image-cache

TLZ.COM.NetCore.View.SSODemo:

image: tlz.netcore.ssodemo:1.0build:

context: ./TLZ.COM.NetCore.Demo

dockerfile: ./TLZ.COM.NetCore.View.SSODemo/Dockerfile

environment:- ASPNETCORE_ENVIRONMENT=Docker

ports:- 11234:1234external_links:-trusting_euclid:trusting_euclid

network_mode: bridge

docker-compose.yml

docker-compose.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

docker-compose build --no-cache && docker-compose up -d

docker-compose.sh

TLZ.COM.NetCore.View.EasyUIDemo(DockerFile)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

FROM dotnet/core/aspnet:3.1AS base

WORKDIR/app

EXPOSE7777FROM dotnet/core/sdk:3.1AS 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 .

RUNsed -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.EasyUIDemo(DockerFile)

TLZ.COM.NetCore.View.ImageSharpImageDemo(DockerFile)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2AS base

WORKDIR/app

EXPOSE5050FROM mcr.microsoft.com/dotnet/core/sdk:2.2AS 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.ImageSharpImageDemo(DockerFile)

TLZ.COM.NetCore.View.SSODemo(DockerFile)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

FROM dotnet/core/aspnet:3.1-buster-slim AS base

WORKDIR/app

EXPOSE1234FROM 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 .

RUNsed -i 's/TLSv1.2/TLSv1.0/g' /etc/ssl/openssl.cnf

ENTRYPOINT ["dotnet", "TLZ.COM.NetCore.View.SSODemo.dll", "--environment=Docker"]

TLZ.COM.NetCore.View.SSODemo(DockerFile)

-----------------------------------------------------

.gitlab-ci.yml(java&springmvc)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

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

.gitlab-ci.yml(java&springmvc)

/root/restart.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

#!/bin/bash/data/tomcat/bin/shutdown.shfor PID in `ps -ef |grep tomcat|grep -v grep|awk '{print $2}'`; do kill -9$PID; done/data/tomcat/bin/startup.sh

/root/restart.sh

/root/restartTomcat.sh (带sleep 2s)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 #!/bin/bash2 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 sleep2s6 /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/bash13 echo "old pid:" && ps -ef | grep tomcat | grep -v grep | awk '{print $2}'

14 echo "关闭 tomcat" && /data/tomcat/bin/shutdown.sh

15 sleep2s16 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-service18 -Delastic.apm.application_packages=org.example,org.another.example19 -Delastic.apm.server_urls=https://apm-server-sample-elastic.tidebuy.net/

20 -Delastic.apm.secret_token=xsl8x8zn85sfvnhkldwv75wd21 -Dcom.sun.management.jmxremote22 -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}'

restartTomcat.sh

tomcat server.xml

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1

2

3

4

5

6

7

8

9

10

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

16

17

18

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

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

35

36

37

38

39

40 run.tidebuy.net

41

42

43

44

45

tomcat server.xml

------------------------------------------------------------------------------

.gitlab-ci.yml(java&springboot&linux&docker-build-run)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 stages:2 -build3 -deploy4

5 build_job:6 stage: build7 image: docker.tidebuy.net/maven:3-jdk-8

8 script:9 - echo "Maven build..."

10 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.common11 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml12 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.db13 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml14 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo15 - mvn clean package -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml16 - 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.jar18 artifacts:19 name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"

20 paths:21 - publish/

22 expire_in: 1days23 only:24 -master25

26 deploy_job:27 stage: deploy28 image: "docker:19.03.5"

29 dependencies:30 -build_job31 services:32 - docker:19.03.5-dind33 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/223140 - echo "Run docker deploy ..."41 - cd $CI_PROJECT_DIR/42 - chmod +x docker-compose.sh43 - sh docker-compose.sh44

45 - echo "Run docker build ..."46 - image_version="${CI_APPLICATION_TAG:-${CI_COMMIT_SHA:0:8}}"47 - easyui_image="springboot22easyui"48 - cd $CI_PROJECT_DIR49 - docker build -f rancher-pipeline/Dockerfile50 --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;done60 - docker run -d -p 28090:8090 --link heuristic_stallman --network bridge --workdir /app --name $easyui_image $easyui_image:$image_version61

62 - exit63 only:64 - master65 when: on_success

.gitlab-ci.yml(java&springboot&linux&docker-build-run)

rancher-pipeline\Dockerfile

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 from docker.tidebuy.net/openjdk:8

2 WORKDIR app3

4 ARG APP_PATH5 ARG MAIN_DLL6 ARG MAIN_ENV7

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\Dockerfile

rancher-pipeline\settings.xml

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1

2

3

4 rancher

5 *

6 Rancher Repository

7 http://192.168.0.112/repository/maven-public/

8

9

10

rancher-pipeline\settings.xml

------------------------------------------------------------------------

.gitlab-ci.yml(java&springboot&linux&docker-compose)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 stages:2 -build3 -deploy4

5 build_job:6 stage: build7 script:8 - echo "Maven build..."

9 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.common10 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml11 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.db12 - mvn clean install -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml13 - cd $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo14 - mvn clean package -Dmaven.test.skip=true -s ../../rancher-pipeline/settings.xml15 - cp $CI_PROJECT_DIR/tb.com.sbmsm.demo/tb.view.sbmsm.easyuidemo/target/tb.easyuidemo.jar /data/web/springboot/publish/tb.easyuidemo.jar16 only:17 -master18

19 deploy_job:20 stage: deploy21 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/223128 - echo "Run docker deploy ..."29 - cd $CI_PROJECT_DIR/30 - chmod +x docker-compose.sh31 - sh docker-compose.sh32 - exit33 only:34 - master

.gitlab-ci.yml(java&springboot&linux&docker-compose)

/data/web/springboot/springboot-run-linux.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

nohup java -jar /data/web/springboot/deploy/tb.easyuidemo.jar --spring.profiles.active=sharding 1>nohup.log 2>&1 &

/data/web/springboot/springboot-run-linux.sh

maven_install&package.bat (windows)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

cd ./tb.common

call mvn cleaninstall -Dmaven.test.skip=truecd ../tb.db

call mvn cleaninstall -Dmaven.test.skip=truecd ../tb.view.sbmsm.easyuidemo

call mvn clean package-Dmaven.test.skip=truecd ..echo Success !!! Thank you, Mr.WangYunPeng !!! Good Luck my friend !!!pause

maven_install&package.bat

docker-compose.yml

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

version: '3.4'services:

tb.com.sbmsm.demo:

image: tb.com.sbmsm.demo:1.0build:

context: ./tb.com.sbmsm.demo

dockerfile: ./tb.view.sbmsm.easyuidemo/Dockerfile

ports:- 18090:8090external_links:-heuristic_stallman:heuristic_stallman

network_mode: bridge

docker-compose.yml

docker-compose.sh

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

docker-compose build --no-cache && docker-compose up -d

docker-compose.sh

tb.view.sbmsm.easyuidemo\Dockerfile(DockerFile)

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

FROM openjdk:8AS base

WORKDIR/app

EXPOSE8090FROM maven:3-jdk-8AS build

WORKDIR/app

COPY . .

RUN mvn cleaninstall -Dmaven.test.skip=true -f tb.common/pom.xml -s settings.xml; \

mvn cleaninstall -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"]

tb.view.sbmsm.easyuidemo\Dockerfile(DockerFile)

settings.xml

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

rancher

*

Rancher Repository

http://192.168.0.112/repository/maven-public/

settings.xml

你可能感兴趣的:(git,ci自动打包java)