Add node interpretter
This commit is contained in:
parent
450cae64b9
commit
a499fed7ba
18
node-interpretter/Makefile
Normal file
18
node-interpretter/Makefile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
DOCKER_REGISTRY = dr.ys-dev.cz
|
||||||
|
DOCKER_PUBLIC_REGISTRY = yoursystemcz
|
||||||
|
APP_NAME = node-interpretter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: build release
|
||||||
|
|
||||||
|
|
||||||
|
build:
|
||||||
|
docker build -t $(DOCKER_REGISTRY)/$(APP_NAME):latest --build-arg "IMAGE_NAME=node" --build-arg "IMAGE_VERSION=10.15.0-slim" ./src
|
||||||
|
|
||||||
|
tag:
|
||||||
|
docker tag $(DOCKER_REGISTRY)/$(APP_NAME):latest $(DOCKER_PUBLIC_REGISTRY)/$(APP_NAME):latest
|
||||||
|
|
||||||
|
release: tag
|
||||||
|
docker push $(DOCKER_REGISTRY)/$(APP_NAME):latest
|
||||||
|
docker push $(DOCKER_PUBLIC_REGISTRY)/$(APP_NAME):latest
|
||||||
41
node-interpretter/bin/node
Executable file
41
node-interpretter/bin/node
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
|
||||||
|
|
||||||
|
SERVICE_NAME="node-interpretter"
|
||||||
|
|
||||||
|
source ${SCRIPT_PATH}/shared.env.shinc 2> /dev/null
|
||||||
|
source ${SCRIPT_PATH}/env.shinc 2> /dev/null
|
||||||
|
|
||||||
|
|
||||||
|
docker inspect --type container ${SERVICE_NAME} > /dev/null 2>&1
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "The node container does not exist"
|
||||||
|
exit 137
|
||||||
|
fi
|
||||||
|
|
||||||
|
NODE_SERVICE_STATE=$(docker inspect --type container ${SERVICE_NAME} --format "{{.State.Running}}")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "Could not get state of the node container"
|
||||||
|
exit 137
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${NODE_SERVICE_STATE}" != "true" ]]; then
|
||||||
|
docker start ${SERVICE_NAME} > /dev/null 2>&1
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "Could not start the node container"
|
||||||
|
exit 137
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
case "${1}" in
|
||||||
|
npm|npx|yarn|yarnpkg|*npm-cli.js*|*npx-cli.js*)
|
||||||
|
docker exec -i ${SERVICE_NAME} "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
docker exec -i ${SERVICE_NAME} node "$@"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
3
node-interpretter/bin/npm
Executable file
3
node-interpretter/bin/npm
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
node npm "$@"
|
||||||
3
node-interpretter/bin/npx
Executable file
3
node-interpretter/bin/npx
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
node npx "$@"
|
||||||
3
node-interpretter/bin/yarn
Executable file
3
node-interpretter/bin/yarn
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
node yarn "$@"
|
||||||
3
node-interpretter/bin/yarnpkg
Executable file
3
node-interpretter/bin/yarnpkg
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
node yarnpkg "$@"
|
||||||
3
node-interpretter/env.shinc.example
Normal file
3
node-interpretter/env.shinc.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PROJECTS_PATH="${HOME}/projects"
|
||||||
|
MOUNT_PATHS=("${HOME}:${HOME}" "${PROJECTS_PATH}:/projects" "/mnt:/mnt")
|
||||||
|
#RESTART=1
|
||||||
129
node-interpretter/run.sh
Executable file
129
node-interpretter/run.sh
Executable file
@ -0,0 +1,129 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
|
||||||
|
|
||||||
|
IMAGE_NAME="yoursystemcz/node-interpretter"
|
||||||
|
IMAGE_VERSION="latest"
|
||||||
|
|
||||||
|
SERVICE_NAME="node-interpretter"
|
||||||
|
|
||||||
|
|
||||||
|
source ${SCRIPT_PATH}/../common.shinc
|
||||||
|
|
||||||
|
#
|
||||||
|
# Project specific variables
|
||||||
|
#
|
||||||
|
|
||||||
|
MOUNT_PATHS=()
|
||||||
|
RESTART=0
|
||||||
|
|
||||||
|
source ${SCRIPT_PATH}/shared.env.shinc 2> /dev/null
|
||||||
|
source ${SCRIPT_PATH}/env.shinc 2> /dev/null
|
||||||
|
|
||||||
|
|
||||||
|
__createLink() {
|
||||||
|
local continue
|
||||||
|
local hostPath="${1}"
|
||||||
|
local binaryLink="${2}"
|
||||||
|
|
||||||
|
if [[ -f "${hostPath}" || -L "${hostPath}" ]]; then
|
||||||
|
__warn "There is already a ${hostPath}, are you sure you want to replace it? [y/(n)]:"
|
||||||
|
read continue
|
||||||
|
if [[ "${continue}" == "y" || "${continue}" == "Y" ]]; then
|
||||||
|
__msg "Linking node binary at ${hostPath}"
|
||||||
|
sudo rm -f "${hostPath}"
|
||||||
|
sudo ln -s "${SCRIPT_PATH}/bin/${binaryLink}" "${hostPath}"
|
||||||
|
[[ $? -ne 0 ]] && __err "Could not link ${binaryLink} binary at ${hostPath}" && return 137
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
__msg "Linking node binary at ${hostPath}"
|
||||||
|
sudo ln -s "${SCRIPT_PATH}/bin/${binaryLink}" "${hostPath}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__deleteLink() {
|
||||||
|
local hostPath="${1}"
|
||||||
|
local binaryLink="${2}"
|
||||||
|
|
||||||
|
if [[ -L "${hostPath}" ]]; then
|
||||||
|
local linkName=$(readlink -f "${hostPath}")
|
||||||
|
if [[ $? -eq 0 && "${linkName}" == "${SCRIPT_PATH}/bin/${binaryLink}" ]]; then
|
||||||
|
__warn "Removing link at ${hostPath}"
|
||||||
|
sudo rm -f ${hostPath}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__createLinks() {
|
||||||
|
__createLink "${NODE_HOST_PATH}" node
|
||||||
|
__createLink "${NODE_HOST_PATH}js" node
|
||||||
|
__createLink "${NPM_HOST_PATH}" npm
|
||||||
|
__createLink "${NPX_HOST_PATH}" npx
|
||||||
|
__createLink "${YARN_HOST_PATH}" yarn
|
||||||
|
__createLink "${YARNPKG_HOST_PATH}" yarnpkg
|
||||||
|
}
|
||||||
|
|
||||||
|
__deleteLinks() {
|
||||||
|
__deleteLink "${NODE_HOST_PATH}" node
|
||||||
|
__deleteLink "${NODE_HOST_PATH}js" node
|
||||||
|
__deleteLink "${NPM_HOST_PATH}" npm
|
||||||
|
__deleteLink "${NPX_HOST_PATH}" npx
|
||||||
|
__deleteLink "${YARN_HOST_PATH}" yarn
|
||||||
|
__deleteLink "${YARNPKG_HOST_PATH}" yarnpkg
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
__createLinks
|
||||||
|
|
||||||
|
local mountPaths=""
|
||||||
|
[[ ${#MOUNT_PATHS[@]} -eq 0 ]] && __err "No MOUNT_PATHS were specified. Please provide these in an .env.shinc file at ${SCRIPT_PATH}/.env.shinc" && return 137
|
||||||
|
for mountPath in ${MOUNT_PATHS[@]}; do
|
||||||
|
mountPaths="${mountPaths} -v ${mountPath}"
|
||||||
|
done
|
||||||
|
|
||||||
|
args="${mountPaths} -v ${SCRIPT_PATH}/configs/${SERVICE_NAME/plex_/}:/config"
|
||||||
|
|
||||||
|
if [[ ${RESTART} -eq 1 ]]; then
|
||||||
|
args="${args} --restart=always"
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker create \
|
||||||
|
--name ${SERVICE_NAME} \
|
||||||
|
--user $(id -u) \
|
||||||
|
-v ${SSH_KEY}:/home/node/.ssh/${SSH_KEY_NAME} \
|
||||||
|
-v ${KNOWN_HOSTS}:/home/node/.ssh/known_hosts \
|
||||||
|
-v npm-cache:/home/node/.npm \
|
||||||
|
-e TZ=Europe/Prague \
|
||||||
|
${args} \
|
||||||
|
--net host \
|
||||||
|
--entrypoint /cmd \
|
||||||
|
${IMAGE_NAME}:${IMAGE_VERSION}
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && __err "Could not create the docker container" && return 137
|
||||||
|
|
||||||
|
docker start ${SERVICE_NAME} && \
|
||||||
|
docker exec --user 0 ${SERVICE_NAME} mkdir -p /usr/local/lib/node_modules && \
|
||||||
|
docker exec --user 0 ${SERVICE_NAME} chown $(id -u) /usr/local/lib/node_modules && \
|
||||||
|
docker exec --user 0 ${SERVICE_NAME} chown $(id -u) /usr/local/bin
|
||||||
|
}
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
stop
|
||||||
|
|
||||||
|
__msg "Removing container... " 0 no
|
||||||
|
STATUS=$(docker rm ${SERVICE_NAME} 2>&1)
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
__err "${STATUS}"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
__success "[ok]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
__deleteLinks
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
exit $?
|
||||||
12
node-interpretter/shared.env.shinc
Normal file
12
node-interpretter/shared.env.shinc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SSH_KEY="$HOME/.ssh/id_rsa"
|
||||||
|
SSH_KEY_NAME="id_rsa"
|
||||||
|
KNOWN_HOSTS="${HOME}/.ssh/known_hosts"
|
||||||
|
PROJECTS_PATH="${HOME}/projects"
|
||||||
|
|
||||||
|
NODE_HOST_PATH="/usr/local/bin/node"
|
||||||
|
NPM_HOST_PATH="/usr/local/bin/npm"
|
||||||
|
NPX_HOST_PATH="/usr/local/bin/npx"
|
||||||
|
YARN_HOST_PATH="/usr/local/bin/yarn"
|
||||||
|
YARNPKG_HOST_PATH="/usr/local/bin/yarnpkg"
|
||||||
8
node-interpretter/src/Dockerfile
Normal file
8
node-interpretter/src/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
ARG IMAGE_NAME
|
||||||
|
ARG IMAGE_VERSION
|
||||||
|
|
||||||
|
FROM ${IMAGE_NAME}:${IMAGE_VERSION}
|
||||||
|
|
||||||
|
COPY ["./cmd", "/cmd"]
|
||||||
|
|
||||||
|
ENTRYPOINT ["node"]
|
||||||
11
node-interpretter/src/cmd
Executable file
11
node-interpretter/src/cmd
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "Waiting for commands..."
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
sleep 10 &
|
||||||
|
wait
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
Loading…
Reference in New Issue
Block a user