-
Notifications
You must be signed in to change notification settings - Fork 234
chore(build): notarize dmg COMPASS-7489 #5354
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51bced8
notarize dmg
mabaasit 4f787be
pr feedback
mabaasit dd78b46
lint
mabaasit 3c2382a
Merge branch 'main' into notarize-dmg
mabaasit b32a6bb
pr feedback
mabaasit 0f8f111
Merge branch 'notarize-dmg' of https://github.com/mongodb-js/compass …
mabaasit 1e8a4f0
Merge branch 'main' of https://github.com/mongodb-js/compass into not…
mabaasit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
// eslint-disable-next-line strict | ||
'use strict'; | ||
const download = require('download'); | ||
const path = require('path'); | ||
const { promises: fs } = require('fs'); | ||
const debug = require('debug')('hadron-build:macos-notarization'); | ||
const { promisify } = require('util'); | ||
const childProcess = require('child_process'); | ||
const execFile = promisify(childProcess.execFile); | ||
|
||
async function setupMacosNotary() { | ||
try { | ||
await fs.access('macnotary/macnotary'); | ||
debug('macnotary already downloaded'); | ||
} catch (err) { | ||
debug('downloading macnotary'); | ||
await download(process.env.MACOS_NOTARY_CLIENT_URL, 'macnotary', { | ||
extract: true, | ||
strip: 1 // remove leading platform + arch directory | ||
}); | ||
await fs.chmod('macnotary/macnotary', 0o755); // ensure +x is set | ||
} | ||
} | ||
|
||
/** | ||
* Notarize a resource with the macOS notary service. | ||
* https://wiki.corp.mongodb.com/display/BUILD/How+to+use+MacOS+notary+service | ||
* | ||
* Notarization is a three step process: | ||
* 1. All the files to be notarized are zipped up into a single file. | ||
* 2. The zip file is uploaded to the notary service. It signs all the | ||
* files in the zip file and returns a new zip file with the signed files. | ||
* 3. The orginal files are removed and the signed files are unzipped into | ||
* their place. | ||
* | ||
* @param {string} src The path to the resource to notarize. It can be a directory or a file. | ||
* @param {object} notarizeOptions | ||
* @param {string} notarizeOptions.bundleId | ||
* @param {string} [notarizeOptions.macosEntitlements] | ||
*/ | ||
async function notarize(src, notarizeOptions) { | ||
debug(`Signing and notarizing "${src}"`); | ||
|
||
await setupMacosNotary(); | ||
|
||
const fileName = path.basename(src); | ||
const unsignedArchive = `${fileName}.zip`; | ||
const signedArchive = `${fileName}.signed.zip`; | ||
|
||
const execOpts = { | ||
cwd: path.dirname(src), | ||
encoding: 'utf8', | ||
}; | ||
|
||
// Step:1 - zip up the file/folder to unsignedArchive | ||
debug(`running "zip -y -r '${unsignedArchive}' '${fileName}'"`); | ||
await execFile('zip', ['-y', '-r', unsignedArchive, fileName], execOpts); | ||
|
||
try { | ||
// Step:2 - send the zip to notary service and save the result to signedArchive | ||
debug(`sending file to notary service (bundle id = ${notarizeOptions.bundleId})`); | ||
const macnotaryResult = await execFile(path.resolve('macnotary/macnotary'), [ | ||
'-t', 'app', | ||
'-m', 'notarizeAndSign', | ||
'-u', process.env.MACOS_NOTARY_API_URL, | ||
'-b', notarizeOptions.bundleId, | ||
'-f', unsignedArchive, | ||
'-o', signedArchive, | ||
'--verify', | ||
...(notarizeOptions.macosEntitlements ? ['-e', notarizeOptions.macosEntitlements] : []) | ||
], execOpts); | ||
debug('macnotary result:', macnotaryResult.stdout, macnotaryResult.stderr); | ||
debug('ls', (await execFile('ls', ['-lh'], execOpts)).stdout); | ||
|
||
// Step:3 - remove existing src, unzip signedArchive to src | ||
debug('removing existing directory contents'); | ||
await execFile('rm', ['-r', fileName], execOpts); | ||
debug(`unzipping with "unzip -u ${signedArchive}"`); | ||
await execFile('unzip', ['-u', signedArchive], execOpts); | ||
} finally { | ||
// cleanup - remove signedArchive and unsignedArchive | ||
debug('ls', (await execFile('ls', ['-lh'], execOpts)).stdout); | ||
debug(`removing ${signedArchive} and ${unsignedArchive}`); | ||
await execFile('rm', ['-r', signedArchive, unsignedArchive], execOpts).catch(err => { | ||
debug('error cleaning up', err); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { notarize }; |
This file contains hidden or 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 |
---|---|---|
@@ -1,23 +1,20 @@ | ||
// eslint-disable-next-line strict | ||
'use strict'; | ||
const chalk = require('chalk'); | ||
const childProcess = require('child_process'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice seeing some line of code leaving this file! :) |
||
const download = require('download'); | ||
const fs = require('fs'); | ||
const _ = require('lodash'); | ||
const semver = require('semver'); | ||
const path = require('path'); | ||
const { promisify } = require('util'); | ||
const normalizePkg = require('normalize-package-data'); | ||
const parseGitHubRepoURL = require('parse-github-repo-url'); | ||
const ffmpegAfterExtract = require('electron-packager-plugin-non-proprietary-codecs-ffmpeg').default; | ||
const windowsInstallerVersion = require('./windows-installer-version'); | ||
const debug = require('debug')('hadron-build:target'); | ||
const execFile = promisify(childProcess.execFile); | ||
const which = require('which'); | ||
const plist = require('plist'); | ||
const { sign, getSignedFilename } = require('./signtool'); | ||
const tarGz = require('./tar-gz'); | ||
const { notarize } = require('./mac-notary-service'); | ||
|
||
function _canBuildInstaller(ext) { | ||
var bin = null; | ||
|
@@ -562,7 +559,6 @@ class Target { | |
}; | ||
|
||
this.createInstaller = async() => { | ||
const appDirectoryName = `${this.productName}.app`; | ||
const appPath = this.appPath; | ||
|
||
{ | ||
|
@@ -580,58 +576,32 @@ class Target { | |
await fs.promises.writeFile(plistFilePath, plist.build(plistContents)); | ||
} | ||
|
||
if (process.env.MACOS_NOTARY_KEY && | ||
process.env.MACOS_NOTARY_SECRET && | ||
process.env.MACOS_NOTARY_CLIENT_URL && | ||
process.env.MACOS_NOTARY_API_URL) { | ||
debug(`Signing and notarizing "${appPath}"`); | ||
// https://wiki.corp.mongodb.com/display/BUILD/How+to+use+MacOS+notary+service | ||
debug(`Downloading the notary client from ${process.env.MACOS_NOTARY_CLIENT_URL} to ${path.resolve('macnotary')}`); | ||
await download(process.env.MACOS_NOTARY_CLIENT_URL, 'macnotary', { | ||
extract: true, | ||
strip: 1 // remove leading platform + arch directory | ||
}); | ||
await fs.promises.chmod('macnotary/macnotary', 0o755); // ensure +x is set | ||
const isNotarizationPossible = process.env.MACOS_NOTARY_KEY && | ||
process.env.MACOS_NOTARY_SECRET && | ||
process.env.MACOS_NOTARY_CLIENT_URL && | ||
process.env.MACOS_NOTARY_API_URL; | ||
|
||
debug(`running "zip -y -r '${appDirectoryName}.zip' '${appDirectoryName}'"`); | ||
await execFile('zip', ['-y', '-r', `${appDirectoryName}.zip`, appDirectoryName], { | ||
cwd: path.dirname(appPath) | ||
}); | ||
debug(`sending file to notary service (bundle id = ${this.bundleId})`); | ||
const macnotaryResult = await execFile(path.resolve('macnotary/macnotary'), [ | ||
'-t', 'app', | ||
'-m', 'notarizeAndSign', | ||
'-u', process.env.MACOS_NOTARY_API_URL, | ||
'-b', this.bundleId, | ||
'-f', `${appDirectoryName}.zip`, | ||
'-o', `${appDirectoryName}.signed.zip`, | ||
'--verify', | ||
...(this.macosEntitlements ? ['-e', this.macosEntitlements] : []) | ||
], { | ||
cwd: path.dirname(appPath), | ||
encoding: 'utf8' | ||
}); | ||
debug('macnotary result:', macnotaryResult.stdout, macnotaryResult.stderr); | ||
debug('ls', (await execFile('ls', ['-lh'], { cwd: path.dirname(appPath), encoding: 'utf8' })).stdout); | ||
debug('removing existing directory contents'); | ||
await execFile('rm', ['-r', appDirectoryName], { | ||
cwd: path.dirname(appPath) | ||
}); | ||
debug(`unzipping with "unzip -u '${appDirectoryName}.signed.zip'"`); | ||
await execFile('unzip', ['-u', `${appDirectoryName}.signed.zip`], { | ||
cwd: path.dirname(appPath), | ||
encoding: 'utf8' | ||
}); | ||
debug('ls', (await execFile('ls', ['-lh'], { cwd: path.dirname(appPath), encoding: 'utf8' })).stdout); | ||
debug(`removing '${appDirectoryName}.signed.zip' and '${appDirectoryName}.zip'`); | ||
await fs.promises.unlink(`${appPath}.signed.zip`); | ||
await fs.promises.unlink(`${appPath}.zip`); | ||
const notarizationOptions = { | ||
bundleId: this.bundleId, | ||
macosEntitlements: this.macosEntitlements | ||
}; | ||
|
||
if (isNotarizationPossible) { | ||
await notarize(appPath, notarizationOptions); | ||
} else { | ||
console.error(chalk.yellow.bold( | ||
'WARNING: macos notary service credentials not set -- skipping signing and notarization!')); | ||
'WARNING: macos notary service credentials not set -- skipping signing and notarization of .app!')); | ||
} | ||
|
||
const createDMG = require('electron-installer-dmg'); | ||
await createDMG(this.installerOptions); | ||
|
||
if (isNotarizationPossible) { | ||
await notarize(this.installerOptions.dmgPath, notarizationOptions); | ||
} else { | ||
console.error(chalk.yellow.bold( | ||
'WARNING: macos notary service credentials not set -- skipping signing and notarization of .dmg!')); | ||
} | ||
}; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.