Skip to content

Commit a4b4caa

Browse files
committed
Merge conflicts
2 parents 35d28ec + c23b57b commit a4b4caa

9 files changed

+145
-60
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Version xx.xx.xx
22

3+
Fixes:
4+
- [gridfs] fixes for moving to Promises
5+
36
Dependencies:
47
- Bump sass from 1.81.0 to 1.83.1
58
- Bump countly-sdk-nodejs from 24.10.0 to 24.10.1

Dockerfile-api

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:hydrogen-bullseye-slim
1+
FROM node:iron-bookworm-slim
22

33
ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,logger,systemlogs,populator,reports,crashes,push,star-rating,slipping-away-users,compare,server-stats,dbviewer,times-of-day,compliance-hub,alerts,onboarding,consolidate,remote-config,hooks,dashboards,sdk,data-manager,guides
44
# Countly Enterprise:
@@ -25,15 +25,14 @@ COPY . .
2525

2626
# install required dependencies which slim image doesn't have
2727
RUN apt-get update && \
28-
apt-get install -y iputils-ping procps net-tools telnet apt-transport-https curl wget git python2 make gcc g++ unzip && \
29-
ln -s /usr/bin/python2.7 /usr/bin/python
28+
apt-get install -y iputils-ping procps net-tools telnet apt-transport-https curl wget git make gcc g++ unzip xz-utils
3029

