Skip to content

Commit

Permalink
Merge pull request #76 from yubiuser/multi-stage
Browse files Browse the repository at this point in the history
Switch to multi-stage build
  • Loading branch information
petersem authored May 14, 2024
2 parents f2270f4 + 20bc29a commit 44ca674
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM node:18-alpine3.17
ENV NODE_ENV=production
FROM node:22-alpine3.19 as builder
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent
RUN mv node_modules ../
COPY . .
COPY ["package.json", "package-lock.json*", "index.js", "./"]
RUN npm install --omit=dev

FROM alpine:3.19 as deploy
RUN apk add --no-cache nodejs
COPY --from=builder /usr/src/app /app
WORKDIR /app
EXPOSE 3000
HEALTHCHECK --interval=10s --timeout=5s --retries=3 --start-period=5s CMD wget --spider http://localhost:8000 > /dev/null || exit 1
CMD ["npm", "start"]
CMD ["node", "index.js"]
83 changes: 43 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,58 +118,61 @@ async function list(){
docker.listContainers(opts, function(err, containers) {
// check for changes in status (first run is populating data only)
let newConArray = [];
containers.forEach(c => {
// if label_enable is false then exclude any specifically false labelled containers
if(LABEL_ENABLE=='false' && JSON.stringify(c.Labels).includes('"monocker.enable":"false"')){
if(isFirstRun==true){
console.log(' - Excluding: ' + c.Names[0].replace("/",""));
//send('Excluding: ' + c.Names[0].replace("/",""));
messages += 'Excluding: ' + c.Names[0].replace("/","") + "\r\n";
}
}
else{
// If label_enable is true, list the specifically included containers
if(LABEL_ENABLE=='true' && JSON.stringify(c.Labels).includes('"monocker.enable":"true"')){
if(isFirstRun==true){
console.log(' - Monitoring: ' + c.Names[0].replace("/",""));
//send('Monitoring: ' + c.Names[0].replace("/",""));
messages += 'Monitoring: ' + c.Names[0].replace("/","") + "\r\n";
if (containers > 0) {
containers.forEach(c => {
// if label_enable is false then exclude any specifically false labelled containers
if (LABEL_ENABLE == 'false' && JSON.stringify(c.Labels).includes('"monocker.enable":"false"')) {
if (isFirstRun == true) {
console.log(' - Excluding: ' + c.Names[0].replace("/", ""));
//send('Excluding: ' + c.Names[0].replace("/",""));
messages += 'Excluding: ' + c.Names[0].replace("/", "") + "\r\n";
}
}
// determine if covered by healthcheck
let hcStatus = "";
if(c.Status.includes("(healthy)")) hcStatus="(healthy)"
if(c.Status.includes("(unhealthy)")) hcStatus="(unhealthy)"
if(monContainers.includes(c.Id + "," + c.State + "," + c.Names[0] + "," + hcStatus) == false && monContainers.length !== 0 ){
// exclude exited status if set
if(EXCLUDE_EXITED == 'true' && c.State.toLocaleLowerCase() == 'exited'){
// ignore
else {
// If label_enable is true, list the specifically included containers
if (LABEL_ENABLE == 'true' && JSON.stringify(c.Labels).includes('"monocker.enable":"true"')) {
if (isFirstRun == true) {
console.log(' - Monitoring: ' + c.Names[0].replace("/", ""));
//send('Monitoring: ' + c.Names[0].replace("/",""));
messages += 'Monitoring: ' + c.Names[0].replace("/", "") + "\r\n";
}
}
else{
// if only offline is set, then only show state changes that are offline
var output = c.Names[0].replace("/","") + ": " + c.State + " " + hcStatus;
if(SHA.toLowerCase()=='true'){
output += " " + c.ImageID
// determine if covered by healthcheck
let hcStatus = "";
if (c.Status.includes("(healthy)")) hcStatus = "(healthy)"
if (c.Status.includes("(unhealthy)")) hcStatus = "(unhealthy)"
if (monContainers.includes(c.Id + "," + c.State + "," + c.Names[0] + "," + hcStatus) == false && monContainers.length !== 0) {
// exclude exited status if set
if (EXCLUDE_EXITED == 'true' && c.State.toLocaleLowerCase() == 'exited') {
// ignore
}
if(ONLY_OFFLINE_STATES=='true'){
if(offlineStates.includes(c.State) || offlineStates.includes(c.State + " " + hcStatus)){
else {
// if only offline is set, then only show state changes that are offline
var output = c.Names[0].replace("/", "") + ": " + c.State + " " + hcStatus;
if (SHA.toLowerCase() == 'true') {
output += " " + c.ImageID
}
if (ONLY_OFFLINE_STATES == 'true') {
if (offlineStates.includes(c.State) || offlineStates.includes(c.State + " " + hcStatus)) {
console.log(" - " + output);
//send(output);
messages += output + "\r\n";
}
}
else {
console.log(" - " + output);
//send(output);
console.log('*****' + output);
messages += output + "\r\n";
}
}
else{
console.log(" - " + output);
//send(output);
console.log('*****' + output);
messages += output+ "\r\n";
}
}
// create new container array
newConArray.push(c.Id + "," + c.State + "," + c.Names[0] + "," + hcStatus);
}
// create new container array
newConArray.push(c.Id + "," + c.State + "," + c.Names[0] + "," + hcStatus);
}
});
);
}
if(isFirstRun==true){
console.log(" - Currently monitoring " + newConArray.length + " (running) containers");
if(DISABLE_STARTUP_MSG.toLowerCase()!='true'){
Expand Down

0 comments on commit 44ca674

Please sign in to comment.