-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context): Support unix context and daemonless (#1062)
* feat(context): Support unix context Signed-off-by: Ce Gao <cegao@tensorchord.ai> * chore: Auto-build image Signed-off-by: Ce Gao <cegao@tensorchord.ai> * chore: Update release workflow Signed-off-by: Ce Gao <cegao@tensorchord.ai> * fix: Update name Signed-off-by: Ce Gao <cegao@tensorchord.ai> * chore: Add license for bash Signed-off-by: Ce Gao <cegao@tensorchord.ai> Signed-off-by: Ce Gao <cegao@tensorchord.ai>
- Loading branch information
Showing
12 changed files
with
204 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2022 The envd Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
set -euo pipefail | ||
|
||
ROOT_DIR=`dirname $0` | ||
|
||
GIT_TAG_VERSION=$(git describe --tags --abbrev=0 | sed -r 's/[v]+//g') # remove v from version | ||
ENVD_VERSION="${ENVD_VERSION:-$GIT_TAG_VERSION}" | ||
DOCKER_HUB_ORG="${DOCKER_HUB_ORG:-tensorchord}" | ||
TAG_SUFFIX="${TAG_SUFFIX:-}" | ||
|
||
cd ${ROOT_DIR} | ||
|
||
docker buildx build \ | ||
--build-arg ENVD_VERSION=${ENVD_VERSION} \ | ||
-t ${DOCKER_HUB_ORG}/envd:${ENVD_VERSION} \ | ||
--pull --push --platform linux/x86_64,linux/arm64 \ | ||
-f envd-daemonless.Dockerfile ../../ | ||
|
||
cd - > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM tensorchord/envd:latest as envd | ||
|
||
FROM moby/buildkit:v0.10.5-rootless | ||
COPY --from=envd /usr/bin/envd /usr/bin/envd | ||
COPY scripts/envd-daemonless.sh /envd-daemonless.sh | ||
|
||
CMD [ "/envd-daemonless.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM scratch | ||
COPY envd /usr/bin/envd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/sh | ||
|
||
# Copyright 2022 The envd Authors | ||
# Copyright 2022 The buildkit Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# envd-daemonless.sh spawns ephemeral buildkitd for executing envd. | ||
# | ||
# Usage: envd-daemonless.sh build ... | ||
# | ||
# Flags for buildkitd can be specified as $BUILDKITD_FLAGS . | ||
# | ||
# The script is compatible with BusyBox shell. | ||
set -eu | ||
|
||
: ${ENVDCTL=envd} | ||
: ${BUILDCTL=buildctl} | ||
: ${BUILDCTL_CONNECT_RETRIES_MAX=10} | ||
: ${BUILDKITD=buildkitd} | ||
: ${BUILDKITD_FLAGS=} | ||
: ${ROOTLESSKIT=rootlesskit} | ||
|
||
# $tmp holds the following files: | ||
# * pid | ||
# * addr | ||
# * log | ||
tmp=$(mktemp -d /tmp/envd-daemonless.XXXXXX) | ||
trap "kill \$(cat $tmp/pid) || true; wait \$(cat $tmp/pid) || true; rm -rf $tmp" EXIT | ||
|
||
startBuildkitd() { | ||
addr= | ||
helper= | ||
if [ $(id -u) = 0 ]; then | ||
addr=/run/buildkit/buildkitd.sock | ||
else | ||
addr=$XDG_RUNTIME_DIR/buildkit/buildkitd.sock | ||
helper=$ROOTLESSKIT | ||
fi | ||
$helper $BUILDKITD $BUILDKITD_FLAGS --addr=unix://$addr >$tmp/log 2>&1 & | ||
pid=$! | ||
echo $pid >$tmp/pid | ||
echo $addr >$tmp/addr | ||
} | ||
|
||
# buildkitd supports NOTIFY_SOCKET but as far as we know, there is no easy way | ||
# to wait for NOTIFY_SOCKET activation using busybox-builtin commands... | ||
waitForBuildkitd() { | ||
addr=unix://$(cat $tmp/addr) | ||
try=0 | ||
max=$BUILDCTL_CONNECT_RETRIES_MAX | ||
until $BUILDCTL --addr=$addr debug workers >/dev/null 2>&1; do | ||
if [ $try -gt $max ]; then | ||
echo >&2 "could not connect to $addr after $max trials" | ||
echo >&2 "========== log ==========" | ||
cat >&2 $tmp/log | ||
exit 1 | ||
fi | ||
sleep $(awk "BEGIN{print (100 + $try * 20) * 0.001}") | ||
try=$(expr $try + 1) | ||
done | ||
} | ||
|
||
startBuildkitd | ||
waitForBuildkitd | ||
$ENVDCTL context create --name daemonless --builder unix --builder-address $(cat $tmp/addr) --use | ||
$ENVDCTL "$@" |