3130
RUN apt-get update && \
3231
apt-get upgrade -y && \
3332
cd /usr/src && \
3433
wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tar.xz && \
3534
tar -xf Python-3.8.12.tar.xz && \
36-
apt-get install -y build-essential sudo zlib1g-dev libssl1.1 libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev && \
35+
apt-get install -y build-essential sudo zlib1g-dev libssl3 libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev && \
3736
cd Python-3.8.12 && \
3837
./configure --enable-optimizations --enable-shared && \
3938
make && \
@@ -51,14 +50,15 @@ RUN curl -s -L -o /tmp/tini.deb "https://github.com/krallin/tini/releases/downlo
5150
# preinstall
5251
cp -n ./api/config.sample.js ./api/config.js && \
5352
cp -n ./frontend/express/config.sample.js ./frontend/express/config.js && \
53+
HOME=/tmp npm install -g npm@latest && \
5454
HOME=/tmp npm install --unsafe-perm=true --allow-root && \
5555
HOME=/tmp npm install argon2 --build-from-source --unsafe-perm=true --allow-root && \
5656
./bin/docker/preinstall.sh && \
5757
bash /opt/countly/bin/scripts/detect.init.sh && \
5858
\
5959
# cleanup & chown
6060
npm remove -y --no-save mocha nyc should supertest && \
61-
apt-get remove -y git gcc g++ make automake autoconf libtool pkg-config unzip sqlite3 && \
61+
apt-get remove -y git gcc g++ make automake autoconf libtool pkg-config unzip sqlite3 wget && \
6262
apt-get install -y libgbm-dev libgbm1 gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils && \
6363
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
6464
rm -rf test /tmp/* /tmp/.??* /var/tmp/* /var/tmp/.??* /var/log/* /root/.npm && \

Dockerfile-centos-api

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RUN yum update -y
3434
RUN curl -s -L -o /tmp/tini.rpm "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.rpm" && \
3535
rpm -i /tmp/tini.rpm && \
3636
\
37-
curl -sL https://rpm.nodesource.com/setup_18.x | bash - && \
37+
curl -sL https://rpm.nodesource.com/setup_20.x | bash - && \
3838
yum install -y nodejs python3.8 python2 python38-libs python38-devel python38-pip nss libdrm libgbm cyrus-sasl* && \
3939
ln -s /usr/bin/node /usr/bin/nodejs && \
4040
unlink /usr/bin/python3 && \
@@ -53,6 +53,7 @@ RUN curl -s -L -o /tmp/tini.rpm "https://github.com/krallin/tini/releases/downlo
5353
# preinstall
5454
cp -n ./api/config.sample.js ./api/config.js && \
5555
cp -n ./frontend/express/config.sample.js ./frontend/express/config.js && \
56+
HOME=/tmp npm install -g npm@latest && \
5657
HOME=/tmp npm install --unsafe-perm=true --allow-root && \
5758
HOME=/tmp npm install argon2 --build-from-source --unsafe-perm=true --allow-root && \
5859
./bin/docker/preinstall.sh && \

Dockerfile-centos-frontend

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN yum update -y
3232
RUN curl -s -L -o /tmp/tini.rpm "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.rpm" && \
3333
rpm -i /tmp/tini.rpm && \
3434
\
35-
curl -sL https://rpm.nodesource.com/setup_18.x | bash - && \
35+
curl -sL https://rpm.nodesource.com/setup_20.x | bash - && \
3636
yum install -y nodejs python3.8 python2 python38-libs python38-devel python38-pip nss libdrm libgbm cyrus-sasl* && \
3737
ln -s /usr/bin/node /usr/bin/nodejs && \
3838
unlink /usr/bin/python3 && \
@@ -52,6 +52,7 @@ RUN curl -s -L -o /tmp/tini.rpm "https://github.com/krallin/tini/releases/downlo
5252
cp -n ./frontend/express/public/javascripts/countly/countly.config.sample.js ./frontend/express/public/javascripts/countly/countly.config.js && \
5353
cp -n ./frontend/express/config.sample.js ./frontend/express/config.js && \
5454
cp -n ./api/config.sample.js ./api/config.js && \
55+
HOME=/tmp npm install -g npm@latest && \
5556
HOME=/tmp npm install --unsafe-perm=true --allow-root && \
5657
HOME=/tmp npm install argon2 --build-from-source --unsafe-perm=true --allow-root && \
5758
./bin/docker/preinstall.sh && \

Dockerfile-core

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ RUN useradd -r -M -U -d /opt/countly -s /bin/false countly && \
4040
gcc g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev \
4141
libevent-dev libjansson-dev libjemalloc-dev cython python3-dev python-setuptools && \
4242
# node
43-
wget -qO- https://deb.nodesource.com/setup_18.x | bash - && \
43+
wget -qO- https://deb.nodesource.com/setup_20.x | bash - && \
4444
# data_migration (mongo clients)
4545
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - && \
4646
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list && \

Dockerfile-frontend

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:hydrogen-bullseye-slim
1+
FROM node:iron-bookworm-slim
22

33
ARG COUNTLY_PLUGINS=mobile,web,desktop,plugins,density,locale,browser,sources,views,logger,systemlogs,populator,reports,crashes,push,star-rating,slipping-away-users,compare,server-stats,dbviewer,times-of-day,compliance-hub,alerts,onboarding,consolidate,remote-config,hooks,dashboards,sdk,data-manager,guides
44
# Countly Enterprise:
@@ -21,15 +21,14 @@ WORKDIR /opt/countly
2121
COPY . .
2222
# install required dependencies which slim image doesn't have
2323
RUN apt-get update && \
24-
apt-get install -y iputils-ping net-tools telnet apt-transport-https procps curl wget git python2 make gcc g++ unzip && \
25-
ln -s /usr/bin/python2.7 /usr/bin/python
24+
apt-get install -y iputils-ping net-tools telnet apt-transport-https procps curl wget git make gcc g++ unzip xz-utils
2625

2726
RUN apt-get update && \
2827
apt-get upgrade -y && \
2928
cd /usr/src && \
3029
wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tar.xz && \
3130
tar -xf Python-3.8.12.tar.xz && \
32-
apt-get install -y build-essential sudo zlib1g-dev libssl1.1 libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev && \
31+
apt-get install -y build-essential sudo zlib1g-dev libssl3 libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev && \
3332
cd Python-3.8.12 && \
3433
./configure --enable-optimizations --enable-shared && \
3534
make && \
@@ -48,6 +47,7 @@ RUN curl -s -L -o /tmp/tini.deb "https://github.com/krallin/tini/releases/downlo
4847
cp -n ./api/config.sample.js ./api/config.js && \
4948
cp -n ./frontend/express/config.sample.js ./frontend/express/config.js && \
5049
cp -n ./frontend/express/public/javascripts/countly/countly.config.sample.js ./frontend/express/public/javascripts/countly/countly.config.js && \
50+
HOME=/tmp npm install -g npm@latest && \
5151
HOME=/tmp npm install --unsafe-perm=true --allow-root && \
5252
HOME=/tmp npm install argon2 --build-from-source --unsafe-perm=true --allow-root && \
5353
./bin/docker/preinstall.sh && \
@@ -56,7 +56,7 @@ RUN curl -s -L -o /tmp/tini.deb "https://github.com/krallin/tini/releases/downlo
5656
\
5757
# cleanup & chown
5858
npm remove -y --no-save mocha nyc should supertest puppeteer && \
59-
apt-get remove -y git gcc g++ make automake autoconf libtool pkg-config unzip sqlite3 && \
59+
apt-get remove -y git gcc g++ make automake autoconf libtool pkg-config unzip sqlite3 wget && \
6060
apt-get autoremove -y && \
6161
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
6262
rm -rf test /tmp/* /tmp/.??* /var/tmp/* /var/tmp/.??* /var/log/* /root/.npm && \

api/utils/countlyFs.js

+71-42
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ countlyFs.gridfs = {};
6868
**/
6969
function beforeSave(category, filename, options, callback, done) {
7070
log.d("checking file", filename);
71-
ob.getId(category, filename, function(err, res) {
71+
ob.getId(category, filename, async function(err, res) {
7272
log.d("file state", filename, err, res);
7373
if (options.forceClean) {
7474
ob.clearFile(category, filename, done);
@@ -80,15 +80,20 @@ countlyFs.gridfs = {};
8080
else if (options.writeMode === "overwrite") {
8181
var bucket = new GridFSBucket(db, { bucketName: category });
8282
log.d("deleting file", filename);
83-
bucket.delete(res, function(error) {
84-
log.d("deleted", filename, error);
85-
if (!error) {
86-
setTimeout(done, 1);
87-
}
88-
else if (callback) {
89-
callback(error);
90-
}
91-
});
83+
let errHandle = null;
84+
try {
85+
await bucket.delete(res);
86+
}
87+
catch (error) {
88+
errHandle = error;
89+
}
90+
log.d("deleted", filename, errHandle);
91+
if (!errHandle) {
92+
setTimeout(done, 1);
93+
}
94+
else if (callback) {
95+
callback(errHandle);
96+
}
9297
}
9398
else {
9499
if (callback) {
@@ -116,6 +121,7 @@ countlyFs.gridfs = {};
116121
* });
117122
*/
118123
ob.getId = function(category, filename, callback) {
124+
log.d("getId", category, filename);
119125
db.collection(category + ".files").findOne({ filename: filename }, {_id: 1}, function(err, res) {
120126
if (callback) {
121127
callback(err, (res && res._id) ? res._id : false);
@@ -144,6 +150,7 @@ countlyFs.gridfs = {};
144150
if (!options) {
145151
options = {};
146152
}
153+
log.d("exists", category, dest, options);
147154
var query = {};
148155
if (options.id) {
149156
query._id = options.id;
@@ -184,7 +191,7 @@ countlyFs.gridfs = {};
184191
if (!options) {
185192
options = {};
186193
}
187-
194+
log.d("saveFile", category, dest, source, options);
188195
var filename = dest.split(path.sep).pop();
189196
beforeSave(category, filename, options, callback, function() {
190197
save(category, filename, fs.createReadStream(source), options, callback);
@@ -218,6 +225,7 @@ countlyFs.gridfs = {};
218225
if (!options) {
219226
options = {};
220227
}
228+
log.d("saveData", category, dest, typeof data, options);
221229
beforeSave(category, filename, options, callback, function() {
222230
var readStream = new Readable;
223231
readStream.push(data);
@@ -253,6 +261,7 @@ countlyFs.gridfs = {};
253261
if (!options) {
254262
options = {};
255263
}
264+
log.d("saveStream", category, dest, typeof readStream, options);
256265
beforeSave(category, filename, options, callback, function() {
257266
save(category, filename, readStream, options, callback);
258267
});
@@ -271,7 +280,7 @@ countlyFs.gridfs = {};
271280
* console.log("Finished", err);
272281
* });
273282
*/
274-
ob.rename = function(category, dest, source, options, callback) {
283+
ob.rename = async function(category, dest, source, options, callback) {
275284
var newname = dest.split(path.sep).pop();
276285
var oldname = source.split(path.sep).pop();
277286
if (typeof options === "function") {
@@ -281,25 +290,35 @@ countlyFs.gridfs = {};
281290
if (!options) {
282291
options = {};
283292
}
284-
293+
log.d("rename", category, dest, source, options);
285294
if (options.id) {
286295
let bucket = new GridFSBucket(db, { bucketName: category });
287-
bucket.rename(options.id, newname, function(error) {
288-
if (callback) {
289-
callback(error);
290-
}
291-
});
296+
let errHandle = null;
297+
try {
298+
await bucket.rename(options.id, newname);
299+
}
300+
catch (error) {
301+
errHandle = error;
302+
}
303+
if (callback) {
304+
callback(errHandle);
305+
}
292306
}
293307
else {
294-
db.collection(category + ".files").findOne({ filename: oldname }, {_id: 1}, function(err, res) {
308+
db.collection(category + ".files").findOne({ filename: oldname }, {_id: 1}, async function(err, res) {
295309
if (!err) {
296310
if (res && res._id) {
297311
let bucket = new GridFSBucket(db, { bucketName: category });
298-
bucket.rename(res._id, newname, function(error) {
299-
if (callback) {
300-
callback(error);
301-
}
302-
});
312+
let errHandle = null;
313+
try {
314+
await bucket.rename(res._id, newname);
315+
}
316+
catch (error) {
317+
errHandle = error;
318+
}
319+
if (callback) {
320+
callback(errHandle);
321+
}
303322
}
304323
else {
305324
if (callback) {
@@ -337,7 +356,7 @@ countlyFs.gridfs = {};
337356
if (!options) {
338357
options = {};
339358
}
340-
359+
log.d("deleteFile", category, dest, options);
341360
if (options.id) {
342361
ob.deleteFileById(category, options.id, callback);
343362
}
@@ -372,13 +391,19 @@ countlyFs.gridfs = {};
372391
* console.log("Finished", err);
373392
* });
374393
*/
375-
ob.deleteAll = function(category, dest, callback) {
394+
ob.deleteAll = async function(category, dest, callback) {
395+
log.d("deleteAll", category, dest);
376396
var bucket = new GridFSBucket(db, { bucketName: category });
377-
bucket.drop(function(error) {
378-
if (callback) {
379-
callback(error);
380-
}
381-
});
397+
let errHandle = null;
398+
try {
399+
await bucket.drop();
400+
}
401+
catch (error) {
402+
errHandle = error;
403+
}
404+
if (callback) {
405+
callback(errHandle);
406+
}
382407
};
383408

384409
/**
@@ -403,7 +428,7 @@ countlyFs.gridfs = {};
403428
if (!options) {
404429
options = {};
405430
}
406-
431+
log.d("getStream", category, dest, options);
407432
if (callback) {
408433
if (options.id) {
409434
ob.getStreamById(category, options.id, callback);
@@ -436,7 +461,7 @@ countlyFs.gridfs = {};
436461
if (!options) {
437462
options = {};
438463
}
439-
464+
log.d("getData", category, dest, options);
440465
if (options.id) {
441466
ob.getDataById(category, options.id, callback);
442467
}
@@ -482,7 +507,7 @@ countlyFs.gridfs = {};
482507
if (!options) {
483508
options = {};
484509
}
485-
510+
log.d("getSize", category, dest, options);
486511
var query = {};
487512
if (options.id) {
488513
query._id = options.id;
@@ -517,7 +542,7 @@ countlyFs.gridfs = {};
517542
if (!options) {
518543
options = {};
519544
}
520-
545+
log.d("getStats", category, dest, options);
521546
var query = {};
522547
if (options.id) {
523548
query._id = options.id;
@@ -554,6 +579,7 @@ countlyFs.gridfs = {};
554579
* });
555580
*/
556581
ob.getDataById = function(category, id, callback) {
582+
log.d("getDataById", category, id);
557583
var bucket = new GridFSBucket(db, { bucketName: category });
558584
var downloadStream = bucket.openDownloadStream(id);
559585
downloadStream.on('error', function(error) {
@@ -585,6 +611,7 @@ countlyFs.gridfs = {};
585611
* });
586612
*/
587613
ob.getStreamById = function(category, id, callback) {
614+
log.d("getStreamById", category, id);
588615
if (callback) {
589616
var bucket = new GridFSBucket(db, { bucketName: category });
590617
callback(null, bucket.openDownloadStream(id));
@@ -602,17 +629,17 @@ countlyFs.gridfs = {};
602629
* });
603630
*/
604631
ob.deleteFileById = async function(category, id, callback) {
632+
log.d("deleteFileById", category, id);
605633
var bucket = new GridFSBucket(db, { bucketName: category });
634+
let errHandle = null;
606635
try {
607636
await bucket.delete(id);
608-
if (callback) {
609-
callback(null);
610-
}
611637
}
612-
catch (ee) {
613-
if (callback) {
614-
callback(ee);
615-
}
638+
catch (error) {
639+
errHandle = error;
640+
}
641+
if (callback) {
642+
callback(errHandle);
616643
}
617644
};
618645

@@ -627,6 +654,7 @@ countlyFs.gridfs = {};
627654
* });
628655
*/
629656
ob.clearFile = function(category, filename, callback) {
657+
log.d("clearFile", category, filename);
630658
db.collection(category + ".files").deleteMany({ filename: filename }, function(err1, res1) {
631659
log.d("deleting files", category, { filename: filename }, err1, res1 && res1.result);
632660
db.collection(category + ".chunks").deleteMany({ files_id: filename }, function(err2, res2) {
@@ -643,6 +671,7 @@ countlyFs.gridfs = {};
643671
* @param {function} callback - function called when files found or query errored, providing error object as first param and a list of filename, creation date and size as secondas second
644672
*/
645673
ob.listFiles = function(category, callback) {
674+
log.d("listFiles", category);
646675
const bucket = new GridFSBucket(db, { bucketName: category });
647676
bucket.find().toArray()
648677
.then((records) => callback(

0 commit comments

Comments
 (0)