Skip to content

Commit de38678

Browse files
committed
[docker] Plugins installation
1 parent 8c601e2 commit de38678

File tree

5 files changed

+66
-64
lines changed

5 files changed

+66
-64
lines changed

Diff for: Dockerfile-api

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM node:8.16
22

3+
ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,enterpriseinfo,logger,systemlogs,errorlogs,populator,reports,crashes,push,star-rating,slipping-away-users,compare,server-stats,dbviewer,assistant,plugin-upload,times-of-day,compliance-hub,video-intelligence-monetization,alerts,onboarding
34
ARG COUNTLY_CONFIG_API_MONGODB_HOST=localhost
45
ARG COUNTLY_CONFIG_FRONTEND_MONGODB_HOST=localhost
56

@@ -8,23 +9,33 @@ ARG COUNTLY_CONFIG_FRONTEND_MONGODB_HOST=localhost
89
ENV TINI_VERSION v0.18.0
910
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
1011
RUN chmod +x /tini
11-
USER 1001
1212

1313
ENTRYPOINT ["/tini", "-v", "--"]
1414

15-
## Required by both images
16-
RUN apt-get update && apt-get -y install sendmail
15+
RUN apt-get update && apt-get -y install sendmail sqlite3 && \
16+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
17+
18+
# Required by push plugin
19+
RUN git clone https://github.com/nghttp2/nghttp2.git $DIR/nghttp2 && \
20+
cd $DIR/nghttp2 && \
21+
git checkout tags/v1.30.0 && \
22+
autoreconf -i && automake && autoconf && ./configure --disable-examples --disable-app && make && make install
1723

1824
# Setup Countly
19-
ENV CLY_DOCKER 1
25+
ENV COUNTLY_DOCKER 1
26+
ENV COUNTLY_DEFAULT_PLUGINS="${COUNTLY_PLUGINS}"
2027

2128
## The files
29+
RUN mkdir /opt/countly && chown 1001:1001 /opt/countly
30+
USER 1001
2231
WORKDIR /opt/countly
2332
COPY --chown=1001 . .
33+
HEALTHCHECK --start-period=120s CMD curl --fail http://localhost:3001/ping || exit 1
2434

