第2集(GItlab+Jenkins+SonarQube+Docker+Harbor+Selenium实现CI/CD之LNMP项目准备)

网友投稿 883 2022-11-23

第2集(GItlab+Jenkins+SonarQube+Docker+Harbor+Selenium实现CI/CD之LNMP项目准备)

第2集(GItlab+Jenkins+SonarQube+Docker+Harbor+Selenium实现CI/CD之LNMP项目准备)

​​第1集,环境搭建​​

​​第3集,WebHook触发mvn打包​​

​​第4集,SonarQube实现CodeReview​​

​​第5集,build image​​

​​第6集,部署到测试环境,Selenium自动测试​​

​​第7集,模拟版本更新,在测试环境验证​​

​​第8集,部署到生产环境​​

​​第9集,流水线部署到测试环境​​

一、在gitlab上创建项目dev_lnmp

​​1.创建项目​​

​​2.在jenkins机器上克隆该项目​​

sudo -iyum -y install gitgit config --global user.name "root"git config --global user.email "anqixiang@163.com"git clone 提取码:cumy

nginx-php-fpm镜像-:

链接:提取码:at3j

docker pull mysqldocker pull richarvey/nginx-php-fpm:latestdocker images

​​2.在dev_lnmp下创建目录,目录结构如下​​

​​3.docker-compose-module.yml内容:​​

version: '3.7'services: mysql: image: 172.16.38.202:8010/library/mysql:8.0.18 container_name: lnmp_mysql hostname: lnmp_mysql restart: always command: - --default-authentication-plugin=mysql_native_password - --character-set-server=utf8 environment: MYSQL_ROOT_PASSWORD: 123456 ports: - 3306:3306 volumes: - /data/docker_volume/mysql/mysql_data:/var/lib/mysql networks: - lnmp security_opt: - seccomp:unconfined lnmp_web: image: #tag#richarvey/nginx-php-fpm:latest container_name: lnmp_web hostname: lnmp_web restart: always depends_on: - mysql ports: - 80:80 - 443:443 networks: - lnmpnetworks: lnmp: name: lnmp_network driver: bridge

​​4.构建代码镜像的材料(以搭建wordpress为例)​​

Dockerfile内容:

FROM richarvey/nginx-php-fpmMAINTAINER nsd_anqixiang@163.com#用于版本控制ENV WORDPRESS_VERSION 4.9COPY index.html /var/wordpress-${WORDPRESS_VERSION}-zh_CN.tar.gz /var/+ecurrent_dir=$(cd `dirname $0` && pwd) #当前工作目录#Harbor仓库信息harbor_ip=172.16.38.202harbor_port=8010harbor_user=adminharbor_pwd=adminharbor_project=lnmpset -edocker login -u admin -p admin#构建镜像Build_Image(){ image_name=nginx-php-fpm image_tag=ver1.0_$(date "+%Y%m%d") image_path=${harbor_ip}:${harbor_port}/${harbor_project}/${image_name}:${image_tag} cd ${current_dir}/dockerfiles/nginx/ docker build -t ${image_path} . docker push ${image_path}}#更改docker-compose.yml文件Update_Compose(){ compose_module_file=${current_dir}/docker-compose-module.yml compose_file=${current_dir}/docker-compose.yml \cp ${compose_module_file} ${compose_file} #local base_tag=$1 #jenkins传进来的参数 new_tag=${image_path} base_tag=$(sed -n '/#tag#/p' ${compose_file} |awk -F'#' '{print $3}') #提取docker-compose.yml的镜像tag sed -ri "/#tag#/ s@^(.*)(#tag#)(.*)@\1${new_tag}@" ${compose_file} #替换为新的tag}######################主函数######################Build_ImageUpdate_Composeset +e

​​7.将整个项目上传到gitlab​​

cd dev_lnmpsudo git add .git commit -m "add c1"git push

三、Harbor创建项目

四、将公共镜像如mysql镜像上传到library项目(Jenkins机器操作)

​​1.配置docker信任仓库​​

sudo vim /etc/docker/daemon.json

"insecure-registries": ["172.16.38.202:8010"]

sudo systemctl restart docker

​​2.打标签​​

docker tag mysql:8.0.18 172.16.38.202:8010/library/mysql:8.0.18

​​3.上传镜像​​

docker login -u admin -p admindocker push 172.16.38.202:8010/library/mysql:8.0.18

​​4.仓库查看​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot过滤器的使用
下一篇:第3集(GItlab+Jenkins+SonarQube+Docker+Harbor+Selenium实现CI/CD之WebHook触发mvn打包)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~