mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #20685 from overleaf/jpa-fix-local-e2e
[server-ce] use database init script for setting up mongo replica set GitOrigin-RevId: cf5c820a8c26da43de2f5c66677dba2c40a3667e
This commit is contained in:
parent
e4f0ea83e7
commit
2b72d89171
4 changed files with 29 additions and 66 deletions
|
@ -13,9 +13,6 @@ services:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
links:
|
|
||||||
- mongo
|
|
||||||
- redis
|
|
||||||
stop_grace_period: 60s
|
stop_grace_period: 60s
|
||||||
volumes:
|
volumes:
|
||||||
- ~/sharelatex_data:/var/lib/overleaf
|
- ~/sharelatex_data:/var/lib/overleaf
|
||||||
|
@ -107,10 +104,16 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
image: mongo:5.0
|
image: mongo:5.0
|
||||||
container_name: mongo
|
container_name: mongo
|
||||||
expose:
|
command: '--replSet overleaf'
|
||||||
- 27017
|
|
||||||
volumes:
|
volumes:
|
||||||
- ~/mongo_data:/data/db
|
- ~/mongo_data:/data/db
|
||||||
|
- ./mongodb-init-replica-set.js:/docker-entrypoint-initdb.d/mongodb-init-replica-set.js
|
||||||
|
environment:
|
||||||
|
MONGO_INITDB_DATABASE: sharelatex
|
||||||
|
extra_hosts:
|
||||||
|
# Required when using the automatic database setup for initializing the replica set.
|
||||||
|
# This override is not needed when running the setup after starting up mongo.
|
||||||
|
- mongo:127.0.0.1
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
||||||
interval: 10s
|
interval: 10s
|
||||||
|
@ -121,8 +124,6 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
image: redis:6.2
|
image: redis:6.2
|
||||||
container_name: redis
|
container_name: redis
|
||||||
expose:
|
|
||||||
- 6379
|
|
||||||
volumes:
|
volumes:
|
||||||
- ~/redis_data:/data
|
- ~/redis_data:/data
|
||||||
|
|
||||||
|
@ -130,8 +131,6 @@ services:
|
||||||
# restart: always
|
# restart: always
|
||||||
# image: rroemhild/test-openldap
|
# image: rroemhild/test-openldap
|
||||||
# container_name: ldap
|
# container_name: ldap
|
||||||
# expose:
|
|
||||||
# - 389
|
|
||||||
|
|
||||||
# See https://github.com/jwilder/nginx-proxy for documentation on how to configure the nginx-proxy container,
|
# See https://github.com/jwilder/nginx-proxy for documentation on how to configure the nginx-proxy container,
|
||||||
# and https://github.com/overleaf/overleaf/wiki/HTTPS-reverse-proxy-using-Nginx for an example of some recommended
|
# and https://github.com/overleaf/overleaf/wiki/HTTPS-reverse-proxy-using-Nginx for an example of some recommended
|
||||||
|
@ -142,7 +141,7 @@ services:
|
||||||
# image: jwilder/nginx-proxy
|
# image: jwilder/nginx-proxy
|
||||||
# container_name: nginx-proxy
|
# container_name: nginx-proxy
|
||||||
# ports:
|
# ports:
|
||||||
# #- "80:80"
|
# - "80:80"
|
||||||
# - "443:443"
|
# - "443:443"
|
||||||
# volumes:
|
# volumes:
|
||||||
# - /var/run/docker.sock:/tmp/docker.sock:ro
|
# - /var/run/docker.sock:/tmp/docker.sock:ro
|
||||||
|
|
1
server-ce/mongodb-init-replica-set.js
Normal file
1
server-ce/mongodb-init-replica-set.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rs.initiate({ _id: "overleaf", members: [ { _id: 0, host: "mongo:27017" } ] })
|
|
@ -8,9 +8,6 @@ services:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
host-admin:
|
|
||||||
# The host-admin service initiates the mongo replica set
|
|
||||||
condition: service_healthy
|
|
||||||
mailtrap:
|
mailtrap:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
environment:
|
environment:
|
||||||
|
@ -40,6 +37,14 @@ services:
|
||||||
mongo:
|
mongo:
|
||||||
image: mongo:5.0.17
|
image: mongo:5.0.17
|
||||||
command: '--replSet overleaf'
|
command: '--replSet overleaf'
|
||||||
|
volumes:
|
||||||
|
- ../mongodb-init-replica-set.js:/docker-entrypoint-initdb.d/mongodb-init-replica-set.js
|
||||||
|
environment:
|
||||||
|
MONGO_INITDB_DATABASE: sharelatex
|
||||||
|
extra_hosts:
|
||||||
|
# Required when using the automatic database setup for initializing the replica set.
|
||||||
|
# This override is not needed when running the setup after starting up mongo.
|
||||||
|
- mongo:127.0.0.1
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
|
||||||
interval: 3s
|
interval: 3s
|
||||||
|
|
|
@ -30,7 +30,6 @@ const IMAGES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let previousConfig = ''
|
let previousConfig = ''
|
||||||
let mongoIsInitialized = false
|
|
||||||
|
|
||||||
function readDockerComposeOverride() {
|
function readDockerComposeOverride() {
|
||||||
try {
|
try {
|
||||||
|
@ -245,42 +244,12 @@ app.post(
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
const { cmd } = req.params
|
const { cmd } = req.params
|
||||||
const { args } = req.body
|
const { args } = req.body
|
||||||
if (['stop', 'down'].includes(cmd)) {
|
|
||||||
mongoIsInitialized = false
|
|
||||||
}
|
|
||||||
runDockerCompose(cmd, args, (error, stdout, stderr) => {
|
runDockerCompose(cmd, args, (error, stdout, stderr) => {
|
||||||
res.json({ error, stdout, stderr })
|
res.json({ error, stdout, stderr })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
function maybeMongoInit(mongoInit, callback) {
|
|
||||||
if (!mongoInit) return callback()
|
|
||||||
runDockerCompose(
|
|
||||||
'up',
|
|
||||||
['--detach', '--wait', 'mongo'],
|
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (error) return callback(error, stdout, stderr)
|
|
||||||
|
|
||||||
runDockerCompose(
|
|
||||||
'exec',
|
|
||||||
[
|
|
||||||
'mongo',
|
|
||||||
'mongo',
|
|
||||||
'--eval',
|
|
||||||
'rs.initiate({ _id: "overleaf", members: [ { _id: 0, host: "mongo:27017" } ] })',
|
|
||||||
],
|
|
||||||
(error, stdout, stderr) => {
|
|
||||||
if (!error) {
|
|
||||||
mongoIsInitialized = true
|
|
||||||
}
|
|
||||||
callback(error, stdout, stderr)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function maybeResetData(resetData, callback) {
|
function maybeResetData(resetData, callback) {
|
||||||
if (!resetData) return callback()
|
if (!resetData) return callback()
|
||||||
|
|
||||||
|
@ -297,7 +266,6 @@ function maybeResetData(resetData, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
previousConfig = ''
|
previousConfig = ''
|
||||||
mongoIsInitialized = false
|
|
||||||
runDockerCompose(
|
runDockerCompose(
|
||||||
'down',
|
'down',
|
||||||
['--timeout=0', '--volumes', 'mongo', 'redis'],
|
['--timeout=0', '--volumes', 'mongo', 'redis'],
|
||||||
|
@ -332,18 +300,16 @@ app.post(
|
||||||
return res.json({ error })
|
return res.json({ error })
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeMongoInit(!mongoIsInitialized, (error, stdout, stderr) => {
|
if (error) return res.json({ error, stdout, stderr })
|
||||||
if (error) return res.json({ error, stdout, stderr })
|
runDockerCompose(
|
||||||
runDockerCompose(
|
'up',
|
||||||
'up',
|
['--detach', '--wait', 'sharelatex'],
|
||||||
['--detach', '--wait', 'sharelatex'],
|
(error, stdout, stderr) => {
|
||||||
(error, stdout, stderr) => {
|
const previousConfigServer = previousConfig
|
||||||
const previousConfigServer = previousConfig
|
previousConfig = JSON.stringify(req.body)
|
||||||
previousConfig = JSON.stringify(req.body)
|
res.json({ error, stdout, stderr, previousConfigServer })
|
||||||
res.json({ error, stdout, stderr, previousConfigServer })
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -362,12 +328,4 @@ app.use(handleValidationErrors())
|
||||||
|
|
||||||
purgeDataDir()
|
purgeDataDir()
|
||||||
|
|
||||||
// Init on startup
|
app.listen(80)
|
||||||
maybeMongoInit(true, err => {
|
|
||||||
if (err) {
|
|
||||||
console.error('mongo init failed', err)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.listen(80)
|
|
||||||
})
|
|
||||||
|
|
Loading…
Reference in a new issue