Skip to content

Commit

Permalink
Haufe-Lexware/wicked.haufe.io#56 Run portal API as user wicked
Browse files Browse the repository at this point in the history
  • Loading branch information
DonMartin76 committed Feb 13, 2017
1 parent 5b6d1f3 commit 84956de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Dockerfile.template
@@ -1,5 +1,9 @@
FROM ${DOCKER_PREFIX}portal-env:${DOCKER_TAG}-onbuild

# Default user is "wicked", but we need root to set all access rights
# correctly, and then start node as wicked using gosu.
USER root

EXPOSE 3001

RUN cp -R /usr/src/portal-env/initial-config /var/portal-api
Expand Down
9 changes: 8 additions & 1 deletion bin/api
Expand Up @@ -24,6 +24,8 @@ var port = normalizePort(process.env.PORT || '3001');
app.set('port', port);

console.log("Portal API environment: " + app.get('env'));
const osUsername = getOsUsername();
console.log("Running as user '" + osUsername + "'");

var environment = app.get('env');
var staticConfigPath = envReader.resolveStaticConfig();
Expand Down Expand Up @@ -101,7 +103,7 @@ initializer.checkDynamicConfig(app, function (err, results) {
server.on('listening', onListening);

// Graceful shutdown
const shutdown = function(signal) {
const shutdown = function (signal) {
app.shuttingDown = true;
console.log("Received " + signal + ". Gracefully shutting down.");
setTimeout(process.exit, 1000);
Expand Down Expand Up @@ -179,4 +181,9 @@ function findEnvKeyFileName(baseDir) {
return path.join(baseDir, fileName);
}
return null;
}

function getOsUsername() {
var username = require('child_process').execSync("whoami", { encoding: 'utf8', timeout: 1000 });
return String(username).trim();
}
10 changes: 7 additions & 3 deletions bin/docker-start.sh
Expand Up @@ -82,8 +82,12 @@ printf ${tempMd5Hash:0:32} > /var/portal-api/static/confighash
echo "Hash: $(cat /var/portal-api/static/confighash)"
popd

export

echo "Setting owner of /var/portal-api to wicked:wicked"
chown -R wicked:wicked /var/portal-api

echo "Starting API..."

# Use direct starting via node, as npm prevents
# SIGTERM being passed in to the node process.
node bin/api
# Use gosu to start node as the user "wicked"
gosu wicked node bin/api

0 comments on commit 84956de

Please sign in to comment.