|
| 1 | +# Dockerfile extending the generic Node image with application files for a |
| 2 | +# single application. |
| 3 | +FROM beta.gcr.io/google_appengine/nodejs |
| 4 | +# Check to see if the the version included in the base runtime satisfies \ |
| 5 | +# >=4.1.0, if not then do an npm install of the latest available \ |
| 6 | +# version that satisfies it. \ |
| 7 | +RUN npm install https://storage.googleapis.com/gae_node_packages/semver.tar.gz && \ |
| 8 | + (node -e 'var semver = require("semver"); \ |
| 9 | + if (!semver.satisfies(process.version, ">=4.1.0")) \ |
| 10 | + process.exit(1);' || \ |
| 11 | + (version=$(curl -L https://storage.googleapis.com/gae_node_packages/node_versions | \ |
| 12 | + node -e ' \ |
| 13 | + var semver = require("semver"); \ |
| 14 | + var http = require("http"); \ |
| 15 | + var spec = process.argv[1]; \ |
| 16 | + var latest = ""; \ |
| 17 | + var versions = ""; \ |
| 18 | + var selected_version; \ |
| 19 | + \ |
| 20 | + function verifyBinary(version) { \ |
| 21 | + var options = { \ |
| 22 | + "host": "storage.googleapis.com", \ |
| 23 | + "method": "HEAD", \ |
| 24 | + "path": "/gae_node_packages/node-" + version + \ |
| 25 | + "-linux-x64.tar.gz" \ |
| 26 | + }; \ |
| 27 | + var req = http.request(options, function (res) { \ |
| 28 | + if (res.statusCode == 404) { \ |
| 29 | + console.error("Binaries for Node satisfying version " + \ |
| 30 | + version + " are not available."); \ |
| 31 | + process.exit(1); \ |
| 32 | + } \ |
| 33 | + }); \ |
| 34 | + req.end(); \ |
| 35 | + } \ |
| 36 | + function satisfies(version) { \ |
| 37 | + if (semver.satisfies(version, spec)) { \ |
| 38 | + process.stdout.write(version); \ |
| 39 | + verifyBinary(version); \ |
| 40 | + return true; \ |
| 41 | + } \ |
| 42 | + } \ |
| 43 | + process.stdin.on("data", function(data) { \ |
| 44 | + versions += data; \ |
| 45 | + }); \ |
| 46 | + process.stdin.on("end", function() { \ |
| 47 | + versions = \ |
| 48 | + versions.split("\n").sort().reverse(); \ |
| 49 | + if (!versions.some(satisfies)) { \ |
| 50 | + console.error("No version of Node found satisfying: " + \ |
| 51 | + spec); \ |
| 52 | + process.exit(1); \ |
| 53 | + } \ |
| 54 | + });' \ |
| 55 | + ">=4.1.0") && \ |
| 56 | + rm -rf /nodejs/* && \ |
| 57 | + (curl https://storage.googleapis.com/gae_node_packages/node-$version-linux-x64.tar.gz | \ |
| 58 | + tar xzf - -C /nodejs --strip-components=1 \ |
| 59 | + ) \ |
| 60 | + ) \ |
| 61 | + ) |
| 62 | +COPY . /app/ |
| 63 | +# You have to specify "--unsafe-perm" with npm install |
| 64 | +# when running as root. Failing to do this can cause |
| 65 | +# install to appear to succeed even if a preinstall |
| 66 | +# script fails, and may have other adverse consequences |
| 67 | +# as well. |
| 68 | +RUN npm --unsafe-perm install |
| 69 | +CMD npm start |
0 commit comments