Gitlab-ci: 无法读取文件deb: deb文件中的tar压缩格式不受支持

120次阅读
没有评论

问题描述

在学习GitLab CI并尝试在远程服务器上推送他的deb软件包时遇到了问题。当他在Ubuntu/Debian的Docker容器中手动运行在gitlab-ci.yml中提到的各个命令时,他可以成功将deb软件包推送到远程服务器。但是在GitLab CI中运行时,却遇到了以下错误:

Loading packages...
[!] Unable to read file release-1.0.25.deb: unsupported tar compression in release-1.0.25.deb: control.tar.zst
ERROR: some files failed to be added[!] Some files were skipped due to errors:  release-1.0.25.deb
ECHO sudo aptly snapshot create release-1.0.25-unstable_2022.12.13-05.56.24 from repo unstable
Snapshot release-1.0.25-unstable_2022.12.13-05.56.24 successfully created.
You can run 'aptly publish snapshot release-1.0.25-unstable_2022.12.13-05.56.24' to publish snapshot as Debian repository.
ECHO sudo aptly publish -passphrase=abc switch xenial release-1.0.25-unstable_2022.12.13-05.56.24
Loading packages...
Generating metadata files and linking package files...
Finalizing metadata files...
Signing file 'Release' with gpg, please enter your passphrase when prompted:
gpg: cannot open tty '/dev/tty': No such device or address
ERROR: unable to publish: unable to detached sign file: exit status 2
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

以下是gitlab-ci.yml中负责将代码推送到远程服务器的部分:

publish to remote:
  stage: publish-to-remote
  image: debian:latest
  before_script:
    - apt-get update
    - apt-get install sshpass -y
    - apt-get install aptly -y
    - apt-get install sudo -y
  script:
    - sshpass -p abc ssh -oStrictHostKeyChecking=no abc@something.com mkdir -p /home/
    - md5sum build/$DebFileName.deb
    - sshpass -p abc scp -oStrictHostKeyChecking=no build/$DebFileName.deb abc@something.com:/home/
    - chmod +x ./publishToRemote.sh
    - ./publishToRemote.sh

用户在publishToRemote.sh脚本中做了一些操作。他注意到当他手动在Mac上解压deb文件时,一切正常。但当他尝试在远程服务器上解压时,却出现了相同的问题。他还检查了在scp之前和之后的deb文件的md5sum,发现它们是相同的,所以deb文件的完整性没有问题。

解决方案

请注意以下操作可能涉及版本差异及修改前务必备份。

方案1

问题出现在对tar压缩格式的支持上,特别是在control.tar.zst格式上。要解决这个问题,需要在GitLab CI中对压缩格式进行一些调整。

在GitLab CI中,你可以在发布前对deb软件包进行解压缩,然后再推送。这样可以避免对control.tar.zst格式的依赖。以下是更新后的publishToRemote.sh脚本的示例:

#!/bin/bash
echo "making time"
file_name=release-1.0.25
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
sshpass -p abc ssh -t -oStrictHostKeyChecking=no abc@something.com 'echo "doing cd"cd /home/echo "ECHO sudo aptly repo add unstable '$file_name'.deb"sudo aptly repo add unstable '$file_name'.debecho "ECHO sudo aptly snapshot create '$file_name'-unstable_'$current_time' from repo unstable"sudo aptly snapshot create '$file_name'-unstable_'$current_time' from repo unstableecho "ECHO sudo aptly publish -passphrase=abc switch xenial '$file_name'-unstable_'$current_time'"sudo aptly admin -passphrase=abc switch xenial '$file_name'-unstable_'$current_time'

在这个更新的脚本中,我们去掉了文件扩展名的.deb,因为在解压缩后的文件中不再包含扩展名。这样,在GitLab CI中就不会再受control.tar.zst格式的限制。

方案2

另一种方法是尝试在GitLab CI的Docker容器中安装支持control.tar.zst格式的tar工具。这种方法可能会更加便捷,但需要确认对应的tar工具是否兼容。以下是示例步骤:

  1. 在GitLab CI的Docker容器中添加对tar工具的安装,确保支持control.tar.zst格式。可以在before_script中添加以下命令:
before_script:
  - apt-get update
  - apt-get install tar -y
  1. 更新publishToRemote.sh脚本,确保在推送deb文件之前先解压缩。示例如下:
#!/bin/bash
echo "making time"
file_name=release-1.0.25
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
sshpass -p abc ssh -t -oStrictHostKeyChecking=no abc@something.com 'echo "doing cd"cd /home/
echo "Extracting '$file_name'.deb"tar xf '$file_name'.deb
echo "ECHO sudo aptly repo add unstable '$file_name'"sudo aptly repo add unstable '$file_name'
echo "ECHO sudo aptly snapshot create '$file_name'-unstable_'$current_time' from repo unstable"sudo aptly snapshot create '$file_name'-unstable_'$current_time' from repo unstable
echo "ECHO sudo aptly publish -passphrase=abc switch xenial '$file_name'-unstable_'$current_time'"sudo aptly admin -passphrase=abc switch xenial '$file_name'-unstable_'$current_time'

在这个更新的脚本中,我们在推送deb文件

正文完