Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/.docker/build
2021-11-27 14:23:33 +01:00

89 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
cd "$(dirname "$0")"
BASE="${PWD}/../"
# BUILD_IMAGE from environment vairables has precedence
if [ ! -z "${BUILD_IMAGE}" ]
then
ENV_BUILD_IMAGE="${BUILD_IMAGE}"
fi
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
if [ -z "${1}" ] && [ ! -z "${SERVER_TAG}" ]
then
./build base
./build ${SERVER_TAG}
exit 0
fi
build_client() {
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"
}
build_server() {
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"
}
build() {
if [ "$1" = "base" ]
then
# build base
docker build -t "${BUILD_IMAGE}:base" -f base/Dockerfile "${BASE}"
else
# build image
docker build -t "${BUILD_IMAGE}:$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:base" -f "$1/Dockerfile" "$1/"
fi
}
build_arm() {
if [ "$1" = "base" ]
then
# build ARM base
docker build -t "${BUILD_IMAGE}:arm-base" -f base/Dockerfile.arm "${BASE}"
elif [ -f "$1/Dockerfile.arm" ]
then
# build dedicated ARM image
docker build -t "${BUILD_IMAGE}:arm-$1" --build-arg="BASE_IMAGE=${BUILD_IMAGE}:arm-base" -f "$1/Dockerfile.arm" "$1/"
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/"
fi
}
case $1 in
client) build_client;;
server) build_server;;
# build arm- images
arm-*) build_arm "${1#arm-}";;
# build images
*) build "$1";;
esac