2020-11-13 12:27:41 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-06-10 17:33:49 +08:00
|
|
|
# Absolute path to the toplevel milvus directory.
|
2020-11-13 12:27:41 +08:00
|
|
|
toplevel=$(dirname "$(cd "$(dirname "${0}")"; pwd)")
|
|
|
|
|
2022-08-26 23:46:54 +08:00
|
|
|
export OS_NAME="${OS_NAME:-ubuntu20.04}"
|
2021-07-08 15:43:45 +08:00
|
|
|
|
2020-11-13 12:27:41 +08:00
|
|
|
pushd "${toplevel}"
|
|
|
|
|
2021-04-29 11:28:27 +08:00
|
|
|
if [[ "${1-}" == "pull" ]]; then
|
2021-07-08 15:43:45 +08:00
|
|
|
docker-compose pull --ignore-pull-failures builder
|
2020-11-13 12:27:41 +08:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-04-29 11:28:27 +08:00
|
|
|
if [[ "${1-}" == "down" ]]; then
|
2020-11-18 16:38:28 +08:00
|
|
|
docker-compose down
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-11-13 12:27:41 +08:00
|
|
|
# Attempt to run in the container with the same UID/GID as we have on the host,
|
|
|
|
# as this results in the correct permissions on files created in the shared
|
|
|
|
# volumes. This isn't always possible, however, as IDs less than 100 are
|
|
|
|
# reserved by Debian, and IDs in the low 100s are dynamically assigned to
|
|
|
|
# various system users and groups. To be safe, if we see a UID/GID less than
|
|
|
|
# 500, promote it to 501. This is notably necessary on macOS Lion and later,
|
|
|
|
# where administrator accounts are created with a GID of 20. This solution is
|
|
|
|
# not foolproof, but it works well in practice.
|
|
|
|
uid=$(id -u)
|
|
|
|
gid=$(id -g)
|
|
|
|
[ "$uid" -lt 500 ] && uid=501
|
|
|
|
[ "$gid" -lt 500 ] && gid=$uid
|
|
|
|
|
2021-07-08 15:43:45 +08:00
|
|
|
mkdir -p "${DOCKER_VOLUME_DIRECTORY:-.docker}/amd64-${OS_NAME}-ccache"
|
|
|
|
mkdir -p "${DOCKER_VOLUME_DIRECTORY:-.docker}/amd64-${OS_NAME}-go-mod"
|
2021-07-09 11:59:09 +08:00
|
|
|
mkdir -p "${DOCKER_VOLUME_DIRECTORY:-.docker}/thirdparty"
|
2021-07-08 15:43:45 +08:00
|
|
|
mkdir -p "${DOCKER_VOLUME_DIRECTORY:-.docker}/amd64-${OS_NAME}-vscode-extensions"
|
2020-11-13 12:27:41 +08:00
|
|
|
chmod -R 777 "${DOCKER_VOLUME_DIRECTORY:-.docker}"
|
|
|
|
|
2021-07-08 15:43:45 +08:00
|
|
|
docker-compose pull --ignore-pull-failures builder
|
2021-04-29 11:28:27 +08:00
|
|
|
if [[ "${CHECK_BUILDER:-}" == "1" ]]; then
|
2021-07-08 15:43:45 +08:00
|
|
|
docker-compose build builder
|
2020-11-17 18:36:03 +08:00
|
|
|
fi
|
2021-04-29 11:28:27 +08:00
|
|
|
|
|
|
|
if [[ "$(id -u)" != "0" ]]; then
|
2022-08-12 20:00:47 +08:00
|
|
|
docker-compose run --no-deps --rm -u "$uid:$gid" builder "$@"
|
2021-04-29 11:28:27 +08:00
|
|
|
else
|
2022-08-12 20:00:47 +08:00
|
|
|
docker-compose run --no-deps --rm --entrypoint "/tini -- /entrypoint.sh" builder "$@"
|
2021-04-29 11:28:27 +08:00
|
|
|
fi
|
2020-11-13 12:27:41 +08:00
|
|
|
|
|
|
|
popd
|