Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding v8 image #14

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 8.0.0/Dockerfile
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"]
38 changes: 38 additions & 0 deletions 8.0.0/hostingstart.html

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions 8.0.0/sshd_config
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

7 changes: 7 additions & 0 deletions 8.0.0/startup/default-static-site.js
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);
82 changes: 82 additions & 0 deletions 8.0.0/startup/generateStartupCommand.js
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);
15 changes: 15 additions & 0 deletions 8.0.0/startup/init_container.sh
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
216 changes: 216 additions & 0 deletions 8.0.0/startup/npm-shrinkwrap.json

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

15 changes: 15 additions & 0 deletions 8.0.0/startup/package.json
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"
}