我正在学习 GitLab CI/CD 并部署了一个用于我的管道的 Kubernetes 运行器。
在第一阶段,我为 Ubuntu 构建了 iperf3 的 .deb 包,然后将其复制为工件并在测试阶段安装。
但是,安装软件包后,找不到 iperf3 二进制文件。我已在 Docker 中手动复制了这些步骤,并且 .deb 包似乎有效并且在其他环境中运行良好。我不明白为什么二进制文件在 CI 测试管道中消失了。
我什至尝试在测试阶段解压 .deb 包和 data.tar.xz 文件,该文件确实包含二进制文件,尽管它看起来是空的或不完整的。我以前从未在其他地方见过这种行为。
.gitlab-ci.yml CICD 代码
stages:
- build
- test
build_job:
stage: build
image: ubuntu:20.04
script:
- echo "Initiating build stage on $(date)"
- apt update && apt install -y build-essential wget
- wget -P tmp/ https://downloads.es.net/pub/iperf/iperf-3.9.tar.gz
- tar -xvf tmp/iperf-3.9.tar.gz -C tmp/
- mkdir build pkg
- tmp/iperf-3.9/configure --prefix=/build
- make && make install
- mkdir build/DEBIAN
- |
echo "Package: iperf3
Version: 3.9-1
Section: utils
Priority: optional
Architecture: all
Maintainer: LMAO <[email protected]>
Description: iperf 3.9 test build" > build/DEBIAN/control
- dpkg-deb --root-owner-group --build build/ pkg/iperf-3.9-focal.deb
- echo "Build completed on $(date)"
tags:
- k3s-focal
artifacts:
paths:
- pkg/iperf-3.9-focal.deb
test_job:
stage: test
image: ubuntu:20.04
script:
- echo "Initiating test stage."
- apt update && apt install -y binutils file xz-utils
- file pkg/iperf-3.9-focal.deb
- ar x pkg/iperf-3.9-focal.deb --output=/tmp
- ls /tmp
- tar -xvf /tmp/data.tar.xz -C /tmp/
- ls -l /tmp/
- /tmp/bin/iperf3 -v
- find / -name iperf3 2>/dev/null
- echo "Test completed successfully."
tags:
- k3s-focal
测试管道的输出
Running with gitlab-runner 17.4.0 (b92ee590)
on gitlab-runner-7bc46d4c54-vzxfc dAHtD6P57, system ID: r_funnNswqJhFr
Preparing the "kubernetes" executor
00:00
Using Kubernetes namespace: gitlab-runner
Using Kubernetes executor with image ubuntu:20.04 ...
Using attach strategy to execute scripts...
Preparing environment
00:06
Using FF_USE_POD_ACTIVE_DEADLINE_SECONDS, the Pod activeDeadlineSeconds will be set to the job timeout: 1h0m0s...
Waiting for pod gitlab-runner/runner-dahtd6p57-project-61903025-concurrent-0-iccn3kfn to be running, status is Pending
Waiting for pod gitlab-runner/runner-dahtd6p57-project-61903025-concurrent-0-iccn3kfn to be running, status is Pending
ContainersNotInitialized: "containers with incomplete status: [init-permissions]"
ContainersNotReady: "containers with unready status: [build helper]"
ContainersNotReady: "containers with unready status: [build helper]"
Running on runner-dahtd6p57-project-61903025-concurrent-0-iccn3kfn via gitlab-runner-7bc46d4c54-vzxfc...
Getting source from Git repository
00:02
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/kernel.panic007/deb-pkging/.git/
Created fresh repository.
Checking out 8e4aa37e as detached HEAD (ref is main)...
Skipping Git submodules setup
Downloading artifacts
00:01
Downloading artifacts for build_job (7942463800)...
Downloading artifacts from coordinator... ok host=cdn.artifacts.gitlab-static.net id=7942463800 responseStatus=200 OK token=glcbt-66
Executing "step_script" stage of the job script
00:09
$ echo "Initiating test stage."
Initiating test stage.
$ apt update && apt install -y binutils file xz-utils
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [128 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [128 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [128 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [1273 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.9 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [4036 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [4024 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1560 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [4188 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [4488 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [33.5 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [28.6 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [55.2 kB]
Fetched 33.2 MB in 3s (11.6 MB/s)
Reading package lists...
Building dependency tree...
Reading state information...
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
binutils-common binutils-x86-64-linux-gnu libbinutils libctf-nobfd0 libctf0
libmagic-mgc libmagic1
Suggested packages:
binutils-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu file libbinutils
libctf-nobfd0 libctf0 libmagic-mgc libmagic1 xz-utils
0 upgraded, 10 newly installed, 0 to remove and 2 not upgraded.
Need to get 2795 kB of archives.
After this operation, 20.3 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libmagic-mgc amd64 1:5.38-4 [218 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libmagic1 amd64 1:5.38-4 [75.9 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 file amd64 1:5.38-4 [23.3 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 xz-utils amd64 5.2.4-1ubuntu1.1 [82.6 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 binutils-common amd64 2.34-6ubuntu1.9 [208 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libbinutils amd64 2.34-6ubuntu1.9 [475 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libctf-nobfd0 amd64 2.34-6ubuntu1.9 [48.2 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libctf0 amd64 2.34-6ubuntu1.9 [46.6 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 binutils-x86-64-linux-gnu amd64 2.34-6ubuntu1.9 [1614 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 binutils amd64 2.34-6ubuntu1.9 [3380 B]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 2795 kB in 1s (3020 kB/s)
Selecting previously unselected package libmagic-mgc.
(Reading database ... 4124 files and directories currently installed.)
Preparing to unpack .../0-libmagic-mgc_1%3a5.38-4_amd64.deb ...
Unpacking libmagic-mgc (1:5.38-4) ...
Selecting previously unselected package libmagic1:amd64.
Preparing to unpack .../1-libmagic1_1%3a5.38-4_amd64.deb ...
Unpacking libmagic1:amd64 (1:5.38-4) ...
Selecting previously unselected package file.
Preparing to unpack .../2-file_1%3a5.38-4_amd64.deb ...
Unpacking file (1:5.38-4) ...
Selecting previously unselected package xz-utils.
Preparing to unpack .../3-xz-utils_5.2.4-1ubuntu1.1_amd64.deb ...
Unpacking xz-utils (5.2.4-1ubuntu1.1) ...
Selecting previously unselected package binutils-common:amd64.
Preparing to unpack .../4-binutils-common_2.34-6ubuntu1.9_amd64.deb ...
Unpacking binutils-common:amd64 (2.34-6ubuntu1.9) ...
Selecting previously unselected package libbinutils:amd64.
Preparing to unpack .../5-libbinutils_2.34-6ubuntu1.9_amd64.deb ...
Unpacking libbinutils:amd64 (2.34-6ubuntu1.9) ...
Selecting previously unselected package libctf-nobfd0:amd64.
Preparing to unpack .../6-libctf-nobfd0_2.34-6ubuntu1.9_amd64.deb ...
Unpacking libctf-nobfd0:amd64 (2.34-6ubuntu1.9) ...
Selecting previously unselected package libctf0:amd64.
Preparing to unpack .../7-libctf0_2.34-6ubuntu1.9_amd64.deb ...
Unpacking libctf0:amd64 (2.34-6ubuntu1.9) ...
Selecting previously unselected package binutils-x86-64-linux-gnu.
Preparing to unpack .../8-binutils-x86-64-linux-gnu_2.34-6ubuntu1.9_amd64.deb ...
Unpacking binutils-x86-64-linux-gnu (2.34-6ubuntu1.9) ...
Selecting previously unselected package binutils.
Preparing to unpack .../9-binutils_2.34-6ubuntu1.9_amd64.deb ...
Unpacking binutils (2.34-6ubuntu1.9) ...
Setting up libmagic-mgc (1:5.38-4) ...
Setting up binutils-common:amd64 (2.34-6ubuntu1.9) ...
Setting up libmagic1:amd64 (1:5.38-4) ...
Setting up libctf-nobfd0:amd64 (2.34-6ubuntu1.9) ...
Setting up file (1:5.38-4) ...
Setting up xz-utils (5.2.4-1ubuntu1.1) ...
update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/lzma.1.gz because associated file /usr/share/man/man1/xz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/unlzma.1.gz because associated file /usr/share/man/man1/unxz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcat.1.gz because associated file /usr/share/man/man1/xzcat.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzmore.1.gz because associated file /usr/share/man/man1/xzmore.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzless.1.gz because associated file /usr/share/man/man1/xzless.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzdiff.1.gz because associated file /usr/share/man/man1/xzdiff.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcmp.1.gz because associated file /usr/share/man/man1/xzcmp.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzgrep.1.gz because associated file /usr/share/man/man1/xzgrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzegrep.1.gz because associated file /usr/share/man/man1/xzegrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzfgrep.1.gz because associated file /usr/share/man/man1/xzfgrep.1.gz (of link group lzma) doesn't exist
Setting up libbinutils:amd64 (2.34-6ubuntu1.9) ...
Setting up libctf0:amd64 (2.34-6ubuntu1.9) ...
Setting up binutils-x86-64-linux-gnu (2.34-6ubuntu1.9) ...
Setting up binutils (2.34-6ubuntu1.9) ...
Processing triggers for libc-bin (2.31-0ubuntu9.16) ...
$ file pkg/iperf-3.9-focal.deb
pkg/iperf-3.9-focal.deb: Debian binary package (format 2.0), with control.tar.xz, data compression xz
$ ar x pkg/iperf-3.9-focal.deb --output=/tmp
$ ls /tmp
control.tar.xz
data.tar.xz
debian-binary
$ tar -xvf /tmp/data.tar.xz -C /tmp/
./
$ ls -l /tmp/
total 2
-rw-r--r-- 1 root root 324 Sep 27 20:34 control.tar.xz
-rw-r--r-- 1 root root 172 Sep 27 20:34 data.tar.xz
-rw-r--r-- 1 root root 4 Sep 27 20:34 debian-binary
$ /tmp/bin/iperf3 -v
/scripts-61903025-7942463801/step_script: line 172: /tmp/bin/iperf3: No such file or directory
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1
该问题是 CI 目录 PATH 与 Runner 工作目录相关的结果。就像在 docker 容器中一样,我假设 CI 工作目录是 root,而不是 /builds/USER/PROJECT。现在一切正常。
stages:
- build
- test
build_job:
stage: build
image: ubuntu:20.04
script:
- echo "Initiating build stage on $(date)"
- apt update && apt install -y build-essential wget
- wget -P /tmp https://downloads.es.net/pub/iperf/iperf-3.9.tar.gz
- tar -xvf /tmp/iperf-3.9.tar.gz -C /tmp
- mkdir /build pkg
- /tmp/iperf-3.9/configure --prefix=/build
- make && make install
- mkdir /build/DEBIAN
- |
echo "Package: iperf3
Version: 3.9-1
Section: utils
Priority: optional
Architecture: all
Maintainer: LMAO <[email protected]>
Description: iperf 3.9 test build" > /build/DEBIAN/control
- dpkg-deb --root-owner-group --build /build pkg/iperf-3.9-focal.deb
- echo "Build completed on $(date)"
tags:
- k3s-focal
artifacts:
paths:
- pkg/iperf-3.9-focal.deb
test_job:
stage: test
image: ubuntu:20.04
script:
- echo "Initiating test stage."
- dpkg -i pkg/iperf-3.9-focal.deb
- iperf3 -v
- echo "Test completed successfully."
tags:
- k3s-focal