Skip to content

Commit 3305a82

Browse files
authored
Merge pull request #58 from OpenConext/fix/mongo
Switch to different mongo container that Just Works on arm64
2 parents 0cfd4b9 + 27d4750 commit 3305a82

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

core/docker-compose.yml

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,49 @@ services:
5050
- 3306:3306
5151

5252
mongo:
53-
image: bitnami/mongodb:7.0
53+
image: mongo:7
5454
environment:
55-
MONGO_INITDB_ROOT_USERNAME: root
56-
MONGO_INITDB_ROOT_PASSWORD: secret
57-
MONGODB_ROOT_PASSWORD: secret
58-
MONGODB_REPLICA_SET_NAME: openconext
59-
MONGODB_REPLICA_SET_MODE: primary
60-
MONGODB_REPLICA_SET_KEY: secretsecret
61-
MONGODB_ADVERTISED_HOSTNAME: mongodb
62-
# Force QEMU emulation instead of Rosetta for x86_64 Apple Silicon Macs.
63-
# Rosetta does not support AVX instructions, which this MongoD image requires, causing an
64-
# "Illegal instruction" error when starting the container:
65-
# /opt/bitnami/scripts/libos.sh: line 346: 50 Illegal instruction "$@" > /dev/null 2>&1
66-
EXPERIMENTAL_DOCKER_DESKTOP_FORCE_QEMU: 1
55+
MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USERNAME:-root}
56+
MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD:-secret}
57+
MONGO_REPLICA_SET_NAME: ${MONGODB_RS_NAME:-openconext}
6758
volumes:
6859
- ./mongo/:/docker-entrypoint-initdb.d/
69-
- openconext_mongodb:/bitnami/mongodb
60+
- openconext_mongodb:/data/db
7061
healthcheck:
71-
test:
72-
[
73-
"CMD",
74-
"mongosh",
75-
"-u",
76-
"managerw",
77-
"-p",
78-
"secret",
79-
"--eval",
80-
"db.stats().ok",
81-
"mongodb://127.0.0.1/manage",
82-
]
83-
interval: 10s
84-
timeout: 10s
85-
retries: 3
86-
start_period: 20s
62+
test: |
63+
# After starting, but before being used, we need to initialize the Mongo replication set
64+
# we abuse the healthcheck for that, because we need to check the health status anyway
65+
mongosh -u $${MONGO_INITDB_ROOT_USERNAME} -p $${MONGO_INITDB_ROOT_PASSWORD} --eval '
66+
try {
67+
rs.status().ok;
68+
}
69+
catch ({ name, message }) {
70+
print("error:" + name);
71+
print("message:" + message);
72+
if (name=="MongoServerError" && message.includes("no replset config has been received")) {
73+
rs.initiate({
74+
_id : "${MONGODB_RS_NAME:-openconext}",
75+
members: [ { _id: 0, host: "mongodb:27017" } ]
76+
});
77+
rs.status().ok;
78+
}
79+
};
80+
'
81+
interval: 2s
82+
timeout: 3s
83+
retries: 5
84+
entrypoint: >
85+
bash -c '
86+
openssl rand -base64 756 > /keyfile \
87+
&& chown mongodb:mongodb /keyfile \
88+
&& chmod 400 /keyfile \
89+
&& exec docker-entrypoint.sh $$@
90+
'
91+
command: |
92+
mongod --bind_ip_all --replSet ${MONGODB_RS_NAME:-openconext} --keyFile /keyfile
93+
restart: always
94+
ports:
95+
- "27017:27017"
8796
networks:
8897
coreconextdev:
8998
hostname: mongodb

0 commit comments

Comments
 (0)