"No such file or directory" 安装 OCI CLI 客户端时

"No such file or directory" when installing OCI CLI client

我们正在使用 Docker 文件将 OCI CLI 客户端 (v 2.6.8) 安装到 Docker 映像中。

命令是:

curl -L -o /tmp/install.sh https://raw.githubusercontent.com/oracle/oci-cli/2.6.8/scripts/install/install.sh
RUN chmod +x /tmp/install.sh
RUN /tmp/install.sh --accept-all-defaults

奇怪的是,它在开始失败之前工作了一段时间。

失败并出现以下错误:

IOError: [Errno 2] No such file or directory: '/root/lib/oracle-cli/bin/bmcs'

之前有一个很长的输出,为简洁起见我将其截断:

13:11:02  [INFO] Downloading Oracle Cloud Infrastructure CLI install script from https://raw.githubusercontent.com/oracle/oci-cli/v2.5.15/scripts/install/install.py to /tmp/oci_cli_install_tmp_n1q6.
...
13:11:02  [INFO] Python3 not found on system PATH
13:11:02  [INFO] Running install script.
13:11:02  [INFO] python /tmp/oci_cli_install_tmp_n1q6  --accept-all-defaults
13:11:05  [INFO] Already using interpreter /usr/bin/python
13:11:05  [INFO] New python executable in /root/lib/oracle-cli/bin/python.   
13:11:05  [INFO] Installing setuptools, pip, wheel...
....
13:11:21  [INFO] Installing collected packages: idna, PyYAML, six, python-dateutil, configparser, enum34, pycparser, cffi, asn1crypto, ipaddress, cryptography, pyOpenSSL, pytz, certifi, oci, arrow, jmespath, terminaltables, click, retrying, oci-cli
13:11:28  [INFO] Successfully installed PyYAML-5.1.2 arrow-0.10.0 asn1crypto-1.2.0 certifi-2019.9.11 cffi-1.13.2 click-6.7 configparser-3.5.0 cryptography-2.4.2 enum34-1.1.6 idna-2.6 ipaddress-1.0.23 jmespath-0.9.3 oci-2.6.5 oci-cli-2.6.13 pyOpenSSL-18.0.0 pycparser-2.19 python-dateutil-2.7.3 pytz-2016.10 retrying-1.3.3 six-1.11.0 terminaltables-3.1.0
13:11:28  [INFO] -- Verifying Python version.
13:11:28  [INFO] -- Python version 2.7.5 okay.
13:11:28  [INFO] -- Creating directory '/root/lib/oracle-cli'.
13:11:28  [INFO] -- We will install at '/root/lib/oracle-cli'.
13:11:28  [INFO] -- Creating directory '/root/bin'.
13:11:28  [INFO] -- The executable will be in '/root/bin'.
13:11:28  [INFO] -- Creating directory '/root/bin/oci-cli-scripts'.
13:11:28  [INFO] -- The scripts will be in '/root/bin/oci-cli-scripts'.
13:11:28  [INFO] -- The optional packages installed will be ''.
13:11:28  [INFO] -- Downloading virtualenv package from https://github.com/pypa/virtualenv/archive/15.0.0.tar.gz.
13:11:28  [INFO] -- Downloaded virtualenv package to /tmp/tmpAuc0vV/15.0.0.tar.gz.
13:11:28  [INFO] -- Checksum of /tmp/tmpAuc0vV/15.0.0.tar.gz OK.
13:11:28  [INFO] -- Extracting '/tmp/tmpAuc0vV/15.0.0.tar.gz' to '/tmp/tmpAuc0vV'.
13:11:28  [INFO] -- Executing: ['/usr/bin/python', 'virtualenv.py', '--python', '/usr/bin/python', '/root/lib/oracle-cli']
13:11:28  [INFO] -- Executing: ['/root/lib/oracle-cli/bin/pip', 'install', '--cache-dir', '/tmp/tmpAuc0vV', 'oci_cli', '--upgrade']
13:11:28  [INFO] Traceback (most recent call last):
13:11:28  [INFO]   File "/tmp/oci_cli_install_tmp_n1q6", line 661, in <module>
13:11:28  [INFO]     main()
13:11:28  [INFO]   File "/tmp/oci_cli_install_tmp_n1q6", line 631, in main
13:11:28  [INFO]     shutil.copyfile(os.path.join(install_dir, 'bin', BMCS_EXECUTABLE_NAME), bmcs_exec_path)
13:11:28  [INFO]   File "/usr/lib64/python2.7/shutil.py", line 82, in copyfile
13:11:28  [INFO] 
13:11:28  [INFO]     with open(src, 'rb') as fsrc:
13:11:28  [INFO] IOError: [Errno 2] No such file or directory: '/root/lib/oracle-cli/bin/bmcs'

安装脚本尽管是特定版本,但会下载最新版本的 python wheel。

这在日志中可见如下:

13:33:17  [INFO] Collecting oci_cli
13:33:17  [INFO]   Downloading https://files.pythonhosted.org/packages/48/fb/eb97ba8f01fda78131513d0126985d6e6c482fac753b80e85a2bb01e3842/oci_cli-2.6.13-py2.py3-none-any.whl (5.8MB)

(安装脚本版本 = 2.6.8,已下载 python 工件版本 2.6.13)。

所以它停止工作的原因是 python 车轮以向后不兼容的方式进行了更改。

解决方法是在安装脚本的运行命令中指定版本:

RUN /tmp/install.sh --accept-all-defaults --oci-cli-version 2.6.8