-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f2e324
commit 466175c
Showing
8 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM node:8.0.0 | ||
MAINTAINER Azure App Services Container Images <appsvc-images@microsoft.com> | ||
|
||
COPY startup /opt/startup | ||
COPY hostingstart.html /home/site/wwwroot/hostingstart.html | ||
COPY sshd_config /etc/ssh/ | ||
|
||
RUN npm install -g pm2 \ | ||
&& mkdir -p /home/LogFiles \ | ||
&& echo "root:Docker!" | chpasswd \ | ||
&& apt update \ | ||
&& apt install -y --no-install-recommends openssh-server \ | ||
&& cd /opt/startup \ | ||
&& npm install \ | ||
&& chmod 755 /opt/startup/init_container.sh | ||
|
||
EXPOSE 2222 8080 | ||
|
||
ENV PM2HOME /pm2home | ||
|
||
ENV PORT 8080 | ||
ENV WEBSITE_ROLE_INSTANCE_ID localRoleInstance | ||
ENV WEBSITE_INSTANCE_ID localInstance | ||
|
||
WORKDIR /home/site/wwwroot | ||
|
||
ENTRYPOINT ["/opt/startup/init_container.sh"] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This is ssh server systemwide configuration file. | ||
# | ||
# /etc/sshd_config | ||
|
||
Port 2222 | ||
ListenAddress 0.0.0.0 | ||
LoginGraceTime 180 | ||
X11Forwarding yes | ||
Ciphers aes128-cbc,3des-cbc,aes256-cbc | ||
MACs hmac-sha1,hmac-sha1-96 | ||
StrictModes yes | ||
SyslogFacility DAEMON | ||
PrintMotd no | ||
IgnoreRhosts no | ||
RhostsAuthentication no | ||
RhostsRSAAuthentication yes | ||
RSAAuthentication no | ||
PasswordAuthentication yes | ||
PermitEmptyPasswords no | ||
PermitRootLogin yes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var express = require('express'); | ||
var server = express(); | ||
var options = { | ||
index: 'hostingstart.html' | ||
}; | ||
server.use('/', express.static('/home/site/wwwroot', options)); | ||
server.listen(process.env.PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs'), | ||
util = require('util'); | ||
|
||
console.log("Generating app startup command"); | ||
|
||
const DEFAULTAPP = "/opt/startup/default-static-site.js"; | ||
const OUTFILE = "/opt/startup/startupCommand"; | ||
|
||
var httpLoggingEnabled = process.env.HTTP_LOGGING_ENABLED; | ||
httpLoggingEnabled = (typeof httpLoggingEnabled !== 'undefined' | ||
&& httpLoggingEnabled !== null | ||
&& (httpLoggingEnabled.toLowerCase() === 'true' || httpLoggingEnabled.toLowerCase() === '1')) | ||
|
||
console.log("HTTP logging enabled: " + httpLoggingEnabled) | ||
|
||
var roleInstanceId = ''; | ||
if (typeof process.env.WEBSITE_ROLE_INSTANCE_ID !== 'undefined' | ||
&& process.env.WEBSITE_ROLE_INSTANCE_ID !== null) { | ||
roleInstanceId = process.env.WEBSITE_ROLE_INSTANCE_ID; | ||
} | ||
|
||
var startupCommand; | ||
var appCommandLine = process.argv.slice(2); | ||
|
||
if (appCommandLine.length >= 2) { | ||
startupCommand = appCommandLine.join(" "); | ||
console.log("Fully specified startup command detected."); | ||
} | ||
else { | ||
var outFile = '/dev/null'; | ||
var errFile = '/dev/null'; | ||
|
||
if (httpLoggingEnabled) { | ||
outFile = util.format('/home/LogFiles/node_%s_out.log', roleInstanceId); | ||
errFile = util.format('/home/LogFiles/node_%s_err.log', roleInstanceId); | ||
} | ||
|
||
var pm2Template = util.format("pm2 start %%s --no-daemon --merge-logs -o %s -e %s", outFile, errFile); | ||
|
||
if (appCommandLine.length == 1) { | ||
// Assume a single-token appCommandLine is a startable node app, and | ||
// run it with pm2 | ||
console.log("Single-token startup command detected, running as JavaScript via PM2"); | ||
startupCommand = util.format(pm2Template, appCommandLine[0]); | ||
} | ||
else { | ||
// No appCommandLine, try to autodetect a user app | ||
var autos = ['bin/www', 'server.js', 'app.js', 'index.js', 'hostingstart.js']; | ||
for (var i = 0; i < autos.length; i++) { | ||
var filename = "/home/site/wwwroot/" + autos[i]; | ||
if (fs.existsSync(filename)) { | ||
console.log("Empty startup command detected, but found " + | ||
filename + ". Running as JavaScript via PM2."); | ||
startupCommand = util.format(pm2Template, filename); | ||
break; | ||
} | ||
} | ||
|
||
if (!startupCommand) | ||
{ | ||
var packageJsonPath = "/home/site/wwwroot/package.json"; | ||
var json = fs.existsSync(packageJsonPath) && JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) | ||
if (typeof json == 'object' | ||
&& typeof json.scripts == 'object' | ||
&& typeof json.scripts.start == 'string') | ||
{ | ||
console.log("Found scripts.start in package.json, running 'npm start'.") | ||
startupCommand = 'npm start'; | ||
} | ||
} | ||
|
||
if (!startupCommand) { | ||
console.log("Empty startup command detected and no candidate startup script " + | ||
"found. Running default static site."); | ||
startupCommand = util.format(pm2Template, DEFAULTAPP); | ||
} | ||
} | ||
} | ||
|
||
// Write to file | ||
fs.writeFileSync(OUTFILE, startupCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
service ssh start | ||
|
||
mkdir "$PM2HOME" | ||
chmod 777 "$PM2HOME" | ||
ln -s /home/LogFiles "$PM2HOME"/logs | ||
|
||
touch /home/LogFiles/node_${WEBSITE_ROLE_INSTANCE_ID}_out.log | ||
echo "$(date) Container started" >> /home/LogFiles/node_${WEBSITE_ROLE_INSTANCE_ID}_out.log | ||
|
||
node /opt/startup/generateStartupCommand.js "$@" | ||
|
||
STARTUPCOMMAND=$(cat /opt/startup/startupCommand) | ||
echo "Running $STARTUPCOMMAND" | ||
exec $STARTUPCOMMAND |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "default-static-site", | ||
"version": "1.0.0", | ||
"description": "Express-driven static site hosted from default App Service wwwroot directory", | ||
"main": "default-static-site.js", | ||
"dependencies": { | ||
"express": "4.15.3" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Azure App Services Container Images <appsvc-images@microsoft.com>", | ||
"license": "Apache-2.0" | ||
} |