-
Notifications
You must be signed in to change notification settings - Fork 0
/
docked-node.sh
executable file
·49 lines (43 loc) · 1022 Bytes
/
docked-node.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
DOCKED_NODE_IMAGE="${DOCKED_NODE_IMAGE:-node}"
DOCKED_NODE_PRE_RUN=""
if [ -n "$DOCKED_NODE_PRE" ]; then
DOCKED_NODE_PRE_RUN="RUN $DOCKED_NODE_PRE"
fi
clean() {
rm -f .docker-node-Dockerfile
}
if [ ! -f package.json ]; then
>&2 echo "No package.json file found."
exit 1
fi
NO_DOCKERIGNORE=false
if [ ! -f .dockerignore ]; then
NO_DOCKERIGNORE=true
cat > .dockerignore <<EOF
.git
node_modules
**/node_modules
EOF
fi
rm -f .docked-node-image
>&2 echo "Building docker image..."
cat > .docker-node-Dockerfile <<EOF
FROM ${DOCKED_NODE_IMAGE}
WORKDIR /app
COPY package.json .
RUN npm install
RUN mv node_modules /
COPY . .
${DOCKED_NODE_PRE_RUN}
CMD node .
EOF
trap clean EXIT
docker build --file .docker-node-Dockerfile --iidfile .docked-node-image . 1>&2
if $NO_DOCKERIGNORE; then
rm .dockerignore
fi
DOCKER_IMAGE_ID=$(cat .docked-node-image)
>&2 echo "Running node inside docker container ${DOCKER_IMAGE_ID}..."
>&2 echo ""
docker run --interactive --tty --rm "$DOCKER_IMAGE_ID" "$@"