neko/.docker/build

108 lines
2.7 KiB
Plaintext
Raw Normal View History

2020-06-17 10:32:34 +12:00
#!/bin/sh
2022-05-15 04:56:51 +12:00
set -ex
2020-06-19 12:38:35 +12:00
cd "$(dirname "$0")"
2020-06-17 10:32:34 +12:00
2021-03-23 10:01:54 +13:00
BASE="${PWD}/../"
2021-04-02 10:18:50 +13:00
# BUILD_IMAGE from environment vairables has precedence
if [ ! -z "${BUILD_IMAGE}" ]
then
ENV_BUILD_IMAGE="${BUILD_IMAGE}"
fi
2021-04-02 10:18:50 +13:00
if [ -f ".env.default" ]
then
export $(cat .env.default | sed 's/#.*//g' | xargs)
fi
if [ -f ".env" ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
# BUILD_IMAGE from environment vairables has precedence
if [ ! -z "${ENV_BUILD_IMAGE}" ]
then
BUILD_IMAGE="${ENV_BUILD_IMAGE}"
unset ENV_BUILD_IMAGE
fi
2021-04-02 10:18:50 +13:00
if [ -z "${1}" ] && [ ! -z "${SERVER_TAG}" ]
then
./build base
./build ${SERVER_TAG}
exit 0
fi
2020-06-17 10:32:34 +12:00
build_client() {
2021-03-23 10:01:54 +13:00
docker build -t neko-dev-client -f base/Dockerfile --target client "${BASE}"
docker run --rm \
--user "$(id -u):$(id -g)" \
-v "${BASE}client/dist:/tmp/dist" \
neko-dev-client sh -c "rm -rf /tmp/dist/*; cp -r /src/dist/* /tmp/dist"
2020-06-17 10:32:34 +12:00
}
build_server() {
2021-03-23 10:01:54 +13:00
docker build -t neko-dev-server -f base/Dockerfile --target server "${BASE}"
docker run --rm \
--user "$(id -u):$(id -g)" \
-v "${BASE}server/bin:/tmp/bin" \
neko-dev-server sh -c "rm -rf /tmp/bin/neko; cp /src/bin/neko /tmp/bin"
2021-03-29 22:27:28 +13:00
}
2021-04-02 08:00:48 +13:00
build() {
if [ "$1" = "base" ]
then
# build base
2021-04-02 10:18:50 +13:00
docker build -t "${BUILD_IMAGE}:base" -f base/Dockerfile "${BASE}"
2021-04-02 08:00:48 +13:00
else
2021-04-04 00:56:41 +13:00
# build image
2021-04-02 10:18:50 +13:00
docker build -t "${BUILD_IMAGE}:$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:base" -f "$1/Dockerfile" "$1/"
2021-04-02 08:00:48 +13:00
fi
2020-06-30 19:45:45 +12:00
}
2021-04-02 08:00:48 +13:00
build_arm() {
if [ "$1" = "base" ]
then
# build ARM base
2021-04-04 00:50:54 +13:00
docker build -t "${BUILD_IMAGE}:arm-base" -f base/Dockerfile.arm "${BASE}"
2021-04-04 00:56:41 +13:00
elif [ -f "$1/Dockerfile.arm" ]
then
# build dedicated ARM image
2021-04-04 00:50:54 +13:00
docker build -t "${BUILD_IMAGE}:arm-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:arm-base" -f "$1/Dockerfile.arm" "$1/"
2021-04-04 00:56:41 +13:00
else
# try to build ARM image with common Dockerfile
docker build -t "${BUILD_IMAGE}:arm-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:arm-base" -f "$1/Dockerfile" "$1/"
2021-04-02 08:00:48 +13:00
fi
}
2023-01-15 11:35:52 +13:00
build_nvidia() {
if [ "$1" = "base" ]
then
# build nvidia base
docker build -t "${BUILD_IMAGE}:nvidia-base" -f base/Dockerfile.nvidia "${BASE}"
elif [ -f "$1/Dockerfile.nvidia" ]
then
# build dedicated nvidia image
docker build -t "${BUILD_IMAGE}:nvidia-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:nvidia-base" -f "$1/Dockerfile.nvidia" "$1/"
else
# try to build nvidia image with common Dockerfile
docker build -t "${BUILD_IMAGE}:nvidia-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:nvidia-base" -f "$1/Dockerfile" "$1/"
fi
}
2020-06-17 10:32:34 +12:00
case $1 in
client) build_client;;
2021-03-23 10:01:54 +13:00
server) build_server;;
2021-04-02 08:00:48 +13:00
# build arm- images
arm-*) build_arm "${1#arm-}";;
2023-01-15 11:35:52 +13:00
# build nvidia- images
nvidia-*) build_nvidia "${1#nvidia-}";;
2021-04-02 08:00:48 +13:00
# build images
2021-03-23 10:01:54 +13:00
*) build "$1";;
2020-06-17 10:32:34 +12:00
esac