Compare commits

...
Author SHA1 Message Date
ElevenNotes f60f0ad124 0.1.5, remove container restart on kill 2023-12-19 11:44:50 +01:00
ElevenNotes e7202481b3 0.1.4 2023-12-05 08:58:34 +01:00
4 changed files with 38 additions and 43 deletions
+1 -2
View File
@@ -1,2 +1 @@
maintain/
/build
maintain/
+1 -1
View File
@@ -1,5 +1,5 @@
# Alpine :: Traefik Labels
![size](https://img.shields.io/docker/image-size/11notes/traefik-labels/0.1.3?color=0eb305) ![version](https://img.shields.io/docker/v/11notes/traefik-labels?color=eb7a09) ![pulls](https://img.shields.io/docker/pulls/11notes/traefik-labels?color=2b75d6) ![activity](https://img.shields.io/github/commit-activity/m/11notes/docker-traefik-labels?color=c91cb8) ![commit-last](https://img.shields.io/github/last-commit/11notes/docker-traefik-labels?color=c91cb8)
![size](https://img.shields.io/docker/image-size/11notes/traefik-labels/0.1.5?color=0eb305) ![version](https://img.shields.io/docker/v/11notes/traefik-labels?color=eb7a09) ![pulls](https://img.shields.io/docker/pulls/11notes/traefik-labels?color=2b75d6) ![activity](https://img.shields.io/github/commit-activity/m/11notes/docker-traefik-labels?color=c91cb8) ![commit-last](https://img.shields.io/github/last-commit/11notes/docker-traefik-labels?color=c91cb8)
Run Traefik Labels based on Alpine Linux. Small, lightweight, secure and fast 🏔️
+36 -39
View File
@@ -69,16 +69,16 @@ class Labels{
if(!this.#poll){
try{
this.#poll = true;
this.#log(`poll start (interval:${process.env.LABELS_INTERVAL})}`);
this.#docker.listContainers((error, containers) => {
containers.forEach(async(container) => {
await this.dockerInspect(container.Id);
});
if(!error){
containers.forEach(async(container) => {
await this.dockerInspect(container.Id);
});
}
});
}catch(e){
this.#log(e, ERROR);
}finally{
this.#log('poll end');
this.#poll = false;
}
}
@@ -88,47 +88,44 @@ class Labels{
return(new Promise((resolve, reject) => {
const container = this.#docker.getContainer(id);
container.inspect(async(error, data) => {
if(!error){
let update = false;
const webHook = {event:status, labels:{}};
const headers = {'Content-Type':'application/json'};
let update = false;
const webHook = {event:status, labels:{}};
const headers = {'Content-Type':'application/json'};
if('' !== process.env.LABELS_WEBHOOK_AUTH_BASIC){
headers['Authorization'] = 'Basic ' + Buffer.from(process.env.LABELS_WEBHOOK_AUTH_BASIC).toString('base64')
}
if('' !== process.env.LABELS_WEBHOOK_AUTH_BASIC){
headers['Authorization'] = 'Basic ' + Buffer.from(process.env.LABELS_WEBHOOK_AUTH_BASIC).toString('base64')
}
if(/start|restart/i.test(status)){
update = true;
}
if(error){
reject(error);
}
this.#log(`inspect container ${data.Name.replace(/^\//i, '')}${(
(null === status) ? '' : ` event[${status}]`
)}`);
if(/start|restart/i.test(status)){
update = true;
}
for(const label in data?.Config?.Labels){
if(/traefik\//i.test(label)){
webHook.labels[label] = data?.Config?.Labels[label];
if(update){
await this.#redis.set(label, data?.Config?.Labels[label], {EX:parseInt(process.env.LABELS_INTERVAL) + parseInt(process.env.LABELS_TIMEOUT)});
}else{
await this.#redis.del(label);
this.#log(`inspect container {${(data?.Name || data?.id).replace(/^\//i, '')}}${(
(null === status) ? '' : ` event[${status}]`
)}`);
for(const label in data?.Config?.Labels){
if(/traefik\//i.test(label)){
webHook.labels[label] = data?.Config?.Labels[label];
if(update){
await this.#redis.set(label, data?.Config?.Labels[label], {EX:parseInt(process.env.LABELS_INTERVAL) + parseInt(process.env.LABELS_TIMEOUT)});
}else{
await this.#redis.del(label);
}
}
}
}
if('' !== process.env.LABELS_WEBHOOK){
try{
const webHookCall = await fetch(process.env.LABELS_WEBHOOK, {method:(
(update) ? 'PUT' : 'DELETE'
), body:JSON.stringify(webHook), headers:headers});
}catch(e){
this.#log(e, ERROR);
if('' !== process.env.LABELS_WEBHOOK){
try{
await fetch(process.env.LABELS_WEBHOOK, {method:(
(update) ? 'PUT' : 'DELETE'
), body:JSON.stringify(webHook), headers:headers});
}catch(e){
this.#log(e, ERROR);
}
}
resolve(true);
}
resolve(true);
});
}));
}
-1
View File
@@ -12,7 +12,6 @@ const child = fork(`${__dirname}/app.js`, [], {
});
child.on('error', (error) =>{
console.error(error);
process.exit(1);
});
child.on('close', (code) =>{
console.warn(`child process closed with exit code ${code}`);