docker安装jenkins 容器,集成python环境

1.docker安装

# centos7 安装docker
1 安装依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
2 设置docker yum源为阿里云
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  
3 安装
sudo yum install docker-ce -y
4.配置阿里云加速器cd /etc/docker
daemon.json 文件
vim daemon.json
加入阿里云加速器地址 72idtxd8随便填
{ "registry-mirrors": ["https://72idtxd8.mirror.aliyuncs.com"] }
保存后,重启docker拉取镜像的速度嘎嘎的

2.安装jenkins

docker pull jenkins/jenkins:lts  # 拉取镜像
docker image ls -a    # 查看所有镜像
docker image  inspect  镜像id  # 查看jenkins的详细信息及版本
mkdir /home/jenkins_home  # 创建一个jenkins映射目录
docker run -itd --name=jenkins_01 -p 9090:8080 -v /home/jenkins_01:/home/jenkins_01 jenkins/jenkins:lts
解释: i 运行容器 it 运行容器 并进入容器执行命令 itd 不会进入容器 --name 给容器起名字 -v 映射目录

 进入容器

docker exec -it jenkins_01 bin/bash
cat /var/jenkins_home/secrets/initialAdminPassword

选择安装推荐的插件

 设置账户密码 安装完成

重启:http://你的ip地址:9090/restart

安装python3 环境

1.官网下载安装包
https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz Python
-3.6.5_.tgz
2. copy 到容器中 或者进入容使用wget下载 在使用容器中使用wget下载比较慢时
docker cp Python-3.6.5_.tgz jenkins_01:/var/jenkins_home/python3

进入容器

docker exec -it -u root 容器id /bin/bash  #进入容器

换源阿里

查看系统,

cat /etc/issue

此时系统默认是debian 9系统,这里yum是没有的,所以不能用yum安装了,这里用apt-get代替yum,

root@cb8e397d5308:/# uname -a
Linux cb8e397d5308 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 GNU/Linux
root@cb8e397d5308:/# cat /etc/issue
Debian GNU/Linux 9 
 l

Debian安装软件巨慢,换Debian源为阿里源

注意:  换源要对应strech

5是Debian      6是squeeze
7是wheezy      8是jessie
9是stretch
cat /etc/apt/sources.list

内容改为

deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib

更新apt-get

apt-get update

 jenkins 容器内安装python

cd /var/jenkins_home/
mkdir python3
cd python3/
docker cp Python-3.6.5_.tgz jenkins_01:/var/jenkins_home/python3 # 从宿主机中copy到容器中
tar -xvf Python-3.6.5.tgz
cd Python-3.6.5
./configure --prefix=/var/jenkins_home/python3

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/var/jenkins_home/python3/Python-3.6.8':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

安装gcc相关依赖

apt-get -y install gcc automake autoconf libtool make
apt-get -y install make*
apt-get -y install zlib*
apt-get -y install openssl libssl-dev
apt-get install sudo

make编译安装

在/var/jenkins_home/python3/Python-3.6.8目录执行make和make install 安装

./configure --prefix=/var/jenkins_home/python3 --with-ssl
make
make install

添加软连接

添加python3软链接

ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3

添加pip3软链接

ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3

检查环境

输入pip3 和python3检查环境

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# pip3

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3
Python 3.6.8 (default, Jan  1 2020, 10:15:14) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

使用pip3安装一个requests包

pip3 install requests

pip 换源     

 vim  /etc/pip.conf  # 没有就新建

修改内容为:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 

这时候pip3 install requests 会很快

 

 

ssl问题

如果pip3安装的时候遇到报ssl相关问题:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

这个是因为缺少ssl依赖包,网上的解决方案是yum install openssl-devel ,由于Debian系统没有yum,用apt-get安装

apt-get -y install openssl libssl-dev

安装完成之后只能解决系统自带的python2对应的pip安装问题,无法解决python3的pip3安装问题。

解决办法:上面编译的时候需加上参数 --with-ssl

./configure --prefix=/var/jenkins_home/python3 --with-ssl

重新执行make和make install 就可以了

也可以在python环境检查是否能导入ssl

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3
Python 3.6.8 (default, Jan  1 2020, 10:15:14) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl

git 拉取gitee 源码 并构建

1.创建项目

 2.拉取git代码   ssh  或 https

ssh: 方式1: 使用私钥

 

ssh 方式二: 使用账号密码

 https: 

构建shell   :

补充解释:jenkins的工作目录: 

 

 进入容器:/var/jenkins_home/workspace/get_01

ls 查看,文件已上传到jenkins的workspace目录

原文地址:https://www.cnblogs.com/bigbox/p/13057648.html