ubuntu 下 docker 中部署 jenkins,并配置安卓 python 开发环境

1、ubuntu中下载Android Sdk

# 安装 unzip 工具
sudo apt update
sudo apt install unzip

# 下载 Android SDK
wget https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip

# 解压
unzip commandlinetools-linux-7302050_latest.zip -d android-sdk

# 移动到合适的目录
sudo mv android-sdk /data/dev/

# 设置环境变量
export ANDROID_HOME=/data/dev/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools/bin

 

2、ubuntu中安装docker

卸载docker

sudo systemctl stop docker
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo groupdel docker
sudo apt-get autoremove

安装docker

wget -qO- https://get.docker.com/ | sh
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version sudo usermod -aG docker $USER sudo service docker start sudo systemctl daemon-reload sudo systemctl restart docker

 

查看磁盘占用空间大小

sudo df -hl

sudo du -ahx --max-depth=1

 

3、启动docker jenkins

创建jenkins文件夹

mkdir jenkins
cd jenkins

vim docker-compose.yml 

version: "3.7"
services: # 集合
  jenkins:
    user: root # 为了避免一些权限问题 在这我使用了root
    restart: always # 重启方式
    image: jenkins/jenkins:lts # 指定服务所使用的镜像 在这里我选择了 LTS (长期支持)
    container_name: jenkins # 容器名称
    ports: # 对外暴露的端口定义
      - "8081:8080" # 访问Jenkins服务端口
    environment:
      TZ: Asia/Shanghai
    volumes: # 卷挂载路径
      - jenkins/jenkins_home:/var/jenkins_home
      - /data/dev:/data/dev # android/java开发环境目录
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker # 这是为了我们可以在容器内使用docker命令
      - /usr/local/bin/docker-compose:/usr/local/bin/docker-compose

 qw 保存后,执行命令启动 jenkins

sudo docker-compose up -d

 

4、进入docker 中的 jenkins,配置python环境

docker exec -it -uroot  jenkins  bash
apt-get update
apt-get install wget

apt install python3
apt install python3-pip


# 或者

cd /var/jenkins_home/
mkdir python3
cd python3/

#下载python3安装包
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
tar -xvf Python-3.7.6.tgz 
cd Python-3.7.6

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

#安装缺少的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

#python3.7以上版本在make install缺少—ctype依赖包
apt-get update
apt-get -y install build-essential python-dev python-setuptools python-pip python-smbus
apt-get -y install build-essential libncursesw5-dev libgdbm-dev libc6-dev
apt-get -y  install zlib1g-dev libsqlite3-dev tk-dev
apt-get -y install libssl-dev openssl
apt-get -y install libffi-dev
apt-get -y install libxpm-dev libxext-dev 
apt-get -y install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev

#make编译安装
./configure --prefix=/var/jenkins_home/python3 --with-ssl
make
make install

#设置软连接
ln -sf /var/jenkins_home/python3/bin/python3.7 /usr/bin/python3
ln -sf /var/jenkins_home/python3/bin/pip3  /usr/bin/pip3
python3 --version
pip3 --version

#若权限不足, 为容器用户设置权限, 路径为挂载路径
chmod -R 1000 /root/jenkins_home

 

5、打开jenkins,创建编译任务

5.1 获取 admin 密码

# 在ubuntu中获取密码
cat jenkins/jenkins_home/secret.key

# 通过docker log 来看,过滤 /var/jenkins_home/secrets/initialAdminPassword ,上一行就是
sudo docker logs jenkins

# 在docker jenkins中获取密码
docker exec -it jenkins bash #docker exec -it -uroot jenkins bash cat /var/jenkins_home/secrets/initialAdminPassword

5.2 在浏览器中打开 http://localhost:8081/ 并输入5.1中拿到的密码

5.3 配置安卓环境变量 http://localhost:8081/manage/configure

 

ANDROID_HOME
/data/dev/android-sdk

FLUTTER_PATH
/data/dev/flutter/bin


ANDROID_PATH
$ANDROID_HOME/build-tools/34.0.0:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin

PATH
$PATH:$ANDROID_PATH:$FLUTTER_PATH:

5.4创建jenkins编译任务

可以在下面的目录中看到所有的任务

 jenkins/jenkins_home/workspace/

 

参考文档:

https://zhuanlan.zhihu.com/p/635528937

 

posted @ 2023-12-11 18:36  狐狸已化妖  阅读(155)  评论(0编辑  收藏  举报