1.准备编译环境容器,所有容器镜像制作gemdaledockerfile这个代码里面,也可以直接拉取官方镜像部署

docker run --name node1420-patternx -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t node:14.20.0

docker run --name node1615-patternx  -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t node:16.15.1

docker run --name nodejs1417-patternx -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t jelastic/nodejs:14.17.5-forever

FROM node:16.20.1-bullseye
docker run --name nodejs16 -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t linice/nodejs16:v1.1.0.0

FROM golang:1.19.6-buster
docker run --name golang -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ -v /data/etc/cron.d/:/etc/cron.d/ -v /data/etc/supervisord.d/:/etc/supervisord.d/ -v /data/var/log/supervisor/:/var/log/supervisor/ --net host --restart always -d -t golang:1.19.6-bullseye

FROM node:14.20.0-buster
docker run --name nodejs14 -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t linice/nodejs14:v1.2.0.0

FROM python:3.9.17-bullseye
docker run --name python39-testing -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t linice/python39-testing:v1.0.0.1

FROM maven:3.8.6-openjdk-11
docker run --name maven3-openjdk11 -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t linice/maven3-openjdk11:v1.2.0.0

FROM python:3.10.13-bullseye
docker run --name ansible --privileged -v /data/root/.ssh/:/root/.ssh/ -v /data/root/.tiup/:/root/.tiup/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ -v /data/ansible/:/data/ -v /data/etc/ansible/:/etc/ansible/ --restart always -d -t linice/ansible:v1.2.0.0

FROM maven:3.8.6-openjdk-8
docker run --name maven3-openjdk8 -v /data/var/www/:/data/var/www/ -v /var/jenkins_home/:/var/jenkins_home/ -v /mnt/hgfs/:/mnt/hgfs/ --net host --restart always -d -t linice/maven3-openjdk8:v1.1.0.0

2.发布jenkins的shell执行脚本代码仓库gemdale_jenkins

gemdale_jenkins
在这里插入图片描述
This project is parameterized
Choice Parameter 参数名称这些参数作为环境变量公开用于构建
这个是定义项目脚本里面变量
dr 默认deploy部署脚本 可以rollback回滚脚本
在这里插入图片描述
project ienjoys 项目变量
在这里插入图片描述
env test prod 环境变量
在这里插入图片描述
部署服务器
在这里插入图片描述
实际部署的服务service是服务名称变量,gemdale_jenkins是实际服务名
在这里插入图片描述
代码分支
在这里插入图片描述
选择变量falsetrue是否更新helm chart release. 默认false, 即不更新.第一次执行要选true
在这里插入图片描述
回滚设置
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
bash /data/var/www/service/gemdale_jenkins/sourcecode/sourcecode.sh

#!/bin/bash
set -e #有报错直接退出
######## define variables -- start ########
# current shell script file's directory
workdir=$(dirname $(readlink -f $0)) #当前文件所在的目录
######## define variables -- end ########
# arg
dr=${dr:-deploy}  #-deploy等于jenkins设置默认变量deploy
# comm_var
shell=$workdir/default/sourcecode-$dr.sh  #设置一个变量
# exec
#执行变量脚本/data/var/www/service/gemdale_jenkins/default/sourcecode-$dr.sh
source $shell     

source sourcecodedeploy.sh

#!/bin/bash

echo 'renew my_tgt:'
rm -rf my_tgt
mkdir my_tgt

######## define variables -- start ########
keep=20
######## define variables -- end ########

# comm
#可无权限执行脚本/data/var/www/service/gemdale_jenkins/default/sourcecode-comm.sh
source $workdir/default/sourcecode-comm.sh

# build_env
service_ws=$WORKSPACE
service_tgt_path=$service_ws

echo 'compress service:'
cd $service_tgt_path
tgz_file=$service-${BUILD_ID}.tar.gz
tgz_file_path=$WORKSPACE/my_tgt/$tgz_file
tar --exclude=my_tgt -czf $tgz_file_path .

# run
dest_tgz_file_path=$dest_d_dir/$service/$tgz_file
dest_d_path=$dest_d_dir/$service/$service-$BUILD_ID

source $workdir/default/sourcecode-run.sh

echo "on destination server: delete old tgz files and service directories, to keep last $keep services. -- start"
del_files=''
for ((i=$keep; i < $(($keep + 100)); i++)); do
  if (($BUILD_ID - $i <= 0)); then
    break;
  fi
  del_files="$del_files $service-$(($BUILD_ID - $i)) $service-$(($BUILD_ID - $i)).tar.gz"
done

docker exec ansible ansible $rs -m shell -a "cd $dest_d_dir/$service &amp;&amp; rm -rf $del_files"
echo "on destination server: delete old tgz files and service directories, to keep last $keep services. -- end"

source sourcecodecomm.sh

#!/bin/bash

# comm_var
dest_dir=/data/var/www/service
dest_d_dir=/data/var/www/service.d
dest_path=$dest_dir/$service

# env_service_var
case $env in
  test | uat )
    case $service in
      patternx-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215,10.0.103.245,10.0.103.247,10.0.103.249}
        ;;
      carpark-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215}
        ;;
      gdimg-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215}
        ;;
      gdnb-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215}
        ;;
      gdr-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215}
        ;;
      gdyk-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215}
        ;;
      gemdale_charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215,10.0.103.245,10.0.103.247,10.0.103.249}
        ;;
      gemdale_jenkins )
        rs=${rs:-10.0.103.245,10.0.103.247,10.0.103.249}
        ;;
      gemdale-playbook )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215,10.36.21.224}
        echo ${rs}
        ;;
      pmc-charts )
        rs=${rs:-10.0.103.211,10.0.103.213,10.0.103.215,10.0.103.245,10.0.103.247,10.0.103.249}
        ;;
    esac
    ;;
  prod )
    case $service in
      patternx-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      ats-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      carpark-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      gdimg-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      gdnb-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      gdr-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      gdyk-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216}
        ;;
      gemdale_charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216,10.0.103.246,10.0.103.250}
        ;;
      gemdale_jenkins )
        rs=${rs:-10.0.103.246,10.0.103.250}
        ;;
      gemdale-playbook )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216,10.36.14.174}
        ;;
      pmc-charts )
        rs=${rs:-10.0.103.212,10.0.103.214,10.0.103.216,10.0.103.246,10.0.103.250}
        ;;
    esac
    ;;
esac

source sourcecode-run.sh

#!/bin/bash

echo 'on destination server, create directories:'
docker exec ansible ansible $rs -m file -a "path=$dest_dir state=directory"
docker exec ansible ansible $rs -m file -a "path=$dest_d_path state=directory"

echo 'scp tgz file to destination server:'
docker exec ansible ansible $rs -m copy -a "src=$tgz_file_path dest=$dest_d_dir/$service/"

echo 'on destination server, decompress tgz file:'
docker exec ansible ansible $rs -m shell -a "tar -xzf $dest_tgz_file_path -C $dest_d_path/"

echo 'on destination server, link to dest_path:'
docker exec ansible ansible $rs -m shell -a "ln -snf $dest_d_path $dest_path"

原文地址:https://blog.csdn.net/jialiu111111/article/details/134788803

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_41842.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注