2023-08-15 17:00:22 +08:00
SHELL = /bin/bash
2019-10-28 13:08:39 +09:00
CONTAINER_ENGINE := docker
2021-05-04 11:59:02 +02:00
GO ?= go
2017-08-14 00:10:28 +10:00
2020-09-08 16:47:19 -07:00
PREFIX ?= /usr/local
2017-04-14 10:15:33 -07:00
BINDIR := $( PREFIX) /sbin
2020-04-27 13:49:39 -07:00
MANDIR := $( PREFIX) /share/man
2016-06-28 15:39:38 -07:00
GIT_BRANCH := $( shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $( shell echo $( GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g" )
RUNC_IMAGE := runc_dev$( if $( GIT_BRANCH_CLEAN) ,:$( GIT_BRANCH_CLEAN) )
2016-04-22 14:37:42 +08:00
PROJECT := github.com/opencontainers/runc
2024-08-15 11:37:59 +02:00
EXTRA_BUILDTAGS :=
BUILDTAGS := seccomp urfave_cli_no_docs
2023-08-15 17:00:22 +08:00
BUILDTAGS += $( EXTRA_BUILDTAGS)
2022-03-31 15:56:14 -07:00
2024-08-15 11:37:59 +02:00
COMMIT := $( shell git describe --dirty --long --always)
2024-08-14 12:46:54 +02:00
EXTRA_VERSION :=
2025-04-08 19:00:59 -07:00
LDFLAGS_COMMON := -X main.gitCommit= $( COMMIT) \
$( if $( strip $( EXTRA_VERSION) ) ,-X main.extraVersion= $( EXTRA_VERSION) ,)
2020-04-20 12:33:58 -07:00
2022-03-31 18:27:40 -07:00
GOARCH := $( shell $( GO) env GOARCH)
2023-06-20 16:41:15 +03:00
# -trimpath may be required on some platforms to create reproducible builds
# on the other hand, it does strip out build information, like -ldflags, which
# some tools use to infer the version, in the absence of go information,
# which happens when you use `go build`.
# This enables someone to override by doing `make runc TRIMPATH= ` etc.
TRIMPATH := -trimpath
Makefile: fix GO_BUILDMODE setting
1. Set to empty value by default.
2. Assume Linux (remove GOOS check, since we do not support other OSes).
3. Instead of using a "not-supported" list, use a "supported" list
(as Go release notes usually say which platforms are supported).
As of today, -buildmode=pie is supported for:
* linux/386, linux/amd64, linux/arm, linux/arm64, and linux/ppc64le
(since Go 1.6, see https://tip.golang.org/doc/go1.6#compiler)
* linux/s390x (since Go 1.7, which adds the initial port)
* linux/riscv64 (since Go 1.16, see
https://tip.golang.org/doc/go1.16#riscv)
NOTE this does not mean we support these architectures; it is merely
a way to see if -buildmode=pie can be used.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-03-31 17:51:11 -07:00
GO_BUILDMODE :=
# Enable dynamic PIE executables on supported platforms.
2025-10-16 09:50:37 +08:00
i f n e q ( , $( filter $ ( GOARCH ) ,386 amd 64 arm arm 64 loong 64 ppc 64le riscv 64 s 390x ) )
Makefile: fix GO_BUILDMODE setting
1. Set to empty value by default.
2. Assume Linux (remove GOOS check, since we do not support other OSes).
3. Instead of using a "not-supported" list, use a "supported" list
(as Go release notes usually say which platforms are supported).
As of today, -buildmode=pie is supported for:
* linux/386, linux/amd64, linux/arm, linux/arm64, and linux/ppc64le
(since Go 1.6, see https://tip.golang.org/doc/go1.6#compiler)
* linux/s390x (since Go 1.7, which adds the initial port)
* linux/riscv64 (since Go 1.16, see
https://tip.golang.org/doc/go1.16#riscv)
NOTE this does not mean we support these architectures; it is merely
a way to see if -buildmode=pie can be used.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-03-31 17:51:11 -07:00
ifeq ( ,$( findstring -race,$( EXTRA_FLAGS) ) )
GO_BUILDMODE := "-buildmode=pie"
2020-05-19 09:44:06 -07:00
endif
e n d i f
2023-06-20 16:41:15 +03:00
GO_BUILD := $( GO) build $( TRIMPATH) $( GO_BUILDMODE) \
2022-03-31 18:27:40 -07:00
$( EXTRA_FLAGS) -tags " $( BUILDTAGS) " \
2022-03-31 15:56:14 -07:00
-ldflags " $( LDFLAGS_COMMON) $( EXTRA_LDFLAGS) "
2022-03-31 18:27:40 -07:00
GO_BUILDMODE_STATIC :=
2022-03-31 15:56:14 -07:00
LDFLAGS_STATIC := -extldflags -static
2022-03-31 18:27:40 -07:00
# Enable static PIE executables on supported platforms.
# This (among the other things) requires libc support (rcrt1.o), which seems
# to be available only for arm64 and amd64 (Debian Bullseye).
i f n e q ( , $( filter $ ( GOARCH ) ,arm 64 amd 64) )
ifeq ( ,$( findstring -race,$( EXTRA_FLAGS) ) )
GO_BUILDMODE_STATIC := -buildmode= pie
2023-02-14 21:27:26 +01:00
LDFLAGS_STATIC := -linkmode external -extldflags -static-pie
2022-03-31 18:27:40 -07:00
endif
e n d i f
# Enable static PIE binaries on supported platforms.
2023-06-20 16:41:15 +03:00
GO_BUILD_STATIC := $( GO) build $( TRIMPATH) $( GO_BUILDMODE_STATIC) \
2022-03-31 18:27:40 -07:00
$( EXTRA_FLAGS) -tags " $( BUILDTAGS) netgo osusergo " \
2022-03-31 15:56:14 -07:00
-ldflags " $( LDFLAGS_COMMON) $( LDFLAGS_STATIC) $( EXTRA_LDFLAGS) "
2016-04-22 14:37:42 +08:00
2021-12-07 18:07:30 +11:00
GPG_KEYID ?= asarai@suse.de
2022-03-31 18:32:36 -07:00
# Some targets need cgo, which is disabled by default when cross compiling.
# Enable cgo explicitly for those.
# Both runc and libcontainer/integration need libcontainer/nsenter.
runc static localunittest : export CGO_ENABLED =1
# seccompagent needs libseccomp (when seccomp build tag is set).
i f n e q ( , $( filter $ ( BUILDTAGS ) ,seccomp ) )
seccompagent : export CGO_ENABLED =1
e n d i f
2016-09-05 22:29:03 +10:00
.DEFAULT : runc
2023-10-05 13:28:53 -07:00
.PHONY : runc
2024-10-28 17:22:19 +08:00
runc : runc -bin
2023-10-05 13:00:49 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : runc -bin
2024-10-28 17:22:19 +08:00
runc-bin :
2020-04-20 12:33:58 -07:00
$( GO_BUILD) -o runc .
2015-06-26 13:06:17 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : all
2024-08-21 18:57:38 -07:00
all : runc memfd -bind
2016-09-05 22:29:03 +10:00
2024-08-16 00:55:48 +09:00
.PHONY : memfd -bind
memfd-bind :
2021-07-28 10:37:29 -07:00
$( GO_BUILD) -o contrib/cmd/$@ /$@ ./contrib/cmd/$@
2016-09-05 22:29:03 +10:00
2024-08-21 18:57:38 -07:00
TESTBINDIR := tests/cmd/_bin
$(TESTBINDIR) :
mkdir $( TESTBINDIR)
2025-03-11 15:50:23 -07:00
TESTBINS := recvtty sd-helper seccompagent fs-idmap pidfd-kill remap-rootfs key_label
2024-08-21 18:57:38 -07:00
.PHONY : test -binaries $( TESTBINS )
test-binaries : $( TESTBINS )
$(TESTBINS) : $( TESTBINDIR )
$( GO_BUILD) -o $( TESTBINDIR) ./tests/cmd/$@
2024-08-16 00:55:48 +09:00
2023-12-13 14:26:42 +00:00
.PHONY : clean
clean :
2024-10-28 17:22:19 +08:00
rm -f runc runc-*
2023-12-13 14:26:42 +00:00
rm -f contrib/cmd/memfd-bind/memfd-bind
2024-08-21 18:57:38 -07:00
rm -fr $( TESTBINDIR)
2023-12-13 14:26:42 +00:00
sudo rm -rf release
rm -rf man/man8
2023-10-05 13:28:53 -07:00
.PHONY : static
2024-10-28 17:22:19 +08:00
static : static -bin
2023-10-05 13:00:49 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : static -bin
2024-10-28 17:22:19 +08:00
static-bin :
2020-04-20 12:33:58 -07:00
$( GO_BUILD_STATIC) -o runc .
2023-08-15 17:00:22 +08:00
2023-10-05 13:28:53 -07:00
.PHONY : releaseall
2023-08-19 12:18:08 +10:00
releaseall : RELEASE_ARGS := "-a 386 -a amd 64 -a arm 64 -a armel -a armhf -a ppc 64le -a riscv 64 -a s 390x "
make release: add cross-build
This implements cross-build for "make release", moving the build into a
container. This way we can support arm, arm64, ppc, and whatnot.
* script/seccomp.sh: separate out of script/release.sh, amend to support
cross-compile and save needed environment variables to a file.
* Dockerfile: add installing libseccomp from source, as this is needed
for release builds.
* script/release.sh: amend to support more architectures in addition to
the native build. Additional arches can be added by specifying
"-a <arch>" argument (can be specified multiple times), or
"make RELEASE_ARGS="-a arm64" release" if called via make.
All supported architectures can be enabled via "make releaseall".
* Makefile: move "release" target to "localrelease", add "release" and
"releaseall" targets to build via the Dockerfile. This is done because
most distros (including Fedora and openSUSE) lack cross-glibc, which is
needed to cross-compile libseccomp.
* Makefile: remove 'cross' and 'localcross' targets, as this is now done
by the release script.
* .github/workflows/validate.yum: amend the release CI job to cross-build
for supported architectures, remove cross job.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-06 11:31:11 -07:00
releaseall : release
2023-10-05 13:28:53 -07:00
.PHONY : release
make release: add cross-build
This implements cross-build for "make release", moving the build into a
container. This way we can support arm, arm64, ppc, and whatnot.
* script/seccomp.sh: separate out of script/release.sh, amend to support
cross-compile and save needed environment variables to a file.
* Dockerfile: add installing libseccomp from source, as this is needed
for release builds.
* script/release.sh: amend to support more architectures in addition to
the native build. Additional arches can be added by specifying
"-a <arch>" argument (can be specified multiple times), or
"make RELEASE_ARGS="-a arm64" release" if called via make.
All supported architectures can be enabled via "make releaseall".
* Makefile: move "release" target to "localrelease", add "release" and
"releaseall" targets to build via the Dockerfile. This is done because
most distros (including Fedora and openSUSE) lack cross-glibc, which is
needed to cross-compile libseccomp.
* Makefile: remove 'cross' and 'localcross' targets, as this is now done
by the release script.
* .github/workflows/validate.yum: amend the release CI job to cross-build
for supported architectures, remove cross job.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-06 11:31:11 -07:00
release : runcimage
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
--rm -v $( CURDIR) :/go/src/$( PROJECT) \
-e RELEASE_ARGS = $( RELEASE_ARGS) \
$( RUNC_IMAGE) make localrelease
2025-04-08 19:00:59 -07:00
script/release_sign.sh -S $( GPG_KEYID)
make release: add cross-build
This implements cross-build for "make release", moving the build into a
container. This way we can support arm, arm64, ppc, and whatnot.
* script/seccomp.sh: separate out of script/release.sh, amend to support
cross-compile and save needed environment variables to a file.
* Dockerfile: add installing libseccomp from source, as this is needed
for release builds.
* script/release.sh: amend to support more architectures in addition to
the native build. Additional arches can be added by specifying
"-a <arch>" argument (can be specified multiple times), or
"make RELEASE_ARGS="-a arm64" release" if called via make.
All supported architectures can be enabled via "make releaseall".
* Makefile: move "release" target to "localrelease", add "release" and
"releaseall" targets to build via the Dockerfile. This is done because
most distros (including Fedora and openSUSE) lack cross-glibc, which is
needed to cross-compile libseccomp.
* Makefile: remove 'cross' and 'localcross' targets, as this is now done
by the release script.
* .github/workflows/validate.yum: amend the release CI job to cross-build
for supported architectures, remove cross job.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-06 11:31:11 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : localrelease
2023-03-29 14:49:12 -07:00
localrelease : verify -changelog
2025-04-08 19:00:59 -07:00
script/release_build.sh $( RELEASE_ARGS)
2016-06-14 18:03:35 +08:00
2023-10-05 13:28:53 -07:00
.PHONY : dbuild
2016-08-30 09:46:47 +08:00
dbuild : runcimage
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
--privileged --rm \
-v $( CURDIR) :/go/src/$( PROJECT) \
2024-08-21 18:57:38 -07:00
$( RUNC_IMAGE) make clean runc test-binaries
2016-04-26 18:00:01 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : lint
2016-04-07 09:36:08 -07:00
lint :
2021-02-16 14:07:28 -08:00
golangci-lint run ./...
2015-06-26 13:06:17 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : man
2016-04-22 14:37:42 +08:00
man :
man/md2man-all.sh
2023-10-05 13:28:53 -07:00
.PHONY : runcimage
2016-08-30 09:46:47 +08:00
runcimage :
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) build $( CONTAINER_ENGINE_BUILD_FLAGS) -t $( RUNC_IMAGE) .
2015-06-26 13:06:17 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : test
2020-04-27 12:55:24 -07:00
test : unittest integration rootlessintegration
2015-06-26 13:06:17 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : localtest
2020-04-27 12:55:24 -07:00
localtest : localunittest localintegration localrootlessintegration
2015-08-21 15:25:26 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : unittest
2016-08-30 09:46:47 +08:00
unittest : runcimage
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
-t --privileged --rm \
-v /lib/modules:/lib/modules:ro \
-v $( CURDIR) :/go/src/$( PROJECT) \
2023-08-04 17:57:35 +10:00
$( RUNC_IMAGE) make localunittest TESTFLAGS = " $( TESTFLAGS) "
2016-04-26 18:00:01 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : localunittest
2024-08-21 18:57:38 -07:00
localunittest : test -binaries
2021-07-19 15:05:55 -07:00
$( GO) test -timeout 3m -tags " $( BUILDTAGS) " $( TESTFLAGS) -v ./...
2015-06-21 19:31:12 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : integration
2016-09-05 18:06:03 +08:00
integration : runcimage
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
-t --privileged --rm \
-v /lib/modules:/lib/modules:ro \
-v $( CURDIR) :/go/src/$( PROJECT) \
2023-08-04 17:57:35 +10:00
$( RUNC_IMAGE) make localintegration TESTPATH = " $( TESTPATH) "
2016-03-14 14:55:05 -05:00
2023-10-05 13:28:53 -07:00
.PHONY : localintegration
2024-08-21 18:57:38 -07:00
localintegration : runc test -binaries
2020-04-20 12:48:12 -07:00
bats -t tests/integration$( TESTPATH)
2016-04-26 18:00:01 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : rootlessintegration
2016-05-11 17:45:00 +10:00
rootlessintegration : runcimage
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
-t --privileged --rm \
-v $( CURDIR) :/go/src/$( PROJECT) \
-e ROOTLESS_TESTPATH \
$( RUNC_IMAGE) make localrootlessintegration
2016-05-11 17:45:00 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : localrootlessintegration
2024-08-21 18:57:38 -07:00
localrootlessintegration : runc test -binaries
2017-09-07 07:07:43 +10:00
tests/rootless.sh
2016-05-11 17:45:00 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : shell
2018-02-28 05:23:01 +00:00
shell : runcimage
2020-04-20 12:42:58 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
-ti --privileged --rm \
-v $( CURDIR) :/go/src/$( PROJECT) \
$( RUNC_IMAGE) bash
2016-09-06 22:40:01 +10:00
2023-10-05 13:28:53 -07:00
.PHONY : install
2015-06-29 13:33:15 -07:00
install :
2020-09-08 16:47:19 -07:00
install -D -m0755 runc $( DESTDIR) $( BINDIR) /runc
2016-05-11 09:48:59 -04:00
2023-10-05 13:28:53 -07:00
.PHONY : install -bash
2016-05-11 09:48:59 -04:00
install-bash :
2020-09-08 16:47:19 -07:00
install -D -m0644 contrib/completions/bash/runc $( DESTDIR) $( PREFIX) /share/bash-completion/completions/runc
2015-06-21 19:31:12 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : install -man
2020-04-27 13:49:39 -07:00
install-man : man
2020-09-08 16:47:19 -07:00
install -d -m 755 $( DESTDIR) $( MANDIR) /man8
install -D -m 644 man/man8/*.8 $( DESTDIR) $( MANDIR) /man8
2016-04-22 14:37:42 +08:00
2023-10-05 13:28:53 -07:00
.PHONY : cfmt
2021-03-17 13:36:31 -07:00
cfmt : C_SRC =$( shell git ls -files '*.c ' | grep -v '^vendor /')
cfmt :
2024-10-30 23:54:32 +11:00
indent -linux -l120 -il0 -ppi2 -cp1 -sar -T size_t -T jmp_buf $( C_SRC)
2020-11-19 17:56:26 -08:00
2023-10-05 13:28:53 -07:00
.PHONY : shellcheck
2020-11-19 17:56:26 -08:00
shellcheck :
make release: add cross-build
This implements cross-build for "make release", moving the build into a
container. This way we can support arm, arm64, ppc, and whatnot.
* script/seccomp.sh: separate out of script/release.sh, amend to support
cross-compile and save needed environment variables to a file.
* Dockerfile: add installing libseccomp from source, as this is needed
for release builds.
* script/release.sh: amend to support more architectures in addition to
the native build. Additional arches can be added by specifying
"-a <arch>" argument (can be specified multiple times), or
"make RELEASE_ARGS="-a arm64" release" if called via make.
All supported architectures can be enabled via "make releaseall".
* Makefile: move "release" target to "localrelease", add "release" and
"releaseall" targets to build via the Dockerfile. This is done because
most distros (including Fedora and openSUSE) lack cross-glibc, which is
needed to cross-compile libseccomp.
* Makefile: remove 'cross' and 'localcross' targets, as this is now done
by the release script.
* .github/workflows/validate.yum: amend the release CI job to cross-build
for supported architectures, remove cross job.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-09-06 11:31:11 -07:00
shellcheck tests/integration/*.bats tests/integration/*.sh \
tests/integration/*.bash tests/*.sh \
2022-02-16 13:52:46 -08:00
man/*.sh script/*
# TODO: add shellcheck for more sh files (contrib/completions/bash/runc).
2020-11-16 16:48:44 -08:00
2023-10-05 13:28:53 -07:00
.PHONY : shfmt
2020-11-16 16:48:44 -08:00
shfmt :
2022-03-23 11:31:48 -07:00
$( CONTAINER_ENGINE) run $( CONTAINER_ENGINE_RUN_FLAGS) \
--rm -v $( CURDIR) :/src -w /src \
2025-03-10 11:58:23 -07:00
mvdan/shfmt:v3.11.0 -d -w .
2022-03-23 11:31:48 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : localshfmt
2022-03-23 11:31:48 -07:00
localshfmt :
shfmt -d -w .
2015-06-30 12:51:09 -07:00
2024-02-15 15:56:19 +01:00
.PHONY : vendor
2019-06-19 21:56:44 +02:00
vendor :
Makefile: fix vendor and verify-dependencies
Commit a08ab87fe added these targets. Alas, the `go mod tidy` never
worked, as it was written as part of `export` statement:
export GO111MODULE=on \
$(GO) mod tidy && \
...
which is the same as
export GO111MODULE=on $(GO) mod tidy && ...
which exports a bunch of variables, such as `go`, `mod`, and `tidy`,
but does not run it.
The fix would be to add a semicolon after the `export` statement,
but since GO111MODULE is not really needed here (maybe some older
golang versions needed it?), let's just drop it.
With this dropped, && does not make any sense, so drop it, too.
NOTE that if someone tries
GO111MODULE=off make vendor
it will fail, but I guess it is expected.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-09-16 16:26:50 -07:00
$( GO) mod tidy
$( GO) mod vendor
2019-06-19 21:56:44 +02:00
$( GO) mod verify
2023-10-05 13:28:53 -07:00
.PHONY : verify -changelog
2022-07-01 15:49:57 -07:00
verify-changelog :
# No space at EOL.
! grep -n '\s$$' CHANGELOG.md
# Period before issue/PR references.
! grep -n '[0-9a-zA-Z][^.] (#[1-9][0-9, #]*)$$' CHANGELOG.md
2023-10-05 13:28:53 -07:00
.PHONY : verify -dependencies
2019-06-19 21:56:44 +02:00
verify-dependencies : vendor
@test -z " $$ (git status --porcelain -- go.mod go.sum vendor/) " \
|| ( echo -e " git status:\n $$ (git status -- go.mod go.sum vendor/)\nerror: vendor/, go.mod and/or go.sum not up to date. Run \"make vendor\" to update " ; exit 1) \
&& echo "all vendor files are up to date."
2023-10-05 12:51:43 -07:00
2023-10-05 13:28:53 -07:00
.PHONY : validate -keyring
2023-04-19 12:29:21 +10:00
validate-keyring :
script/keyring_validate.sh