25-
## API dependencies
26-
RUN bin/docker/install-api.sh
27-
28-
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
35+
## API runtime dependencies
36+
RUN cp -n api/config.sample.js api/config.js && \
37+
cp -n frontend/express/config.sample.js frontend/express/config.js && \
38+
HOME=/tmp npm install && \
39+
rm -rf /tmp/*
2940

3041
CMD ["/opt/countly/bin/docker/cmd.sh", "api"]

Diff for: Dockerfile-frontend

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM node:8.16
22

3+
ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,enterpriseinfo,logger,systemlogs,errorlogs,populator,reports,crashes,push,star-rating,slipping-away-users,compare,server-stats,dbviewer,assistant,plugin-upload,times-of-day,compliance-hub,video-intelligence-monetization,alerts,onboarding
34
ARG COUNTLY_CONFIG_API_MONGODB_HOST=localhost
45
ARG COUNTLY_CONFIG_FRONTEND_MONGODB_HOST=localhost
56

@@ -8,23 +9,27 @@ ARG COUNTLY_CONFIG_FRONTEND_MONGODB_HOST=localhost
89
ENV TINI_VERSION v0.18.0
910
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
1011
RUN chmod +x /tini
11-
USER 1001
1212

1313
ENTRYPOINT ["/tini", "-v", "--"]
1414

15-
## Required by both images
16-
RUN apt update && apt -y install sendmail
15+
RUN apt-get update && apt-get -y install sendmail && \
16+
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1717

1818
# Setup Countly
19-
ENV CLY_DOCKER 1
19+
ENV COUNTLY_DOCKER 1
20+
ENV COUNTLY_DEFAULT_PLUGINS="${COUNTLY_PLUGINS}"
2021

2122
## The files
23+
RUN mkdir /opt/countly && chown 1001:1001 /opt/countly
24+
USER 1001
2225
WORKDIR /opt/countly
2326
COPY --chown=1001 . .
27+
HEALTHCHECK --start-period=120s CMD curl --fail http://localhost:6001/ping || exit 1
2428

25-
## API dependencies
26-
RUN bin/docker/install-frontend.sh
27-
28-
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
29+
RUN cp -n frontend/express/public/javascripts/countly/countly.config.sample.js frontend/express/public/javascripts/countly/countly.config.js && \
30+
cp -n frontend/express/config.sample.js frontend/express/config.js && \
31+
cp -n api/config.sample.js api/config.js && \
32+
HOME=/tmp npm install && \
33+
rm -rf /tmp/*
2934

3035
CMD ["/opt/countly/bin/docker/cmd.sh", "frontend"]

Diff for: bin/docker/cmd.sh

100644100755
+34-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
#!/bin/bash
22

3-
if [ -z "$CLY_PLUGINS" ]; then
4-
if [ -f $DIR/../../plugins/plugins.json ]; then
5-
echo "[docker] Using existing plugins.json"
3+
CMD=$1
4+
5+
if [ -f /opt/countly/plugins/plugins.json ]; then
6+
echo "[docker] Plugins have been built, skipping rebuilding"
7+
else
8+
if [ -z "$COUNTLY_PLUGINS" ]; then
9+
COUNTLY_PLUGINS="$COUNTLY_DEFAULT_PLUGINS"
10+
echo "[docker] Using default plguin list: $COUNTLY_PLUGINS"
611
else
7-
echo "[docker] ERROR: neither CLY_PLUGINS env var, or plugins.json exists"
8-
exit 1
12+
echo "[docker] Using COUNTLY_PLUGINS: $COUNTLY_PLUGINS"
913
fi
10-
else
11-
echo "[docker] Using CLY_PLUGINS: $CLY_PLUGINS"
12-
a=($(echo "$CLY_PLUGINS" | tr ',' '\n'))
13-
echo "[docker] Written plugins:"
14-
printf %s\\n "${a[@]}"|sed 's/["\]/\\&/g;s/.*/"&"/;1s/^/[/;$s/$/]/;$!s/$/,/'
15-
printf %s\\n "${a[@]}"|sed 's/["\]/\\&/g;s/.*/"&"/;1s/^/[/;$s/$/]/;$!s/$/,/' > $DIR/../../plugins/plugins.json
14+
15+
a=$(echo "$COUNTLY_PLUGINS" | tr ',' '\n')
16+
printf %s\\n "${a[@]}"|sed 's/["\]/\\&/g;s/.*/"&"/;1s/^/[/;$s/$/]/;$!s/$/,/' > /opt/countly/plugins/plugins.json
17+
18+
while read -r plugin; do
19+
echo "[docker] Installing ${plugin}:"
20+
(cd "/opt/countly/plugins/$plugin" && HOME=/tmp npm install)
21+
/usr/local/bin/node "/opt/countly/plugins/$plugin/install.js"
22+
echo "[docker] Done installing ${plugin}."
23+
done <<< "$a"
1624
fi
1725

18-
bash $DIR/../scripts/countly.install.plugins.sh
26+
case "$CMD" in
27+
"api" )
28+
exec /usr/local/bin/node /opt/countly/api/api.js
29+
;;
1930

20-
if [ "$0" -eq "api" ]; then
21-
node ../../api/api.js
22-
elif [ "$0" -eq "frontend" ]; then
23-
grunt dist-all
24-
node ../../frontend/express/app.js
25-
else
26-
echo "[docker] First cmd.sh argument must equal 'api' or 'frontend', but was $0"
27-
exit 1
28-
elif
31+
"frontend" )
32+
npx grunt dist-all
33+
exec /usr/local/bin/node /opt/countly/frontend/express/app.js
34+
;;
35+
36+
* )
37+
# Run custom command. Thanks to this line we can still use
38+
# "docker run our_image /bin/bash" and it will work
39+
exec $CMD ${@:2}
40+
;;
41+
esac

Diff for: bin/docker/install-api.sh

-16
This file was deleted.

Diff for: bin/docker/install-frontend.sh

-11
This file was deleted.

0 commit comments

Comments
 (0)