Compare commits

...
7 Commits
Author SHA1 Message Date
ElevenNotes 2eadac07bb add container info 2024-01-21 09:03:17 +01:00
ElevenNotes e129945fde true JSON with elevenLogJSON 2024-01-18 11:42:57 +01:00
ElevenNotes 2d9bfafffa add debug option 2024-01-18 09:37:47 +01:00
ElevenNotes 823151dc98 fix ? on object 2024-01-18 09:28:42 +01:00
ElevenNotes 7bd574c3a3 latest 2024-01-18 09:12:29 +01:00
ElevenNotes e7c3a83ae2 add correct arch and build 2024-01-18 09:09:18 +01:00
ElevenNotes 24a2e20641 fix URL 2024-01-18 08:56:56 +01:00
4 changed files with 32 additions and 24 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# Alpine :: Traefik Labels
![size](https://img.shields.io/docker/image-size/11notes/labels/latest?color=0eb305) ![version](https://img.shields.io/docker/v/11notes/labels?color=eb7a09) ![pulls](https://img.shields.io/docker/pulls/11notes/labels?color=2b75d6) ![activity](https://img.shields.io/github/commit-activity/m/11notes/docker-labels?color=c91cb8) ![commit-last](https://img.shields.io/github/last-commit/11notes/docker-labels?color=c91cb8)
![size](https://img.shields.io/docker/image-size/11notes/traefik-labels/amd64-0.1.8?color=0eb305) ![version](https://img.shields.io/docker/v/11notes/traefik-labels/amd64-0.1.8?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 🏔️
+3 -2
View File
@@ -8,7 +8,6 @@
# :: Header
FROM 11notes/node:stable
COPY --from=util /util/node/util.js /labels/lib
ENV APP_ROOT=/labels
# :: Run
@@ -16,11 +15,13 @@
# :: prepare image
RUN set -ex; \
mkdir -p ${APP_ROOT}; \
mkdir -p ${APP_ROOT}/lib; \
apk --no-cache add \
bind-tools; \
apk --no-cache upgrade;
COPY --from=util /util/node/util.js /labels/lib
# :: install
RUN set -ex; \
cd ${APP_ROOT}; \
+3 -2
View File
@@ -13,7 +13,6 @@
# :: Header
FROM arm64v8/node:20.10.0-alpine3.19
COPY --from=util /util/node/util.js /labels/lib
COPY --from=qemu qemu-aarch64-static /usr/bin
ENV APP_ROOT=/labels
@@ -22,11 +21,13 @@
# :: prepare image
RUN set -ex; \
mkdir -p ${APP_ROOT}; \
mkdir -p ${APP_ROOT}/lib; \
apk --no-cache add \
bind-tools; \
apk --no-cache upgrade;
COPY --from=util /util/node/util.js /labels/lib
# :: install
RUN set -ex; \
cd ${APP_ROOT}; \
+25 -19
View File
@@ -3,14 +3,21 @@ process.once('SIGINT', () => process.exit(0));
const Docker = require('dockerode');
const redis = require('redis');
const { nsupdate } = requore('./nsupdate');
const { logJSON } = require('/labels/lib/util.js');
const { nsupdate } = require('./nsupdate');
const { elevenLogJSON } = require('/labels/lib/util.js');
const ENV_REDIS_INTERVAL = parseInt(process.env?.LABELS_INTERVAL || 300);
const ENV_REDIS_TIMEOUT = parseInt(process.env?.LABELS_TIMEOUT|| 30);
const ENV_LABELS_WEBHOOK = process.env?.LABELS_WEBHOOK;
const ENV_LABELS_WEBHOOK_AUTH_BASIC = process.env?.LABELS_WEBHOOK_AUTH_BASIC;
elevenLogJSON('info', {config:{
LABELS_INTERVAL :ENV_REDIS_INTERVAL,
LABELS_TIMEOUT:ENV_REDIS_TIMEOUT,
LABELS_WEBHOOK:ENV_LABELS_WEBHOOK,
LABELS_WEBHOOK_AUTH_BASIC:((ENV_LABELS_WEBHOOK_AUTH_BASIC) ? true: false)
}});
class Labels{
#docker;
#redis;
@@ -27,10 +34,6 @@ class Labels{
}
async watch(){
if(ENV_LABELS_WEBHOOK){
logJSON('info', `using webhook ${ENV_LABELS_WEBHOOK}`);
}
this.#redis = await redis.createClient({
url:process.env.LABELS_REDIS_URL,
pingInterval:30000,
@@ -41,7 +44,6 @@ class Labels{
this.#redis.connect();
this.#redis.on('ready', ()=>{
logJSON('info', 'successfully connected to redis');
(async() => {
await this.dockerPoll();
})();
@@ -49,7 +51,7 @@ class Labels{
});
this.#redis.on('error', error =>{
logJSON('error', error);
elevenLogJSON('error', error);
});
setInterval(async() => {
@@ -60,7 +62,7 @@ class Labels{
dockerEvents(){
this.#docker.getEvents({}, (error, data) => {
if(error){
logJSON('error', error);
elevenLogJSON('error', error);
}else{
data.on('data', async(chunk) => {
const event = JSON.parse(chunk.toString('utf8'));
@@ -84,7 +86,7 @@ class Labels{
}
});
}catch(e){
logJSON('error', e);
elevenLogJSON('error', e);
}finally{
this.#poll = false;
}
@@ -109,35 +111,39 @@ class Labels{
WAN:{server:'', key:'', commands:[]},
LAN:{server:'', key:'', commands:[]},
}
elevenLogJSON('info', `inspect container {${(data?.Name || data?.id).replace(/^\//i, '')}}${(
(null === status) ? '' : ` event[${status}]`
)}`);
for(const label in data?.Config?.Labels){
switch(true){
case /traefik\//i.test(label):
if(update){
await this.#redis.set(label, data?.Config?.Labels[label], {EX:ENV_REDIS_INTERVAL + ENV_REDIS_TIMEOUT});
await this.#redis.set(label, data.Config.Labels[label], {EX:ENV_REDIS_INTERVAL + ENV_REDIS_TIMEOUT});
}else{
await this.#redis.del(label);
}
container.labels.traefik[label] = data?.Config?.Labels[label];
container.labels.traefik[label] = data.Config.Labels[label];
break;
case /rfc2136\//i.test(label):
container.labels.rfc2136[label] = data?.Config?.Labels[label];
container.labels.rfc2136[label] = data.Config.Labels[label];
const type = ((label.match(/rfc2136\/WAN\//i)) ? 'WAN' : 'LAN');
switch(true){
case /rfc2136\/\S+\/server/i.test(label):
rfc2136[type].server = data?.Config?.Labels[label];
rfc2136[type].server = data.Config.Labels[label];
break;
case /rfc2136\/\S+\/key/i.test(label):
rfc2136[type].key = data?.Config?.Labels[label];
rfc2136[type].key = data.Config.Labels[label];
break;
default:
if(!update){
data?.Config?.Labels[label] = data?.Config?.Labels[label].replace(/update add/i, 'update delete');
data.Config.Labels[label] = data.Config.Labels[label].replace(/update add/i, 'update delete');
}
rfc2136[type].commands.push(data?.Config?.Labels[label]);
rfc2136[type].commands.push(data.Config.Labels[label]);
}
break;
}
@@ -148,7 +154,7 @@ class Labels{
try{
await nsupdate(rfc2136[type].server, rfc2136[type].key, rfc2136[type].commands);
}catch(e){
logJSON('error', e);
elevenLogJSON('error', e);
}
}
}
@@ -159,7 +165,7 @@ class Labels{
(update) ? 'PUT' : 'DELETE'
), body:JSON.stringify(container), headers:this.#webhook.headers, signal:AbortSignal.timeout(2500)});
}catch(e){
logJSON('error', e);
elevenLogJSON('error', e);
}
}