Skip to content

Commit

Permalink
Patch release (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk authored Nov 9, 2021
1 parent e21b6bd commit 4d75906
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 92 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ If running in an Azure Web App, all of these values can be injected as applicati
| TODO_MONGO_CONNSTR | _none_ | Connect to specified MongoDB instance, when set the Todo feature will be enabled in the menu bar |
| TODO_MONGO_DB | todoDb | Name of the database in MongoDB to use (optional) |
| APPINSIGHTS_INSTRUMENTATIONKEY | _none_ | Enable Application Insights monitoring |
| WEATHER_API_KEY | _none_ | DarkSky weather API key. [Info here](https://openweathermap.org/api) |
| WEATHER_API_KEY | _none_ | OpenWeather API key. [Info here](https://openweathermap.org/api) |
| AAD_APP_ID | _none_ | Application ID of app registered in Azure AD |
| AAD_APP_SECRET | _none_ | Secret / password of app registered in Azure AD |
| AAD_REDIRECT_URL_BASE | _none_ | Hostname/domain where app is running |
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG ARCH=
ARG IMAGE_BASE=14-alpine

FROM ${ARCH}node:$IMAGE_BASE
LABEL Name="Node.js Demo App" Version=4.8.0
LABEL Name="Node.js Demo App" Version=4.8.1
LABEL org.opencontainers.image.source = "https://github.com/benc-uk/nodejs-demoapp"
ENV NODE_ENV production
WORKDIR /app
Expand Down
81 changes: 32 additions & 49 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nodejs-demoapp",
"description": "Node.js Express app for demos",
"version": "4.8.0",
"version": "4.8.1",
"author": "Ben Coleman",
"engines": {
"node": ">=14.0.0"
Expand Down
Binary file added src/public/images/container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions src/routes/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ router.get('/info', function (req, res, next) {
uptime: convertSeconds(os.uptime()),
}

const isKube = fs.existsSync('/var/run/secrets/kubernetes.io')
let isContainer = isKube || fs.existsSync('/.dockerenv')

// Fallback to try to detect containerd, only works when *NOT* in Kubernetes
if (!isContainer) {
try {
const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8')
if (cgroup.includes('containerd')) {
isContainer = true
}
} catch (err) {
isContainer = false
}
}

res.render('info', {
title: 'Node DemoApp: Info',
info: info,
isDocker: fs.existsSync('/.dockerenv'),
isKube: fs.existsSync('/var/run/secrets/kubernetes.io'),
isKube: isKube,
isContainer: isContainer,
})
})

Expand Down Expand Up @@ -141,6 +156,6 @@ function convertSeconds(n) {
n %= 3600
let mins = Math.floor(n / 60)
n %= 60
let secs = n
let secs = Math.round(n)
return `${days} days, ${hours} hours, ${mins} mins, ${secs} seconds`
}
8 changes: 4 additions & 4 deletions src/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ul>
<li>System status / information view</li>
<li>App Insights support</li>
<li>Geolocated weather info (from DarkSky API)</li>
<li>Geolocated weather info (from OpenWeather API)</li>
<li>Tools for triggering errors and high CPU load</li>
<li>Mini todo app using MongoDB data store</li>
<li>Support for user authentication with Azure AD</li>
Expand All @@ -23,9 +23,9 @@
<a target='_blank' href='https://github.com/benc-uk/nodejs-demoapp' class="btn btn-info btn-lg">Project on
Github</a>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<img src='images/docker.png' width='58px' /> &nbsp;
<a target='_blank' href='https://hub.docker.com/r/bencuk/nodejs-demoapp' class="btn btn-info btn-lg">Docker images
on Dockerhub</a>
<img src='images/container.png' width='58px' /> &nbsp;
<a target='_blank' href='https://github.com/benc-uk/nodejs-demoapp/pkgs/container/nodejs-demoapp' class="btn btn-info btn-lg">Container Images
on GitHub</a>
</p>


Expand Down
58 changes: 25 additions & 33 deletions src/views/info.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,102 @@
<div class="card text-white bg-secondary">
<div class="card-header bg-info h3"><i class="fas fa-question-circle"></i> &nbsp; System Runtime Information</div>
<div class="card-body">

<table class="table table-striped h5">

<tr>
<td><i class="fa fa-cube"></i></td>
<td> Containerized</td>
<% if (isDocker) { %>
<td>Looks like we're running in a Docker container! 😁 </td>
<td>Containerized</td>
<% if (isContainer) { %>
<td>Looks like we're running in a container! 😁</td>
<% } else { %>
<td>Not running as a Docker container 😢 </td>
<td>Not running as a container 😢</td>
<% } %>
</tr>
<tr>
<td><i class="fa fa-project-diagram"></i></td>
<td> Kubernetes</td>
<td>Kubernetes</td>
<% if (isKube) { %>
<td>We're also running in a Kubernetes pod! 😃 </td>
<td>We're also running in a Kubernetes pod! 😃</td>
<% } else { %>
<td>Not running in Kubernetes 😢 </td>
<td>Not running in Kubernetes 😢</td>
<% } %>
</tr>

<tr>
<td>&nbsp;<i class="fas fa-lightbulb"></i></td>
<td> App Insights</td>
<td>App Insights</td>
<% if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) { %>
<td>Reporting data to App Insights, nice job! </td>
<td>Reporting data to App Insights, nice job!</td>
<% } else { %>
<td>Not reporting data to App Insights</td>
<% } %>
</tr>

<tr>
<td><i class="fa fa-home"></i></td>
<td> Hostname</td>
<td>Hostname</td>
<td><%= info.hostname %></td>
</tr>
<tr>
<td><i class="fa fa-clock"></i></td>
<td> System Uptime</td>
<td>System Uptime</td>
<td><%= info.uptime %></td>
</tr>
<tr>
<td><i class="fas fa-laptop"></i></td>
<td> OS Version</td>
<td>OS Version</td>
<td><%= info.type %> - <%= info.release %></td>
</tr>
<tr>
<td><i class="fa fa-wrench"></i></td>
<td> Architecture</td>
<td>Architecture</td>
<td><%= info.arch %></td>
</tr>
<tr>
<td><i class="fa fa-microchip"></i></td>
<td> Processors</td>
<td>Processors</td>
<td><%= info.cpus.length%> &times; <%= info.cpus[0].model %></td>
</tr>
<tr>
<td><i class="fas fa-memory"></i></td>
<td> Memory</td>
<td>Memory</td>
<td><%= info.mem %> MB</td>
</tr>
<tr>
<td><i class="fab fa-codepen"></i></td>
<td> Node Version</td>
<td>Node Version</td>
<td><%= info.nodever %></td>
</tr>
<% if (process.env.RELEASE_INFO) { %>
<tr>
<tr>
<td><i class="fa fa-window-restore"></i></td>
<td> Release Info</td>
<td>Release Info</td>
<td><%= process.env.RELEASE_INFO %></td>
</tr>
<% } %>
</table>

</div>
</div>

<br>
<br />

<div class="card text-white bg-secondary">
<div class="card-header bg-info h3"><i class="fa fa-sitemap"></i> &nbsp; Server Environmental Variables</div>
<div class="card-body">

<div class="envtable">
<table class="table table-hover">
<% for(let envVar in process.env) { %>
<% if (envVar.toUpperCase().includes('SECRET')) continue %>
<% if (envVar.toUpperCase().includes('PWD')) continue %>
<% if (envVar.toUpperCase().includes('PASSWORD')) continue %>
<% if (envVar.toUpperCase().includes('KEY')) continue %>
<% if (envVar.toUpperCase().includes('PATH')) continue %>
<% if (envVar.toUpperCase().includes('NPM_')) continue %>
<% for(let envVar in process.env) { %> <% if (envVar.toUpperCase().includes('SECRET')) continue %> <% if
(envVar.toUpperCase().includes('PWD')) continue %> <% if (envVar.toUpperCase().includes('PASSWORD')) continue %>
<% if (envVar.toUpperCase().includes('KEY')) continue %> <% if (envVar.toUpperCase().includes('PATH')) continue
%> <% if (envVar.toUpperCase().includes('NPM_')) continue %>
<tr>
<td> <%= envVar %> </td>
<td><%= envVar %></td>
<td class="envvars"><%= process.env[envVar] %></td>
</tr>
<% } %>
</table>
</div>

</div>
</div>

<%- include('_foot.ejs') %>
<%- include('_foot.ejs') %>

0 comments on commit 4d75906

Please sign in to comment.