Skip to content

Commit 7fbbf72

Browse files
committed
Switch to different mongo container that Just Works on arm64
Needs some hackery to initialize the replication sets
1 parent 1c9762c commit 7fbbf72

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

core/docker-compose.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,49 @@ services:
4444
- 3306:3306
4545

4646
mongo:
47-
image: bitnami/mongodb:7.0
47+
image: mongo:7
4848
environment:
49-
MONGO_INITDB_ROOT_USERNAME: root
50-
MONGO_INITDB_ROOT_PASSWORD: secret
51-
MONGODB_ROOT_PASSWORD: secret
52-
MONGODB_REPLICA_SET_NAME: openconext
53-
MONGODB_REPLICA_SET_MODE: primary
54-
MONGODB_REPLICA_SET_KEY: secretsecret
55-
MONGODB_ADVERTISED_HOSTNAME: mongodb
49+
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USERNAME:-root}
50+
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD:-secret}
51+
MONGO_REPLICA_SET_NAME: ${MONGODB_RS_NAME:-openconext}
5652
volumes:
5753
- ./mongo/:/docker-entrypoint-initdb.d/
58-
- openconext_mongodb:/bitnami/mongodb
54+
- openconext_mongodb:/data/db
5955
healthcheck:
60-
test: ['CMD', 'true']
61-
# test:
62-
# [
63-
# "CMD",
64-
# "mongosh",
65-
# "-u",
66-
# "managerw",
67-
# "-p",
68-
# "secret",
69-
# "--eval",
70-
# "db.stats().ok",
71-
# "mongodb://127.0.0.1/manage",
72-
# ]
73-
interval: 10s
74-
timeout: 10s
75-
retries: 3
76-
start_period: 20s
56+
test: |
57+
# After starting, but before being used, we need to initialize the Mongo replication set
58+
# we abuse the healthcheck for that, because we need to check the health status anyway
59+
mongosh -u $${MONGO_INITDB_ROOT_USERNAME} -p $${MONGO_INITDB_ROOT_PASSWORD} --eval '
60+
try {
61+
rs.status().ok;
62+
}
63+
catch ({ name, message }) {
64+
print("error:" + name);
65+
print("message:" + message);
66+
if (name=="MongoServerError" && message.includes("no replset config has been received")) {
67+
rs.initiate({
68+
_id : "${MONGODB_RS_NAME:-openconext}",
69+
members: [ { _id: 0, host: "mongodb:27017" } ]
70+
});
71+
rs.status().ok;
72+
}
73+
};
74+
'
75+
interval: 2s
76+
timeout: 3s
77+
retries: 5
78+
entrypoint: >
79+
bash -c '
80+
openssl rand -base64 756 > /keyfile \
81+
&& chown mongodb:mongodb /keyfile \
82+
&& chmod 400 /keyfile \
83+
&& exec docker-entrypoint.sh $$@
84+
'
85+
command: |
86+
mongod --bind_ip_all --replSet ${MONGODB_RS_NAME:-openconext} --keyFile /keyfile
87+
restart: always
88+
ports:
89+
- "27017:27017"
7790
networks:
7891
coreconextdev:
7992
hostname: mongodb

0 commit comments

Comments
 (0)