Skip to content

Commit 303093d

Browse files
author
Michal Gil
committed
Docker compose and sudo installation (with dependencies) during image build + containers restart when notified
1 parent 6d0c1c4 commit 303093d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

build/config-follower/install.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,16 @@ run /pd_build/release.sh
99
run rm -r /etc/service/cron
1010
run rm -r /etc/service/sshd && rm /etc/my_init.d/00_regen_ssh_host_keys.sh
1111

12+
# Docker compose inside the container
13+
# Dependencies
14+
run apt-get update
15+
run apt-get install -y sudo curl python-dev libffi-dev gcc libc-dev make
16+
# Docker-compose download and preparation
17+
run sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
18+
run sudo chmod +x /usr/local/bin/docker-compose
19+
run sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
20+
# To disable password prompt for sudo
21+
echo "app ALL = NOPASSWD: /usr/local/bin/docker-compose, /usr/bin/docker-compose" > /etc/sudoers.d/docker-compose
22+
1223
# Clean up after ourselves.
1324
run /pd_build/finalize.sh

src/routes/notify.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import type Application from '../app';
44
const logger = require('../utils/logging').getLogger('notify');
5+
const child_process = require('child_process');
6+
const fs = require('fs');
57

68
module.exports = function (expressApp: express$Application, app: Application) {
79

@@ -10,7 +12,28 @@ module.exports = function (expressApp: express$Application, app: Application) {
1012
app.fetchConfig()
1113
.then((filesWritten) => {
1214
res.send({files: filesWritten});
15+
restartPryvContainers();
1316
})
1417
.catch(next);
1518
});
19+
20+
function restartPryvContainers() {
21+
const fileLoc = '/app/pryv/pryv.yml';
22+
if(fs.existsSync(fileLoc)) {
23+
try {
24+
child_process.execSync(`sudo docker-compose -f ${fileLoc} down`);
25+
}
26+
catch(e) {
27+
console.error('Error during stopping runnning containers', e)
28+
}
29+
try {
30+
child_process.execSync(`sudo docker-compose -f ${fileLoc} up -d`);
31+
}
32+
catch(e) {
33+
console.error('Error during starting stopped containers', e)
34+
}
35+
} else {
36+
console.error(`Docker compose file: ${fileLoc} does not exist`)
37+
}
38+
}
1639
};

0 commit comments

Comments
 (0)