Compare commits

...
Author SHA1 Message Date
ElevenNotes d978cd42c8 0.1.6 2023-12-19 13:56:06 +01:00
ElevenNotes af8343f89a 0.1.6 simplify webhook 2023-12-19 13:55:52 +01:00
2 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# Alpine :: Traefik Labels
![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)
![size](https://img.shields.io/docker/image-size/11notes/traefik-labels/0.1.6?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 🏔️
+14 -13
View File
@@ -6,15 +6,21 @@ class Labels{
#docker;
#redis;
#poll = false;
#webhook = {
headers:{'Content-Type':'application/json'}
};
constructor(){
this.#docker = new Docker({socketPath:'/run/docker.sock'});
if('' !== process.env.LABELS_WEBHOOK_AUTH_BASIC){
this.#webhook.headers['Authorization'] = 'Basic ' + Buffer.from(process.env.LABELS_WEBHOOK_AUTH_BASIC).toString('base64')
}
}
#log(message, error){
#log(message, type){
console.log(JSON.stringify({
time:new Date().toISOString(),
type:(error === ERROR) ? 'ERROR' : 'INFO',
type:(type === ERROR) ? 'ERROR' : 'INFO',
message:message,
}));
}
@@ -72,7 +78,7 @@ class Labels{
this.#docker.listContainers((error, containers) => {
if(!error){
containers.forEach(async(container) => {
await this.dockerInspect(container.Id);
await this.dockerInspect(container.Id, 'poll');
});
}
});
@@ -90,14 +96,8 @@ class Labels{
container.inspect(async(error, data) => {
if(!error){
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(/start|restart/i.test(status)){
const webHook = {event:status, labels:{}};
if(/start|restart|poll/i.test(status)){
update = true;
}
@@ -109,17 +109,18 @@ class Labels{
if(/traefik\//i.test(label)){
webHook.labels[label] = data?.Config?.Labels[label];
if(update){
this.#log(`${label} = ${data?.Config?.Labels[label]}`);
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){
if('' !== process.env.LABELS_WEBHOOK){
try{
await fetch(process.env.LABELS_WEBHOOK, {method:(
(update) ? 'PUT' : 'DELETE'
), body:JSON.stringify(webHook), headers:headers});
), body:JSON.stringify(webHook), headers:this.#webhook.headers, signal:AbortSignal.timeout(5000)});
}catch(e){
this.#log(e, ERROR);
}