转载

Jenkins自动化部署 .net core

Jenkins自动化部署 .net core

k8s in rancher版

Jenkins自动化部署 .net core

准备基础软件

Gogs

docker run -d -p 10022:22 -p 10080:3000 / 
--name=gogs --net=gogs / 
-v /opt/docker/gogs/:/data / 
gogs/gogs
复制代码

Rancher

docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:stable
复制代码

Jenkins

https://hub.docker.com/r/carsonf/jenkinsci_jenkins
https://github.com/CarsonFjz/ci-jenkins-with-docker //构建源码,可自己定制其他
复制代码

Jenkins docker

1.初始密码在 /jenkins_home/secrets/initialAdminPassword 这个文件

2.完成初始化后 在左边列表 [系统管理->插件管理] 下载安装插件并重启jenkins

可选插件那里安装Gogs和Git Parameter,然后重启jenkins

Jenkins自动化部署 .net core

3.新建项目

Jenkins自动化部署 .net core

4.在Gogs配置一个钩子

推送地址:http://[jenkins url]/gogs-webhook/?job=[project name]

Jenkins自动化部署 .net core

5.在Jenkins的项目配置

Jenkins自动化部署 .net core
Jenkins自动化部署 .net core

6.编辑自己的dockerfile和docker-compose.yml

docker-compose.yml

ps: ${GIT_BRANCH}是获取git分支名称

version: '3.3'

services: 
  webapp:
    restart: always
    image: "${GIT_BRANCH}/webapp"
    build:
      context: WebApplication1/.
      dockerfile: Dockerfile
    container_name: webapptest
    ports:
      - "8085:8085"
复制代码

dockerfile

根据自己实际情况进行构建

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 8085

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY . .
RUN dotnet restore "WebApplication1.csproj"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
复制代码
原文  https://juejin.im/post/5cb8a1dd51882546402b217f
正文到此结束
Loading...