From 6d319473dfdcfbebc2aef3c39e8db299f95cb903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E9=A6=99ROS?= <87068644+fishros@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:42:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85Doc?= =?UTF-8?q?ker=E4=BB=8E=E6=B8=85=E5=8D=8E=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/tool_install_docker.py | 63 +++++++++++++++--------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/tools/tool_install_docker.py b/tools/tool_install_docker.py index a3333d7..9182d84 100644 --- a/tools/tool_install_docker.py +++ b/tools/tool_install_docker.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from .base import BaseTool -from .base import PrintUtils,CmdTask,FileUtils,AptUtils,ChooseTask -from .base import osversion,osarch +from .base import PrintUtils, CmdTask, FileUtils, AptUtils, ChooseTask +from .base import osversion, osarch from .base import run_tool_file class Tool(BaseTool): @@ -12,54 +12,43 @@ def __init__(self): def install_docker(self): """ - $ curl -fsSL https://get.docker.com -o get-docker.sh - $ sudo sh get-docker.sh - + Executing Docker install script with updated commands for new installation steps. """ PrintUtils.print_info("开始根据系统架构,为你下载对应版本的docker~") - # 更换系统源 - # dic = {1:"更换系统源再继续安装",2:"不更换继续安装"} - # code,result = ChooseTask(dic, "如果您是第一次安装,推荐您先更换一下系统源").run() - # if code==1: - # run_tool_file('tools.tool_config_system_source') - - # check apt - if not AptUtils.checkapt(): return False + # Check if apt is available + if not AptUtils.checkapt(): + return False - #pre-install - CmdTask('sudo apt install apt-transport-https ca-certificates curl software-properties-common -y',120).run() + # Pre-installation steps + CmdTask('apt-get update', 120, os_command=True).run() + CmdTask('DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl ', 120, os_command=True).run() + CmdTask('install -m 0755 -d /etc/apt/keyrings', 10, os_command=True).run() - #add key - CmdTask('curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -',10).run() - #verify key - CmdTask('sudo apt-key fingerprint 0EBFCD88',10).run() - if osarch=="bullseye": - CmdTask("curl -fsSL https://get.docker.com -o get-docker.sh").run() - CmdTask("sudo sh get-docker.sh").run() - PrintUtils.print_info("安装完成,接下来你可以尝试使用docker --version指令测试是有正常回显~") - return + # Add Docker GPG key + CmdTask('curl -fsSL "https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg" -o /etc/apt/keyrings/docker.asc', 10, os_command=True).run() + CmdTask('chmod a+r /etc/apt/keyrings/docker.asc', 10,os_command=True).run() - # 根据系统架构下载不同版本的安装包 - if osarch=='amd64': - CmdTask('sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -y',os_command=True).run() - elif osarch=='arm64': - CmdTask('sudo add-apt-repository "deb [arch=arm64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -y',os_command=True).run() + # Add Docker repository + if osarch == 'amd64': + CmdTask('echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list', os_command=True).run() + elif osarch == 'arm64': + CmdTask('echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list', os_command=True).run() else: return False + + # Update apt index and install Docker PrintUtils.print_info("下载完成,接下来升级apt索引~") - CmdTask("sudo apt update").run() + CmdTask('apt-get update ', 10,os_command=True).run() PrintUtils.print_info("开始安装最新版本docker CE~") - CmdTask("sudo apt --fix-broken install -y").run() - # CmdTask("sudo apt install docker-ce -y").run() - AptUtils.install_pkg_check_dep("docker-ce") - CmdTask("sudo groupadd docker").run() + CmdTask('DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin', 120,os_command=True).run() + + # Post-installation steps + CmdTask('sudo groupadd docker', 10,os_command=True).run() user = FileUtils.getusers()[0] - CmdTask("sudo gpasswd -a {} docker".format(user)).run() - # CmdTask("newgrp docker",os_command=True).run() + CmdTask('sudo gpasswd -a {} docker'.format(user), 10,os_command=True).run() PrintUtils.print_info("安装完成,接下来你可以尝试使用docker --version指令测试是有正常回显~") def run(self): self.install_docker() -