1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 07:10:05 +02:00

bug(portal-data): support compose reconnects

This commit is contained in:
geek 2017-06-22 12:08:13 -05:00 committed by Sérgio Ramos
parent bc679d6ac6
commit be842aba31
7 changed files with 44 additions and 5 deletions

View File

@ -54,8 +54,6 @@ docker-compose-api:
environment:
- CONSUL=consul
restart: always
dns:
- 127.0.0.1
traefik:
image: d0cker/traefik

View File

@ -14,6 +14,8 @@ RUN npm install -g npm@^4 \
&& ./node_modules/.bin/lerna bootstrap --scope portal-api --include-filtered-dependencies
COPY packages/portal-api/etc/containerpilot.json5 ${CONTAINERPILOT}
COPY packages/portal-api/bin /bin
WORKDIR /opt/app/packages/portal-api
CMD ["/bin/containerpilot"]

View File

@ -0,0 +1,13 @@
#!/bin/bash
# Copy creds from env vars to files on disk
if [ -n ${!TRITON_CREDS_PATH} ] \
&& [ -n ${!TRITON_CA} ] \
&& [ -n ${!TRITON_CERT} ] \
&& [ -n ${!TRITON_KEY} ]
then
mkdir -p ${TRITON_CREDS_PATH}
echo -e "${TRITON_CA}" | tr '#' '\n' > ${TRITON_CREDS_PATH}/ca.pem
echo -e "${TRITON_CERT}" | tr '#' '\n' > ${TRITON_CREDS_PATH}/cert.pem
echo -e "${TRITON_KEY}" | tr '#' '\n' > ${TRITON_CREDS_PATH}/key.pem
fi

View File

@ -1,9 +1,17 @@
{
consul: 'localhost:8500',
jobs: [
{
"name": "setup-config",
"exec": "/bin/prestart.sh"
},
{
name: 'bootstrap',
exec: 'node bootstrap-data.js'
exec: 'node bootstrap-data.js',
when: {
source: 'setup-config',
once: 'exitSuccess'
}
},
{
name: 'api',
@ -22,7 +30,8 @@
when: {
source: 'bootstrap',
once: 'exitSuccess'
}
},
restarts: 'unlimited'
},
{
name: 'consul-agent',

View File

@ -24,6 +24,10 @@ module.exports = function (server, options, next) {
data
}));
data.on('error', (err) => {
server.log(['error'], err);
});
data.connect((err) => {
if (err) {
return next(err);
@ -65,6 +69,6 @@ internals.refresh = function (data) {
return;
}
data._dockerCompose.client.connect(`tcp://${docker.address}:${docker.port}`);
data.reconnectCompose(`tcp://${docker.address}:${docker.port}`);
};
};

View File

@ -61,6 +61,15 @@ module.exports = class Data extends EventEmitter {
this._db.establish(internals.tables, cb);
}
reconnectCompose (dockerComposeHost) {
this._dockerCompose.close();
this._dockerCompose = new DockerClient(dockerComposeHost);
this._dockerCompose.on('error', (err) => {
this.emit('error', err);
});
}
// portals

View File

@ -31,6 +31,10 @@ check() {
TRITON_CREDS_PATH=/root/.triton
echo TRITON_CREDS_PATH=${TRITON_CREDS_PATH} >> _env
echo DOCKER_CERT_PATH=${TRITON_CREDS_PATH} >> _env
echo DOCKER_TLS_VERIFY=1 >> _env
echo COMPOSE_HTTP_TIMEOUT=300 >> _env
echo DOCKER_CLIENT_TIMEOUT=300 >> _env
echo DOCKER_HOST=${DOCKER_HOST} >> _env
echo TRITON_USER=${TRITON_USER} >> _env
echo TRITON_DC=${TRITON_DC} >> _env
echo TRITON_CA=$(cat "${DOCKER_CERT_PATH}"/ca.pem | tr '\n' '#') >> _env