Skip to content

Commit c83d595

Browse files
committed
Add MongoDB 8.0 support
1 parent b5c0e4a commit c83d595

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

.github/workflows/ci-8-0.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI / 8.0
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- .github/workflows/ci-8-0.yaml
7+
- src/8.0/**
8+
push:
9+
paths:
10+
- .github/workflows/ci-8-0.yaml
11+
- src/8.0/**
12+
branches:
13+
- main
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
test-and-release:
21+
uses: ./.github/workflows/reusable--test-and-release.yaml
22+
with:
23+
version: "8.0"
24+
secrets:
25+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
26+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ test-all:
1818
make test MONGO_VERSION=5.0
1919
make test MONGO_VERSION=6.0
2020
make test MONGO_VERSION=7.0
21+
make test MONGO_VERSION=8.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ We support the following versions:
2929
- 5.0
3030
- 6.0
3131
- 7.0
32+
- 8.0
3233

3334
They are from [Docker official image](https://hub.docker.com/_/mongo).
3435

src/8.0/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM mongo:8.0
2+
3+
RUN mkdir -p \
4+
/var/lib/sharded-mongo/mongod-config \
5+
/var/lib/sharded-mongo/mongod-shard \
6+
/docker-entrypoint-initdb.d
7+
8+
COPY docker-entrypoint.sh /usr/local/bin
9+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
10+
11+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
12+
CMD ["mongos", "-f", "/etc/mongos.conf"]

src/8.0/docker-entrypoint.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script coordinates a MongoDB sharded cluster.
4+
# The implementation follows https://www.mongodb.com/docs/manual/tutorial/deploy-shard-cluster/.
5+
#
6+
7+
set -Eeuo pipefail
8+
9+
echo "[sharded-mongo/docker-entrypoint.sh] forking config server..."
10+
11+
mongod \
12+
--configsvr \
13+
--replSet config \
14+
--dbpath /var/lib/sharded-mongo/mongod-config \
15+
--bind_ip_all \
16+
--ipv6 \
17+
--port 27019 \
18+
--fork \
19+
--logpath /var/log/mongod-config.log
20+
21+
if [ ! -e /var/lib/sharded-mongo/mongod-config.initialized ]; then
22+
echo "[sharded-mongo/docker-entrypoint.sh] initializing config server..."
23+
mongosh --eval 'rs.initiate({_id: "config", configsvr: true, members: [{ _id : 0, host : "localhost:27019" }]})' localhost:27019
24+
touch /var/lib/sharded-mongo/mongod-config.initialized
25+
fi
26+
27+
echo "[sharded-mongo/docker-entrypoint.sh] forking shard server..."
28+
29+
mongod \
30+
--shardsvr \
31+
--replSet shard \
32+
--dbpath /var/lib/sharded-mongo/mongod-shard \
33+
--bind_ip_all \
34+
--ipv6 \
35+
--port 27018 \
36+
--fork \
37+
--logpath /var/log/mongod-shard.log
38+
39+
if [ ! -e /var/lib/sharded-mongo/mongod-shard.initialized ]; then
40+
echo "[sharded-mongo/docker-entrypoint.sh] initializing shard server..."
41+
mongosh --eval 'rs.initiate({_id: "shard", members: [{ _id : 0, host : "localhost:27018" }]})' localhost:27018
42+
touch /var/lib/sharded-mongo/mongod-shard.initialized
43+
fi
44+
45+
echo "[sharded-mongo/docker-entrypoint.sh] forking mongos server..."
46+
47+
cat <<CONF >/etc/mongos.conf
48+
net:
49+
bindIpAll: true
50+
ipv6: true
51+
port: 27017
52+
sharding:
53+
configDB: config/localhost:27019
54+
CONF
55+
56+
mongos \
57+
--config /etc/mongos.conf \
58+
--fork \
59+
--logpath /var/log/mongos.log
60+
61+
if [ ! -e /var/lib/sharded-mongo/mongos.initialized ]; then
62+
echo "[sharded-mongo/docker-entrypoint.sh] initializing mongos server..."
63+
mongosh --eval 'sh.addShard("shard/localhost:27018")' localhost:27017
64+
touch /var/lib/sharded-mongo/mongos.initialized
65+
66+
for f in /docker-entrypoint-initdb.d/*; do
67+
case "$f" in
68+
*.sh) echo "$0: running $f"; . "$f" ;;
69+
*.js) echo "$0: running $f"; mongosh localhost:27017 "$f"; echo ;;
70+
*) echo "$0: ignoring $f" ;;
71+
esac
72+
done
73+
fi
74+
75+
echo "[sharded-mongo/docker-entrypoint.sh] shutting mongos server down..."
76+
77+
mongosh --eval 'db.shutdownServer()' localhost:27017/admin || true
78+
79+
while pgrep mongos > /dev/null; do
80+
echo "[sharded-mongo/docker-entrypoint.sh] mongos is shutting down. sleep 1 second..."
81+
sleep 1
82+
done
83+
84+
exec "$@"

0 commit comments

Comments
 (0)