I am setting up a GitLab pipeline for running test. The test are supposed to use MongoDB, so I want to use the GitLab mongo service. This is my .gitlab-ci.yml
:
<code>image: node:18.19-bullseye
services:
- name: mongo:latest
cache:
paths:
- node_modules/
- t-lib/node_modules
- t-api/node_modules
- t-client/node_modules
unit-tests:
script:
- cd t-api
- npm install
- node ./test-db.js
</code>
<code>image: node:18.19-bullseye
services:
- name: mongo:latest
cache:
paths:
- node_modules/
- t-lib/node_modules
- t-api/node_modules
- t-client/node_modules
unit-tests:
script:
- cd t-api
- npm install
- node ./test-db.js
</code>
image: node:18.19-bullseye
services:
- name: mongo:latest
cache:
paths:
- node_modules/
- t-lib/node_modules
- t-api/node_modules
- t-client/node_modules
unit-tests:
script:
- cd t-api
- npm install
- node ./test-db.js
and this is the ./test-db.js
:
<code>import {MongoClient} from 'mongodb';
const url = `mongodb://mongo:27017`;
MongoClient.connect(url, function (err, client) {
if (err) {
console.error(err);
return;
}
console.log("Connected successfully to server");
client.close();
});
</code>
<code>import {MongoClient} from 'mongodb';
const url = `mongodb://mongo:27017`;
MongoClient.connect(url, function (err, client) {
if (err) {
console.error(err);
return;
}
console.log("Connected successfully to server");
client.close();
});
</code>
import {MongoClient} from 'mongodb';
const url = `mongodb://mongo:27017`;
MongoClient.connect(url, function (err, client) {
if (err) {
console.error(err);
return;
}
console.log("Connected successfully to server");
client.close();
});
And this is the output from the GitLab pipeline:
<code>Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:37
Using Docker executor with image node:18.19-bullseye ...
Starting service mongo:latest ...
Pulling docker image mongo:latest ...
Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image node:18.19-bullseye ...
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
Preparing environment
00:05
Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/toxicstartup/toxic/.git/
Created fresh repository.
Checking out b4387de2 as detached HEAD (ref is small-improvements)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Restoring cache
00:01
Checking cache for default-non_protected...
WARNING: file does not exist
Failed to extract cache
Executing "step_script" stage of the job script
00:53
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
$ cd t-api
$ npm install
added 749 packages, and audited 751 packages in 22s
81 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
$ node ./test-db.js
/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278
const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongo:27017' => ServerDescription {
address: 'mongo:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 318481,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20)
at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22)
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd76:5338:4685:1:0:242:ac11:3',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.19.1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
</code>
<code>Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:37
Using Docker executor with image node:18.19-bullseye ...
Starting service mongo:latest ...
Pulling docker image mongo:latest ...
Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image node:18.19-bullseye ...
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
Preparing environment
00:05
Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/toxicstartup/toxic/.git/
Created fresh repository.
Checking out b4387de2 as detached HEAD (ref is small-improvements)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Restoring cache
00:01
Checking cache for default-non_protected...
WARNING: file does not exist
Failed to extract cache
Executing "step_script" stage of the job script
00:53
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
$ cd t-api
$ npm install
added 749 packages, and audited 751 packages in 22s
81 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
$ node ./test-db.js
/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278
const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongo:27017' => ServerDescription {
address: 'mongo:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 318481,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20)
at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22)
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd76:5338:4685:1:0:242:ac11:3',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.19.1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
</code>
Running with gitlab-runner 17.0.0~pre.88.g761ae5dd (761ae5dd)
on green-6.saas-linux-small-amd64.runners-manager.gitlab.com/default YKxHNyexq, system ID: s_a201ab37b78a
Preparing the "docker+machine" executor
00:37
Using Docker executor with image node:18.19-bullseye ...
Starting service mongo:latest ...
Pulling docker image mongo:latest ...
Using docker image sha256:a31b196b207d768e78f2af331869e91d13443f691080d3b93e8009a53391eeaa for mongo:latest with digest mongo@sha256:54996a559c724c726a31fb8131e1c9088a05f7e531760e2897212389bbf20fed ...
Waiting for services to be up and running (timeout 30 seconds)...
Pulling docker image node:18.19-bullseye ...
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
Preparing environment
00:05
Running on runner-ykxhnyexq-project-37348985-concurrent-0 via runner-ykxhnyexq-s-l-s-amd64-1722786860-9ab4b67c...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/toxicstartup/toxic/.git/
Created fresh repository.
Checking out b4387de2 as detached HEAD (ref is small-improvements)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Restoring cache
00:01
Checking cache for default-non_protected...
WARNING: file does not exist
Failed to extract cache
Executing "step_script" stage of the job script
00:53
Using docker image sha256:01f146fd9fbc62c824fee6dc213dc42bd955b4cb2d6266a4d86e6f3b82930e24 for node:18.19-bullseye with digest node@sha256:ba50a7e017c566a0d6a5af7008f3f4e61cc5a4114f441e5e486b592d1c361567 ...
$ cd t-api
$ npm install
added 749 packages, and audited 751 packages in 22s
81 packages are looking for funding
run `npm fund` for details
5 high severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
$ node ./test-db.js
/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278
const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
^
MongoServerSelectionError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at Timeout._onTimeout (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/sdam/topology.js:278:38)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'mongo:27017' => ServerDescription {
address: 'mongo:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 318481,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at connectionFailureError (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:367:20)
at Socket.<anonymous> (/builds/toxicstartup/toxic/t-api/node_modules/mongodb/lib/cmap/connect.js:290:22)
at Object.onceWrapper (node:events:632:26)
at Socket.emit (node:events:517:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED fd76:5338:4685:1:0:242:ac11:3:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: 'fd76:5338:4685:1:0:242:ac11:3',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
Node.js v18.19.1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
Seems like the alias mongo has been replaced by IPv6 (which I assume means the service has started successfully), but the connection does not work. Any ideas how to make this work?