Skip to content

Commit b5e20c8

Browse files
committed
Added a custom entrypoint to set the max-old-size as this is a low memory nodejs environment
1 parent a6c05b6 commit b5e20c8

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ RUN ./node_modules/.bin/grunt test
1010
RUN ./node_modules/.bin/grunt build
1111

1212
FROM mhart/alpine-node:${NODEJS_VERSION} as deploy
13+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
14+
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
15+
1316
WORKDIR /app
1417
RUN addgroup nonroot && \
1518
adduser -D nonroot -G nonroot && \

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
context: '.'
77
args:
88
NODEJS_VERSION: 14.4.0
9-
command: 'node lib/apps/controller/index.js'
9+
command: 'controller'
1010
environment:
1111
PORT: '80' # Run on port 80 locally in docker-compose to replicate kubernetes service object port magenting
1212
hostname: 'controller'
@@ -25,7 +25,7 @@ services:
2525

2626
agent:
2727
image: stono/kconmon:${VERSION:-latest}
28-
command: 'node lib/apps/agent/index.js'
28+
command: 'agent'
2929
environment:
3030
PORT: '80' # Run on port 80 locally in docker-compose to replicate kubernetes service object port magenting
3131
hostname: 'agent'

entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ ! -z "$CONTAINER_RESOURCE_REQUEST_MEMORY" ]; then
5+
export MAX_OLD_SPACE=$(/usr/bin/original_node -pe 'Math.round(process.env.CONTAINER_RESOURCE_REQUEST_MEMORY / 1024 / 1024 / 100 * 75)')
6+
ADDITIONAL_ARGS="--max_old_space_size=$MAX_OLD_SPACE"
7+
fi
8+
9+
if [ "$1" = "agent" ]; then
10+
TARGET_APP="/app/lib/apps/agent/index.js"
11+
elif [ "$1" = "controller" ]; then
12+
TARGET_APP="/app/lib/apps/controller/index.js"
13+
else
14+
echo "Unknown command: $1"
15+
exit 1
16+
fi
17+
18+
# Pass through to the original node script
19+
exec /usr/bin/node $ADDITIONAL_ARGS $TARGET_APP

helmfile/charts/kconmon/templates/agent/daemonset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ spec:
7474
image: "{{ required "Please specify the docker image" .Values.docker.image }}:{{ .Values.docker.tag | default .Chart.Version }}"
7575
imagePullPolicy: IfNotPresent
7676
args:
77-
- node
78-
- lib/apps/agent/index.js
77+
- /usr/local/bin/entrypoint.sh
78+
- agent
7979
env:
8080
- name: CONTAINER_RESOURCE_REQUEST_MEMORY
8181
valueFrom:

helmfile/charts/kconmon/templates/controller/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ spec:
3939
image: "{{ required "Please specify the docker image" .Values.docker.image }}:{{ .Values.docker.tag | default .Chart.Version }}"
4040
imagePullPolicy: IfNotPresent
4141
args:
42-
- node
43-
- lib/apps/controller/index.js
42+
- /usr/local/bin/entrypoint.sh
43+
- controller
4444
env:
4545
- name: CONTAINER_RESOURCE_REQUEST_MEMORY
4646
valueFrom:

0 commit comments

Comments
 (0)