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:
Jakob Ackermann
2024-10-02 16:09:03 +02:00
committed by Copybot
parent e4f0ea83e7
commit 2b72d89171
4 changed files with 29 additions and 66 deletions

View File

@@ -30,7 +30,6 @@ const IMAGES = {
}
let previousConfig = ''
let mongoIsInitialized = false
function readDockerComposeOverride() {
try {
@@ -245,42 +244,12 @@ app.post(
(req, res) => {
const { cmd } = req.params
const { args } = req.body
if (['stop', 'down'].includes(cmd)) {
mongoIsInitialized = false
}
runDockerCompose(cmd, args, (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) {
if (!resetData) return callback()
@@ -297,7 +266,6 @@ function maybeResetData(resetData, callback) {
}
previousConfig = ''
mongoIsInitialized = false
runDockerCompose(
'down',
['--timeout=0', '--volumes', 'mongo', 'redis'],
@@ -332,18 +300,16 @@ app.post(
return res.json({ error })
}
maybeMongoInit(!mongoIsInitialized, (error, stdout, stderr) => {
if (error) return res.json({ error, stdout, stderr })
runDockerCompose(
'up',
['--detach', '--wait', 'sharelatex'],
(error, stdout, stderr) => {
const previousConfigServer = previousConfig
previousConfig = JSON.stringify(req.body)
res.json({ error, stdout, stderr, previousConfigServer })
}
)
})
if (error) return res.json({ error, stdout, stderr })
runDockerCompose(
'up',
['--detach', '--wait', 'sharelatex'],
(error, stdout, stderr) => {
const previousConfigServer = previousConfig
previousConfig = JSON.stringify(req.body)
res.json({ error, stdout, stderr, previousConfigServer })
}
)
})
}
)
@@ -362,12 +328,4 @@ app.use(handleValidationErrors())
purgeDataDir()
// Init on startup
maybeMongoInit(true, err => {
if (err) {
console.error('mongo init failed', err)
process.exit(1)
}
app.listen(80)
})
app.listen(80)