mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
*.sh: use shfmt
I played with shfmt options (-bn, -ci, -sr) a bit trying to minimize the patch generated (and also because I don't have a strong preference on these matters), and it appears to be that the patch size is about the same nevertheless, so I chose no options. This commit is brought to you by shfmt -ln bash -w man/*.sh script/*.sh tests/*.sh tests/integration/*.bash Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# bits of this were adapted from check_config.sh in docker
|
||||
# bits of this were adapted from check_config.sh in docker
|
||||
# see also https://github.com/docker/docker/blob/master/contrib/check-config.sh
|
||||
|
||||
possibleConfigs=(
|
||||
@@ -202,7 +202,7 @@ flags=(
|
||||
NF_NAT_IPV4 IP_NF_FILTER IP_NF_TARGET_MASQUERADE
|
||||
NETFILTER_XT_MATCH_{ADDRTYPE,CONNTRACK,IPVS}
|
||||
IP_NF_NAT NF_NAT NF_NAT_NEEDED
|
||||
|
||||
|
||||
# required for bind-mounting /dev/mqueue into containers
|
||||
POSIX_MQUEUE
|
||||
)
|
||||
|
||||
+29
-26
@@ -66,29 +66,29 @@ releasedir=""
|
||||
hashcmd=""
|
||||
while getopts "S:c:r:v:h:" opt; do
|
||||
case "$opt" in
|
||||
S)
|
||||
keyid="$OPTARG"
|
||||
;;
|
||||
c)
|
||||
commit="$OPTARG"
|
||||
;;
|
||||
r)
|
||||
releasedir="$OPTARG"
|
||||
;;
|
||||
v)
|
||||
version="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
hashcmd="$OPTARG"
|
||||
;;
|
||||
\:)
|
||||
echo "Missing argument: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
S)
|
||||
keyid="$OPTARG"
|
||||
;;
|
||||
c)
|
||||
commit="$OPTARG"
|
||||
;;
|
||||
r)
|
||||
releasedir="$OPTARG"
|
||||
;;
|
||||
v)
|
||||
version="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
hashcmd="$OPTARG"
|
||||
;;
|
||||
\:)
|
||||
echo "Missing argument: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -113,10 +113,13 @@ rm -rf "$releasedir" && mkdir -p "$releasedir"
|
||||
build_project "$releasedir/$project.$goarch"
|
||||
|
||||
# Generate new archive.
|
||||
git archive --format=tar --prefix="$project-$version/" "$commit" | xz > "$releasedir/$project.tar.xz"
|
||||
git archive --format=tar --prefix="$project-$version/" "$commit" | xz >"$releasedir/$project.tar.xz"
|
||||
|
||||
# Generate sha256 checksums for both.
|
||||
( cd "$releasedir" ; "$hashcmd" "$project".{"$goarch",tar.xz} > "$project.$hashcmd" ; )
|
||||
(
|
||||
cd "$releasedir"
|
||||
"$hashcmd" "$project".{"$goarch",tar.xz} >"$project.$hashcmd"
|
||||
)
|
||||
|
||||
# Set up the gpgflags.
|
||||
[[ "$keyid" ]] && export gpgflags="--default-key $keyid"
|
||||
@@ -126,5 +129,5 @@ gpg_cansign $gpgflags || bail "Could not find suitable GPG key, skipping signing
|
||||
gpg $gpgflags --detach-sign --armor "$releasedir/$project.$goarch"
|
||||
gpg $gpgflags --detach-sign --armor "$releasedir/$project.tar.xz"
|
||||
gpg $gpgflags --clear-sign --armor \
|
||||
--output "$releasedir/$project.$hashcmd"{.tmp,} && \
|
||||
--output "$releasedir/$project.$hashcmd"{.tmp,} &&
|
||||
mv "$releasedir/$project.$hashcmd"{.tmp,}
|
||||
|
||||
@@ -17,7 +17,7 @@ BUSYBOX_IMAGE="$BATS_TMPDIR/busybox.tar"
|
||||
BUSYBOX_BUNDLE="$BATS_TMPDIR/busyboxtest"
|
||||
|
||||
# hello-world in tar format
|
||||
HELLO_FILE=`get_hello`
|
||||
HELLO_FILE=$(get_hello)
|
||||
HELLO_IMAGE="$TESTDATA/$HELLO_FILE"
|
||||
HELLO_BUNDLE="$BATS_TMPDIR/hello-world"
|
||||
|
||||
@@ -95,11 +95,11 @@ function update_config() {
|
||||
# a rootless configuration.
|
||||
function runc_rootless_idmap() {
|
||||
bundle="${1:-.}"
|
||||
update_config ' .mounts |= map((select(.type == "devpts") | .options += ["gid=5"]) // .)
|
||||
update_config ' .mounts |= map((select(.type == "devpts") | .options += ["gid=5"]) // .)
|
||||
| .linux.uidMappings += [{"hostID": '"$ROOTLESS_UIDMAP_START"', "containerID": 1000, "size": '"$ROOTLESS_UIDMAP_LENGTH"'}]
|
||||
| .linux.gidMappings += [{"hostID": '"$ROOTLESS_GIDMAP_START"', "containerID": 100, "size": 1}]
|
||||
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START+10))"', "containerID": 1, "size": 20}]
|
||||
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START+100))"', "containerID": 1000, "size": '"$(($ROOTLESS_GIDMAP_LENGTH-1000))"'}]' $bundle
|
||||
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 10))"', "containerID": 1, "size": 20}]
|
||||
| .linux.gidMappings += [{"hostID": '"$(($ROOTLESS_GIDMAP_START + 100))"', "containerID": 1000, "size": '"$(($ROOTLESS_GIDMAP_LENGTH - 1000))"'}]' $bundle
|
||||
}
|
||||
|
||||
# Shortcut to add empty resources as part of a rootless configuration.
|
||||
@@ -122,7 +122,7 @@ function init_cgroup_paths() {
|
||||
# init once
|
||||
test -n "$CGROUP_UNIFIED" && return
|
||||
|
||||
if [ -n "${RUNC_USE_SYSTEMD}" ] ; then
|
||||
if [ -n "${RUNC_USE_SYSTEMD}" ]; then
|
||||
SD_UNIT_NAME="runc-cgroups-integration-test.scope"
|
||||
if [ $(id -u) = "0" ]; then
|
||||
REL_CGROUPS_PATH="/machine.slice/$SD_UNIT_NAME"
|
||||
@@ -144,13 +144,15 @@ function init_cgroup_paths() {
|
||||
# it's quite hard to test.
|
||||
# - freezer (since kernel 5.2) we can auto-detect by looking for the
|
||||
# "cgroup.freeze" file a *non-root* cgroup.
|
||||
CGROUP_SUBSYSTEMS=$(cat /sys/fs/cgroup/cgroup.controllers; echo devices)
|
||||
CGROUP_SUBSYSTEMS=$(
|
||||
cat /sys/fs/cgroup/cgroup.controllers
|
||||
echo devices
|
||||
)
|
||||
CGROUP_BASE_PATH=/sys/fs/cgroup
|
||||
CGROUP_PATH=${CGROUP_BASE_PATH}${REL_CGROUPS_PATH}
|
||||
|
||||
# Find any cgroup.freeze files...
|
||||
if [ -n "$(find "$CGROUP_BASE_PATH" -type f -name "cgroup.freeze" -print -quit)" ]
|
||||
then
|
||||
if [ -n "$(find "$CGROUP_BASE_PATH" -type f -name "cgroup.freeze" -print -quit)" ]; then
|
||||
CGROUP_SUBSYSTEMS+=" freezer"
|
||||
fi
|
||||
else
|
||||
@@ -177,7 +179,7 @@ function check_cgroup_value() {
|
||||
source=$1
|
||||
expected=$2
|
||||
|
||||
if [ "x$CGROUP_UNIFIED" = "xyes" ] ; then
|
||||
if [ "x$CGROUP_UNIFIED" = "xyes" ]; then
|
||||
cgroup=$CGROUP_PATH
|
||||
else
|
||||
ctrl=${source%%.*}
|
||||
@@ -427,7 +429,7 @@ function setup_busybox() {
|
||||
BUSYBOX_IMAGE="/testdata/busybox.tar"
|
||||
fi
|
||||
if [ ! -e $BUSYBOX_IMAGE ]; then
|
||||
curl -o $BUSYBOX_IMAGE -sSL `get_busybox`
|
||||
curl -o $BUSYBOX_IMAGE -sSL $(get_busybox)
|
||||
fi
|
||||
tar --exclude './dev/*' -C "$BUSYBOX_BUNDLE"/rootfs -xf "$BUSYBOX_IMAGE"
|
||||
cd "$BUSYBOX_BUNDLE"
|
||||
|
||||
@@ -3,10 +3,10 @@ get_busybox() {
|
||||
case $(go env GOARCH) in
|
||||
arm64)
|
||||
echo 'https://github.com/docker-library/busybox/raw/dist-arm64v8/glibc/busybox.tar.xz'
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
echo 'https://github.com/docker-library/busybox/raw/dist-amd64/glibc/busybox.tar.xz'
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ get_hello() {
|
||||
case $(go env GOARCH) in
|
||||
arm64)
|
||||
echo 'hello-world-aarch64.tar'
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
echo 'hello-world.tar'
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ get_and_extract_debian() {
|
||||
case $(go env GOARCH) in
|
||||
arm64)
|
||||
skopeo copy docker://arm64v8/debian:buster "oci:$debian"
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
skopeo copy docker://amd64/debian:buster "oci:$debian"
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
|
||||
args="$([ -z "${ROOTLESS_TESTPATH+x}" ] && echo "--rootless")"
|
||||
|
||||
+18
-16
@@ -21,7 +21,7 @@
|
||||
|
||||
ALL_FEATURES=("idmap" "cgroup")
|
||||
# cgroup is managed by systemd when RUNC_USE_SYSTEMD is set
|
||||
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then
|
||||
if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then
|
||||
ALL_FEATURES=("idmap")
|
||||
fi
|
||||
ROOT="$(readlink -f "$(dirname "${BASH_SOURCE}")/..")"
|
||||
@@ -35,10 +35,16 @@ function enable_idmap() {
|
||||
|
||||
# Set up sub{uid,gid} mappings.
|
||||
[ -e /etc/subuid.tmp ] && mv /etc/subuid{.tmp,}
|
||||
( grep -v '^rootless' /etc/subuid ; echo "rootless:$ROOTLESS_UIDMAP_START:$ROOTLESS_UIDMAP_LENGTH" ) > /etc/subuid.tmp
|
||||
(
|
||||
grep -v '^rootless' /etc/subuid
|
||||
echo "rootless:$ROOTLESS_UIDMAP_START:$ROOTLESS_UIDMAP_LENGTH"
|
||||
) >/etc/subuid.tmp
|
||||
mv /etc/subuid{.tmp,}
|
||||
[ -e /etc/subgid.tmp ] && mv /etc/subgid{.tmp,}
|
||||
( grep -v '^rootless' /etc/subgid ; echo "rootless:$ROOTLESS_GIDMAP_START:$ROOTLESS_GIDMAP_LENGTH" ) > /etc/subgid.tmp
|
||||
(
|
||||
grep -v '^rootless' /etc/subgid
|
||||
echo "rootless:$ROOTLESS_GIDMAP_START:$ROOTLESS_GIDMAP_LENGTH"
|
||||
) >/etc/subgid.tmp
|
||||
mv /etc/subgid{.tmp,}
|
||||
|
||||
# Reactivate new{uid,gid}map helpers if applicable.
|
||||
@@ -65,14 +71,13 @@ function disable_idmap() {
|
||||
|
||||
# List of cgroups. We handle name= cgroups as well as combined
|
||||
# (comma-separated) cgroups and correctly split and/or strip them.
|
||||
ALL_CGROUPS=( $(cat /proc/self/cgroup | cut -d: -f2 | sed -E '{s/^name=//;s/,/\n/;/^$/D}') )
|
||||
ALL_CGROUPS=($(cat /proc/self/cgroup | cut -d: -f2 | sed -E '{s/^name=//;s/,/\n/;/^$/D}'))
|
||||
CGROUP_MOUNT="/sys/fs/cgroup"
|
||||
CGROUP_PATH="/runc-cgroups-integration-test"
|
||||
|
||||
function enable_cgroup() {
|
||||
# Set up cgroups for use in rootless containers.
|
||||
for cg in "${ALL_CGROUPS[@]}"
|
||||
do
|
||||
for cg in "${ALL_CGROUPS[@]}"; do
|
||||
mkdir -p "$CGROUP_MOUNT/$cg$CGROUP_PATH"
|
||||
# We only need to allow write access to {cgroup.procs,tasks} and the
|
||||
# directory. Rather than changing the owner entirely, we just change
|
||||
@@ -90,7 +95,7 @@ function enable_cgroup() {
|
||||
if [[ -e "$CGROUP_MOUNT/cgroup.controllers" ]]; then
|
||||
# Enable controllers. Some controller (e.g. memory) may fail on containerized environment.
|
||||
set -x
|
||||
for f in $(cat "$CGROUP_MOUNT/cgroup.controllers"); do echo +$f > "$CGROUP_MOUNT/cgroup.subtree_control"; done
|
||||
for f in $(cat "$CGROUP_MOUNT/cgroup.controllers"); do echo +$f >"$CGROUP_MOUNT/cgroup.subtree_control"; done
|
||||
set +x
|
||||
# Create the cgroup.
|
||||
mkdir -p "$CGROUP_MOUNT/$CGROUP_PATH"
|
||||
@@ -104,8 +109,7 @@ function enable_cgroup() {
|
||||
|
||||
function disable_cgroup() {
|
||||
# Remove cgroups used in rootless containers.
|
||||
for cg in "${ALL_CGROUPS[@]}"
|
||||
do
|
||||
for cg in "${ALL_CGROUPS[@]}"; do
|
||||
[ -d "$CGROUP_MOUNT/$cg$CGROUP_PATH" ] && rmdir "$CGROUP_MOUNT/$cg$CGROUP_PATH"
|
||||
done
|
||||
# cgroup v2
|
||||
@@ -123,14 +127,12 @@ features_powerset="$(powerset "${ALL_FEATURES[@]}")"
|
||||
|
||||
# Iterate over the powerset of all features.
|
||||
IFS=:
|
||||
for enabled_features in $features_powerset
|
||||
do
|
||||
idx="$(($idx+1))"
|
||||
for enabled_features in $features_powerset; do
|
||||
idx="$(($idx + 1))"
|
||||
echo "[$(printf '%.2d' "$idx")] run rootless tests ... (${enabled_features%%+})"
|
||||
|
||||
unset IFS
|
||||
for feature in "${ALL_FEATURES[@]}"
|
||||
do
|
||||
for feature in "${ALL_FEATURES[@]}"; do
|
||||
hook_func="disable_$feature"
|
||||
grep -E "(^|\+)$feature(\+|$)" <<<$enabled_features &>/dev/null && hook_func="enable_$feature"
|
||||
"$hook_func"
|
||||
@@ -140,11 +142,11 @@ do
|
||||
set -e
|
||||
echo path: $PATH
|
||||
export ROOTLESS_FEATURES="$enabled_features"
|
||||
if [[ -n "${RUNC_USE_SYSTEMD}" ]] ; then
|
||||
if [[ -n "${RUNC_USE_SYSTEMD}" ]]; then
|
||||
# We use `ssh rootless@localhost` instead of `sudo -u rootless` for creating systemd user session.
|
||||
# Alternatively we could use `machinectl shell`, but it is known not to work well on SELinux-enabled hosts as of April 2020:
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1788616
|
||||
ssh -t -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/rootless.key rootless@localhost -- PATH="$PATH" RUNC_USE_SYSTEMD="$RUNC_USE_SYSTEMD" bats -t "$ROOT/tests/integration$ROOTLESS_TESTPATH"
|
||||
ssh -t -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/rootless.key rootless@localhost -- PATH="$PATH" RUNC_USE_SYSTEMD="$RUNC_USE_SYSTEMD" bats -t "$ROOT/tests/integration$ROOTLESS_TESTPATH"
|
||||
else
|
||||
sudo -HE -u rootless PATH="$PATH" $(which bats) -t "$ROOT/tests/integration$ROOTLESS_TESTPATH"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user