18f-pages-server
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -114,3 +114,4 @@ 'use strict'; | ||
new ComponentFactory(config, builderOpts, branch, logger)), | ||
finishBuild; | ||
finishBuild, | ||
migrateLog; | ||
@@ -129,5 +130,2 @@ logger.log(info.repository.full_name + ':', | ||
// latest status. | ||
var newLogPath = path.join( | ||
builder.configHandler.buildDestination, 'build.log'); | ||
if (err) { | ||
@@ -139,23 +137,59 @@ logger.error(err.message ? err.message : err); | ||
} | ||
logger.close(function() { | ||
return err ? reject(err) : resolve(); | ||
}); | ||
}); | ||
}; | ||
fs.rename(buildLog, newLogPath, function(renameErr) { | ||
var errMsg; | ||
migrateLog = function(err) { | ||
var newLogPath = path.join( | ||
builder.configHandler.buildDestination, 'build.log'); | ||
if (renameErr) { | ||
errMsg = 'Error moving build log: ' + renameErr; | ||
console.error(errMsg); | ||
if (!err) { | ||
reject(errMsg); | ||
} | ||
} | ||
logger.close(function() { | ||
return err ? reject(err) : resolve(); | ||
}); | ||
return copyLog(buildLog, newLogPath) | ||
.then(function() { | ||
return removeLog(buildLog); | ||
}) | ||
.catch(function(err) { | ||
console.error('Error moving build log: ' + (err.message || err)); | ||
return Promise.reject(err); | ||
}) | ||
.then(function() { | ||
return err ? Promise.reject(err) : Promise.resolve(); | ||
}); | ||
}); | ||
}; | ||
return builder.build() | ||
.then(finishBuild, finishBuild); | ||
.then(finishBuild, finishBuild) | ||
.then(migrateLog, migrateLog); | ||
}; | ||
// In the Dockerized 18F/knowledge-sharing-toolkit environment, the git | ||
// repositories live on one Docker volume (pages/repos), and the generated | ||
// sites live on another (pages/sites). This server orignally used | ||
// fs.rename(), which failed in this environment with the error: | ||
// | ||
// Error moving build log: Error: EXDEV: cross-device link not permitted, | ||
// rename '/usr/local/18f/pages/repos/pages-internal.18f.gov/hub.log' -> | ||
// '/usr/local/18f/pages/sites/pages-internal.18f.gov/hub/build.log' | ||
// | ||
// Copying and manually removing the original log resolves this issue. | ||
function copyLog(sourceLog, targetLog) { | ||
return new Promise(function(resolve, reject) { | ||
var sourceStream = fs.createReadStream(sourceLog), | ||
targetStream = fs.createWriteStream(targetLog); | ||
sourceStream.on('error', reject); | ||
targetStream.on('error', reject); | ||
targetStream.on('close', resolve); | ||
sourceStream.pipe(targetStream); | ||
}); | ||
} | ||
function removeLog(sourceLog) { | ||
return new Promise(function(resolve, reject) { | ||
fs.unlink(sourceLog, function(err) { | ||
return err ? reject(err) : resolve(); | ||
}); | ||
}); | ||
} | ||
SiteBuilder.makeBuilderListener = function(webhook, builderConfig) { | ||
@@ -162,0 +196,0 @@ var org = builderConfig.githubOrg || config.githubOrg, |
{ | ||
"name": "18f-pages-server", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Static website publishing server for 18F Pages", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129916
2339