惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
雷峰网
雷峰网
罗磊的独立博客
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
Cisco Talos Blog
Cisco Talos Blog
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
About on SuperTechFans
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Cloudflare Blog
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
Spread Privacy
Spread Privacy
D
DataBreaches.Net
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Cyberwarzone
Cyberwarzone
爱范儿
爱范儿
U
Unit 42
Security Latest
Security Latest
M
MIT News - Artificial intelligence
月光博客
月光博客
Scott Helme
Scott Helme
G
Google Developers Blog
有赞技术团队
有赞技术团队
T
Tor Project blog
宝玉的分享
宝玉的分享
Y
Y Combinator Blog
博客园 - Franky
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
V
V2EX
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
S
Securelist
博客园 - 三生石上(FineUI控件)
Blog — PlanetScale
Blog — PlanetScale
TaoSecurity Blog
TaoSecurity Blog
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
腾讯CDC
D
Docker
Google Online Security Blog
Google Online Security Blog

博客园 - ddrsql

从“黑盒”到“全景”:在.NET中拥抱OpenTelemetry与SigNoz的可观测工具 关于git分支堆叠 记录团队使用git合并代码丢失 记一次对老服务改造 国产麒麟(Kylin-Server-10)系统无外网环境安装docker vue3学习之axios、mockjs、nswag vue3学习之tabler组件Layout布局 vue3学习之BootstrapVueNext Framework升级到Core以及Dapper支持达梦数据库 Avalonia集成Prism与Abp Avalonia中使用EF增删改查DM数据库 Linux中使用原生Wpf之Avalonia WPF通过wine适配统信uos系统 单体仓库下通过helm优雅的将微服务部署到k8s DevOps 前端项目(angular、vue、react)打包静态资源生成一份Docker镜像支持部署不同环境 VS使用IIS调试(非附加进程).net core、.net framework程序 k8s集群通过nginx-ingress做tcp、udp 4层网络转发 swaggerui集成oauth implicit redis cluster集群web管理工具 relumin
DevOps .net core Jenkins持续集成Linux、Docker、K8S
ddrsql · 2019-03-30 · via 博客园 - ddrsql

jenkins插件

系统管理 -> 管理插件,安装如下插件。

#如果搜索不到去掉Plugin在搜索
GitLab Plugin
Gitlab Hook Plugin
#使用Gitlab账号做用户权限管理,可选(也可集成LDAP)
Gitlab Authentication plugin

Docker plugin
docker-build-step

SSH plugin

GitLab Plugin配置

在GitLab中配置,创建个人访问令牌后获取到令牌备用

系统管理 -> 系统设置 中 左上角 'Jenkins > 配置' 选择GitLab

Credentials配置

  • 类型选择GitLab API token
  • 将令牌填充到API token中
  • 描述 名称

创建构建任务

  • 新建任务 -> 输入名称 选择构建一个自由风格的软件项目;完成后进入配置。

  • 源码管理 -> Git;

Repository URL:中填入gitlab项目对应的ssh路径(eg:git@git.cn:group/sample.app.git);

Credentials:设置添加SSH私钥;

同时在gitlab( http://xxx/profile/keys )添加ssh公钥

  • 构建触发器 -> 勾选Build when a change is pushed to GitLab;

将GitLab webhook URL: http://xxx/group/sample.app 、Secret token添加到gitlab( http://xxx/group/sample.app/settings/integrations


  • 构建环境 -> 勾选Delete workspace before build starts、Add timestamps to the Console Output;

  • 构建 -> 增加构建步骤 -> 执行 shell;

添加sh脚本,jenkins服务需要安装dotnet。
如果需要.netcore多版本环境参考CentOS 7 下安装部署.NET Core多版本环境

#!/bin/sh

pwd
ls
echo $PATH
whoami
which dotnet
dotnet --info
dotnet --version

echo '=====dotnet 方式====='
dotnet restore
cd ./src/sample.app
rm -rf $WORKSPACE/jenkins_publish
mkdir -p $WORKSPACE/jenkins_publish
dotnet publish -o $WORKSPACE/jenkins_publish
scp -r $WORKSPACE/jenkins_publish/* root@xx.xx.xx.xx:/home/Web

echo '=====Docker swarm方式====='
GITHASH=`git rev-parse --short HEAD`
echo $GITHASH

cd $WORKSPACE
docker login xx.xx.xx.xx -u admin -p HarborPwd
docker build -t img-name:$GITHASH . -f src/Dockerfile
docker tag img-name:$GITHASH xx.xx.xx.xx/img-name:$GITHASH
docker push xx.xx.xx.xx/img-name:$GITHASH

#清理容器
docker rm $(sudo docker ps -a -q)
#清理image
docker images|grep none|awk '{print $3}'|xargs docker rmi

cat>test.yml<<EOF
version: '3.4'

services:
 img-name:
   image: xx.xx.xx.xx/img-name:$GITHASH
   environment:
     ASPNETCORE_ENVIRONMENT: 'dev'
   volumes:
     - /etc/localtime:/etc/localtime:ro
   ports:
     - target: 80
       published: 9527
       mode: host
   deploy:
     mode: global
EOF
#拷贝到docker swarm所在服务器
scp test.yml root@xx.xx.xx.xx:/root


echo '=====K8s 方式====='
GITHASH=`git rev-parse --short HEAD`
echo $GITHASH

cd $WORKSPACE
docker login xx.xx.xx.xx -u admin -p HarborPwd
docker build -t img-name:$GITHASH . -f src/Dockerfile
docker tag img-name:$GITHASH xx.xx.xx.xx/img-name:$GITHASH
docker push xx.xx.xx.xx/img-name:$GITHASH

#清理容器
docker rm $(sudo docker ps -a -q)
#清理image
docker images|grep none|awk '{print $3}'|xargs docker rmi

cat>test.yaml<<EOF
apiVersion: v1
kind: Service
metadata:
 labels:
   app: api-service
 name: api-service
spec:
 #type: NodePort  #nodeport方式暴露
 selector:
   app: api-service
 ports:
 - protocol: TCP
   port: 80
   targetPort: 80
   #nodePort: 30002  #端口范围只能是 30000-32767,不指定随机分配
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: api-service-ingress
 namespace: default
spec:
 rules:
 - host: api.xxxx.com  #域名
   http:
     paths:
     - path: /
       backend:
         serviceName: api-service
         servicePort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: api-service-deployment
spec:
 selector:
   matchLabels:
     app: api-service
 replicas: 1
 template:
   metadata:
     labels:
       app: api-service
   spec:
     containers:
       - name: api-service
         image: xx.xx.xx.xx/api-service:$GITHASH
         imagePullPolicy: Always
         ports:
           - containerPort: 80
         volumeMounts:
           - name: timezone
             mountPath: /etc/localtime
     volumes:
       - name: timezone
         hostPath:
           path: /etc/localtime
     imagePullSecrets:
       - name: secret-name
EOF
#拷贝到k8s master所在服务器
scp test.yaml root@xx.xx.xx.xx:/usr/local/src
  • 构建 -> 增加构建步骤 -> Build / Publish Docker Image;

在上面直接使用shell命令,未使用此功能

  • 构建 -> 增加构建步骤 -> Execute shell script on remote host using ssh;

部署

#Command中shell脚本
echo '=====虚拟机方式====='
supervisorctl restart youserver-name

echo '=====Docker swarm 方式====='
docker -v
docker stack deploy -c test.yml --with-registry-auth test

echo '=====K8s 方式====='
cd /usr/local/src
kubectl apply -f .
kubectl get pod

虚拟机方式

Docker swarm方式

K8s 方式