runc 源码编译(基于 ubuntu 18.04)

一、基础环境

  • Ubuntu 18.06
  • go 1.12.5

二、编译步骤

# apt install pkg-config libseccomp-dev -y
# git clone https://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc"
# cd "$GOPATH/src/github.com/opencontainers/runc"
# git checkout 69663f0b
# make BUILDTAGS="seccomp apparmor selinux" static

编译好的二进制文件就位于 $GOPATH/src/github.com/opencontainers/runc/runc

三、关于 dirty 脏版本的处理

如果你对代码进行了修改,默认编译出的 runc 会被标记为 dirty,类似于:

# ./runc --version
runc version 1.0.0-rc5+dev
commit: 69663f0bd4b60df09991c08812a60108003fa340-dirty
spec: 1.0.0

要去掉这个烦人的 dirty 标记,需要修改 Makefile,去掉那个 -dirty

--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ RUNC_IMAGE := runc_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
 PROJECT := github.com/opencontainers/runc
 BUILDTAGS := seccomp
 COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
-COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")
+COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}","${COMMIT_NO}")

是不是豁然开朗了呢?

# ./runc --version
runc version 1.0.0-rc5+dev
commit: 69663f0bd4b60df09991c08812a60108003fa340
spec: 1.0.0

发布了272 篇原创文章 · 获赞 93 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/shida_csdn/article/details/100105656