Comments (18)
@akoskm @eBsowka Yeah, I remember why I never merged the docker-network
branch: the GitHub Actions runner does not properly clean up the network used to connect all containers.
There are two ways of networking when using docker actions on a self-hosted runners:
- you run your tests directly on the runner
- you can connect to dependencies (like MongoDB) using
localhost
as the host address
- you can connect to dependencies (like MongoDB) using
- you run your tests in another docker container
- the runner creates a dedicated Docker network for all containers configured in the action’s workflow file
- the runner then connects all containers to this dedicated network
- your test can then use
localhost
to connect to dependencies - third-party actions (like this MongoDB container action) must also connect to the dedicated network
- yet, there’s no step to tell the runner to disconnect third-party container actions to disconnect from the network or clean themselfs up when tearing down
While writing this, I think there’s a solution we can build into this MongoDB action: an input that disconnects the container from the network ensuring that your self-hosted runner can clean up correctly (remove container, remove the network).
from mongodb-github-action.
I made the error from `MongoDB in GitHub Action disappear by cleaning up the docker images on my actions runner machine:
Starting as single-node replica set (in replica set [rs0])
Unable to find image 'mongo:4.2' locally
4.2: Pulling from library/mongo
I'm still getting the same error from the tests.
from mongodb-github-action.
If I mess up the connection string, for example:
- name: Run unit tests
env:
MONGO_URI: mongodb://mongodb/test?replicaSet=rs0
run: |
./version.sh
npm run test-unit
I get a different error:
(node:427) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [Error: getaddrinfo ENOTFOUND mongodb
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
name: 'MongoNetworkError'
}]
from mongodb-github-action.
@akoskm Hey Akos, looks like you're connecting to MongoDB using a Node.js app. Is it the mongodb
package or Mongoose or something else you're using?
Is your app using the provided MONGO_URI "as is" or do you replace/add some other values (Iike auth credentials)?
from mongodb-github-action.
Hey, thanks for the prompt response @marcuspoehls!
I'm using Mongoose to connect to MongoDB. MONGO_URI is used "as is".
This is how my setup was working with services:
.
It's really similar to what you have in your test:
mongodb-github-action/test/replica-set.js
Lines 12 to 19 in 56f4c41
mine goes like this:
await mongoose.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });
where MONGO_URI
is coming from the workflow file.
from mongodb-github-action.
Good you found the test using Mongoose. I remember running into issues with the database connection when using Mongoose and replica sets. You already copied the connection details from the test. That's good. Could you please test whether adding the replica set config to the Mongoose object helps? Maybe it gets overridden in the connection string. But I'm not sure.
from mongodb-github-action.
Tried this, actually, I wrapped my above connect code such as:
before(async function(){
try {
console.log(MONGO_URI);
await mongoose.connect(MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 10000,
replicaSet: 'rs0'
});
app.db = mongoose.connection;
// please ignore these lines, I'm setting up some models like this because 5y ago it seemed like a good idea 😅
require('../../schema/Finish')(app, mongoose);
require('../../schema/Counter')(app, mongoose);
} catch (err) {
console.log(err)
}
});
and here's the error I'm getting:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:42069
at NativeConnection.Connection.openUri (/__w/10log-base/10log-base/node_modules/mongoose/lib/connection.js:800:32)
at /__w/10log-base/10log-base/node_modules/mongoose/lib/index.js:342:10
at /__w/10log-base/10log-base/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (/__w/10log-base/10log-base/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose.connect (/__w/10log-base/10log-base/node_modules/mongoose/lib/index.js:341:10)
at Context.<anonymous> (/__w/10log-base/10log-base/test/unit/index.js:16:22)
at callFn (/__w/10log-base/10log-base/node_modules/mocha/lib/runnable.js:358:21)
at Hook.Runnable.run (/__w/10log-base/10log-base/node_modules/mocha/lib/runnable.js:346:5)
at next (/__w/10log-base/10log-base/node_modules/mocha/lib/runner.js:454:10)
at Immediate.<anonymous> (/__w/10log-base/10log-base/node_modules/mocha/lib/runner.js:516:5)
at processImmediate (internal/timers.js:458:21) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) { 'localhost:42069' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
from mongodb-github-action.
@akoskm Looks like your connection string has the wrong port. Can you check whether the MONGO_URI
is the one provided in your GitHub Action workflow? Because the error message says port 42069
and I guess you’re trying to connect on port 27017
from mongodb-github-action.
Oh sorry, in the meantime I updated my yaml config to experiment with different ports:
- name: MongoDB in GitHub Actions
uses: supercharge/[email protected]
with:
mongodb-version: '4.2'
mongodb-replica-set: rs0
mongodb-port: 42069
from mongodb-github-action.
I found in the input of this action the following:
Initiating replica set [rs0]
MongoDB shell version v4.2.14
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("09535804-17aa-4146-b0d5-32f762bbc573") }
So I tried hardcoding the full URL I see here in my test (compressors cannot be disabled in Mongoose):
MONGO_URI = 'mongodb://127.0.0.1:42069/?compressors=snappy&gssapiServiceName=mongodb';
I got the following error:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:42069
at NativeConnection.Connection.openUri (/__w/10log-base/10log-base/node_modules/mongoose/lib/connection.js:800:32)
at /__w/10log-base/10log-base/node_modules/mongoose/lib/index.js:342:10
at /__w/10log-base/10log-base/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (/__w/10log-base/10log-base/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose.connect (/__w/10log-base/10log-base/node_modules/mongoose/lib/index.js:341:10)
at Context.<anonymous> (/__w/10log-base/10log-base/test/unit/index.js:16:22)
at callFn (/__w/10log-base/10log-base/node_modules/mocha/lib/runnable.js:358:21)
at Hook.Runnable.run (/__w/10log-base/10log-base/node_modules/mocha/lib/runnable.js:346:5)
at next (/__w/10log-base/10log-base/node_modules/mocha/lib/runner.js:454:10)
at Immediate.<anonymous> (/__w/10log-base/10log-base/node_modules/mocha/lib/runner.js:516:5)
at processImmediate (internal/timers.js:458:21) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) { '127.0.0.1:42069' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
from mongodb-github-action.
Looks like the connection attempt from the logs goes to the default port 27017
. Even with a custom port configured.
Just to make sure: you're still using the Mongoose options for URL parser and topology? I remember those being required for replica sets. Mongoose wouldn't connect properly without these
Akos, do you work on a public project where I can look at the logs of the GitHub Action?
from mongodb-github-action.
I just sent you a link to the build log/yaml file in DM on Twitter.
from mongodb-github-action.
Hello
Was the last issue resolved? What was the problem?
I am currently struggling with the same problem. I start the MongoDB in git actions I manage to restore database but then when I try to connect to that restored database with nextflow pipeline it gives me:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
from mongodb-github-action.
@eBsowka I'm still using the docker-network
branch:
uses: supercharge/mongodb-github-action@docker-network
@marcuspoehls do you remember why this wasn't merged into master? Is it the issue with the network not being cleaned up?
from mongodb-github-action.
from mongodb-github-action.
@vladkasianenko Hey Vlad, I didn’t look into this issue over the last year. I have to get back digging and reading on container actions. Maybe GitHub changed or improved the way how they work. If you have any knowledge about solving this issue, please share it. I appreciate any progress, hint, and lead 🙂
from mongodb-github-action.
same issue, but I have it in my own server with gitea and act_runner...
My script cannot connect to mongo (from mongoose) and once I restart my action it stops because container exists...
from mongodb-github-action.
# Stop and remove all running Docker containers before the job
- name: Stop and remove all running Docker containers
run: |
echo "Stopping all running Docker containers..."
docker ps -q | xargs --no-run-if-empty docker stop
echo "Removing all Docker containers..."
docker ps -a -q | xargs --no-run-if-empty docker rm
from mongodb-github-action.
Related Issues (20)
- [BUG] Action does not fail in case of missing image HOT 13
- How can i add/implement health check using this approach? HOT 1
- `mongo` and `mongosh` disappeared? HOT 15
- How can I Restore Dump from external location HOT 3
- mongoimport command not found HOT 2
- Reaching Docker Hub limit HOT 7
- Cannot connect to mongodb from Springboot HOT 2
- Add action typing HOT 4
- Mongodb tools HOT 1
- Please update v1 tag to point to newest version HOT 2
- single-instance can complete before ready to accept connections HOT 1
- How do I bind to all available interfaces? HOT 2
- tags and releases HOT 2
- MongoServerError: Authentication failed. HOT 3
- Authentication failed. HOT 2
- Error: docker: command not found
- toomanyrequests: You have reached your pull rate limit. HOT 1
- Can we use any mongodb version before 3.4.0 HOT 12
- Action fails due to docker: toomanyrequests HOT 3
- Authentication error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongodb-github-action.