Compare commits
7
Commits
dev
...
arm64v8-0.1.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eadac07bb | ||
|
|
e129945fde | ||
|
|
2d9bfafffa | ||
|
|
823151dc98 | ||
|
|
7bd574c3a3 | ||
|
|
e7c3a83ae2 | ||
|
|
24a2e20641 |
@@ -1,5 +1,5 @@
|
||||
# Alpine :: Traefik Labels
|
||||
    
|
||||
    
|
||||
|
||||
Run Traefik Labels based on Alpine Linux. Small, lightweight, secure and fast 🏔️
|
||||
|
||||
|
||||
+3
-2
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user