Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions bin/setup-cgroups
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,40 @@ fi
mkdir -p /sys/fs/cgroup
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup

sed -e 1d /proc/cgroups | while read sys hierarchy num enabled; do
if [ "$enabled" != "1" ]; then
# subsystem disabled; skip
continue
fi
{
read -r _ # skip first line
while read -r sys _hierarchy _num enabled; do
if [ "$enabled" != "1" ]; then
# subsystem disabled; skip
continue
fi

grouping="$(cat /proc/self/cgroup | cut -d: -f2 | grep "\\<$sys\\>")" || true
if [ -z "$grouping" ]; then
# subsystem not mounted anywhere; mount it on its own
grouping="$sys"
fi
grouping="$(</proc/self/cgroup cut -d: -f2 | grep "\\<$sys\\>")" || true
if [ -z "$grouping" ]; then
# subsystem not mounted anywhere; mount it on its own
grouping="$sys"
fi

mountpoint="/sys/fs/cgroup/$grouping"
mountpoint="/sys/fs/cgroup/$grouping"

mkdir -p "$mountpoint"
mkdir -p "$mountpoint"

# clear out existing mount to make sure new one is read-write
if mountpoint -q "$mountpoint"; then
umount "$mountpoint"
fi
# clear out existing mount to make sure new one is read-write
if mountpoint -q "$mountpoint"; then
umount "$mountpoint"
fi

mount -n -t cgroup -o "$grouping" cgroup "$mountpoint"
mount -n -t cgroup -o "$grouping" cgroup "$mountpoint"

if [ "$grouping" != "$sys" ]; then
if [ -L "/sys/fs/cgroup/$sys" ]; then
rm "/sys/fs/cgroup/$sys"
fi
if [ "$grouping" != "$sys" ]; then
if [ -L "/sys/fs/cgroup/$sys" ]; then
rm "/sys/fs/cgroup/$sys"
fi

ln -s "$mountpoint" "/sys/fs/cgroup/$sys"
fi
done
ln -s "$mountpoint" "/sys/fs/cgroup/$sys"
fi
done
} </proc/cgroups

if ! test -e /sys/fs/cgroup/systemd ; then
mkdir /sys/fs/cgroup/systemd
Expand Down
5 changes: 3 additions & 2 deletions scripts/build-image
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

set -e -u -x

cd $(dirname $0)/..
script=${BASH_SOURCE[0]}
cd "${script%/*}"/.. || exit

export PATH=$PWD/bin:$PATH

. ./scripts/setup-buildkit.sh

mkdir -p image

build
exec build
10 changes: 6 additions & 4 deletions scripts/push-image
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ version=""

case $GITHUB_REF in
refs/heads/*)
tag=$(echo $GITHUB_REF | sed 's|refs/heads/||')
tag=${GITHUB_REF#refs/heads/}
;;

refs/tags/v[0-9]*)
version=$(echo $GITHUB_REF | sed 's|refs/tags/v||')
version=${GITHUB_REF#refs/tags/v}
;;

refs/tags/*)
tag=$(echo $GITHUB_REF | sed 's|refs/tags/||')
tag=${GITHUB_REF#refs/tags/}
;;

refs/pull/[0-9]*/merge)
tag=pr$(echo $GITHUB_REF | sed 's|refs/pull/\([0-9]\+\)/merge|\1|')
tag=${GITHUB_REF#refs/pull/}
tag=${tag%/merge}
tag=pr$tag
;;

*)
Expand Down
27 changes: 17 additions & 10 deletions scripts/setup-buildkit.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
if ! which buildctl >/dev/null || ! which buildkitd >/dev/null; then
#!/usr/bin/env bash
# this is sourced, not executed; the shebang above is a hint for shellcheck and/or editors

uname_arch=$(uname -m)
case $uname_arch in
x86_64) arch=amd64;;
aarch64) arch=arm64;;
*) arch=$uname_arch;;
esac

if ! command -v buildctl >/dev/null || ! command -v buildkitd >/dev/null; then
BUILDKIT_VERSION=0.9.1
BUILDKIT_URL=https://github.com/moby/buildkit/releases/download/v$BUILDKIT_VERSION/buildkit-v$BUILDKIT_VERSION.linux-amd64.tar.gz
BUILDKIT_URL=https://github.com/moby/buildkit/releases/download/v$BUILDKIT_VERSION/buildkit-v$BUILDKIT_VERSION.linux-${arch}.tar.gz

curl -fL "$BUILDKIT_URL" | tar zxf -
fi

if [ "$(id -u)" != "0" ]; then
if ! which newuidmap >/dev/null || ! which newgidmap >/dev/null; then
echo "newuidmap and newgidmap must be installed"
if [ "$UID" != "0" ]; then
if ! command -v newuidmap >/dev/null || ! command -v newgidmap >/dev/null; then
echo "newuidmap and newgidmap must be installed" >&2
exit 1
fi

if ! which rootlesskit >/dev/null; then
pushd rootlesskit
make
popd

if ! command -v rootlesskit >/dev/null; then
(cd rootlesskit && exec make)
cp rootlesskit/bin/* bin/
fi
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -e -u

cd $(dirname $0)/..
script=${BASH_SOURCE[0]}
cd "${script%/*}/.." || exit

export PATH=$PWD/bin:$PATH

Expand Down
Loading