Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9e8b899
feat(manfile): setup npm script to fetch manual file
mabaasit Oct 26, 2021
0887a63
feat(manfile): github action to commit manual file
mabaasit Oct 26, 2021
3c6446b
chore(manfile): extract file name
mabaasit Oct 26, 2021
aa9fac4
feat(manfile): add manfile in tarball build
mabaasit Oct 26, 2021
ef3d97c
test(manfile): add fixtures and fix tests
mabaasit Oct 26, 2021
4063759
feat(manfile): add manfile to every distribution
mabaasit Oct 26, 2021
127a94b
test(manfile): fix tests
mabaasit Oct 26, 2021
5d88895
chore(manfile): better var names
mabaasit Oct 26, 2021
7b365a5
chore(manfile): clean up
mabaasit Oct 26, 2021
b51314c
feat(manfile): include manfile in all packages
mabaasit Oct 27, 2021
52cacc7
test(manfile): add test conditions for rpm and deb
mabaasit Oct 27, 2021
5443174
test(manfile): download manpage in packag step
mabaasit Oct 27, 2021
5eafecf
chore(manfile): clean up download
mabaasit Oct 27, 2021
dfab808
fix(manfile): clean up build config
mabaasit Oct 27, 2021
f02e068
fix(manfile): extract manpage config
mabaasit Oct 27, 2021
9ae2f9d
fix(manfile): correct filename in fixtures
mabaasit Oct 27, 2021
e0223fe
feat(manfile): optional manfile in build config
mabaasit Oct 27, 2021
5e855ae
feat(manfile): correctly zip manfile and clean up config
mabaasit Oct 28, 2021
5b05084
chore(manfile): remove man config
mabaasit Oct 28, 2021
2871f30
chore(manfile): consistent naming
mabaasit Oct 28, 2021
e2d817b
chore(manfile): cr clean up, ensure file is zipped
mabaasit Oct 28, 2021
38feb99
test(manfile): fix tests and test for manpage
mabaasit Oct 29, 2021
5da2386
chore(manfile): cr clean up, gzip implementation
mabaasit Nov 1, 2021
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
23 changes: 21 additions & 2 deletions config/build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const os = require('os');
*/
const ROOT = path.join(__dirname, '..');

/**
* The tmp folder location.
*/
const TMP_DIR = path.join(ROOT, 'tmp');

/**
* The mongosh package.
*/
Expand Down Expand Up @@ -44,7 +49,7 @@ const EXECUTABLE_PATH = path.join(OUTPUT_DIR, process.platform === 'win32' ? 'mo
* We use the name mongocryptd-mongosh to avoid conflicts with users
* potentially installing the 'proper' mongocryptd package.
*/
const MONGOCRYPTD_PATH = path.resolve(__dirname, '..', 'tmp', 'mongocryptd-mongosh' + (process.platform === 'win32' ? '.exe' : ''));
const MONGOCRYPTD_PATH = path.resolve(TMP_DIR, 'mongocryptd-mongosh' + (process.platform === 'win32' ? '.exe' : ''));

/**
* Build info JSON data file.
Expand All @@ -66,6 +71,11 @@ const REVISION = process.env.GITHUB_COMMIT ?? process.env.REVISION;
*/
const COPYRIGHT = `${new Date().getYear() + 1900} MongoDB, Inc.`;

/**
* The manual page file name
*/
const MANPAGE_NAME = 'mongosh.1.gz'

/**
* Export the configuration for the build.
*/
Expand Down Expand Up @@ -141,6 +151,10 @@ module.exports = {
packagedFilePath: 'THIRD_PARTY_NOTICES'
}
],
manpage: {
sourceFilePath: path.resolve(TMP_DIR, 'manpage', MANPAGE_NAME),
packagedFilePath: MANPAGE_NAME,
},
metadata: {
name: 'mongosh',
rpmName: 'mongodb-mongosh',
Expand All @@ -159,5 +173,10 @@ module.exports = {
debTemplateDir: path.resolve(__dirname, '..', 'packaging', 'deb-template'),
rpmTemplateDir: path.resolve(__dirname, '..', 'packaging', 'rpm-template'),
msiTemplateDir: path.resolve(__dirname, '..', 'packaging', 'msi-template')
}
},
manpage: {
sourceUrl: 'https://docs.mongodb.com/mongodb-shell/manpages.tar.gz',
downloadPath: path.resolve(TMP_DIR, 'manpage'),
fileName: MANPAGE_NAME,
},
};
7 changes: 7 additions & 0 deletions packages/build/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { PackageInformation } from '../packaging/package';
import { BuildVariant } from './build-variant';

interface ManPageConfig {
sourceUrl: string;
downloadPath: string;
fileName: string;
}

/**
* Defines the configuration interface for the build system.
*/
Expand Down Expand Up @@ -42,4 +48,5 @@ export interface Config {
mongocryptdPath: string;
packageInformation?: PackageInformation;
artifactUrlFile?: string;
manpage?: ManPageConfig;
}
20 changes: 20 additions & 0 deletions packages/build/src/packaging/download-manpage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import nock from 'nock';
import { join } from 'path';
import { promises as fs } from 'fs';
import { downloadManpage } from './download-manpage';

describe('packaging download manpage', () => {
it('downloads manpage', async() => {
nock('http://example.com')
.get('/')
.replyWithFile(
200,
join(__dirname, '..', '..', 'test', 'fixtures', 'manpages.tar.gz')
);

const destination = join(__dirname, '..', '..', 'tmp', 'manpage');
const name = 'manpages.gz';
await downloadManpage('http://example.com', destination, name);
await fs.access(join(destination, name));
});
});
22 changes: 22 additions & 0 deletions packages/build/src/packaging/download-manpage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fetch from 'node-fetch';
import tar from 'tar';
import { createReadStream, createWriteStream, promises as fs } from 'fs';
import { promisify } from 'util';
import { join } from 'path';
import { pipeline } from 'stream';
import { createGzip } from 'zlib';

export async function downloadManpage(url: string, destination: string, name: string) {
await fs.mkdir(destination, { recursive: true });
const response = await fetch(url);
await promisify(pipeline)(
response.body,
tar.x({ cwd: destination })
);
await promisify(pipeline)(
createReadStream(join(destination, 'mongosh.1')),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
createReadStream(join(destination, 'mongosh.1')),
createReadStream(join(destination, path.basename(name, '.gz'))),

createGzip(),
createWriteStream(join(destination, name))
);
console.info(`Saved manpage: ${join(destination, name)}`);
}
1 change: 1 addition & 0 deletions packages/build/src/packaging/package/debian.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('tarball debian', () => {
expect(stdout).to.match(/^-rw-r.-r--.+\/usr\/share\/doc\/foobar\/LICENSE_foo$/m);
expect(stdout).to.match(/^-rw-r.-r--.+\/usr\/share\/doc\/foobar\/README$/m);
expect(stdout).to.match(/^-rw-r.-r--.+\/usr\/share\/doc\/foobar\/copyright$/m);
expect(stdout).to.match(/^-rw-r.-r--.+\/usr\/share\/man\/man1\/mongosh.1.gz$/m);
}
{
const { stdout } = await execFile('dpkg', ['-I', tarball.path]);
Expand Down
8 changes: 8 additions & 0 deletions packages/build/src/packaging/package/debian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export async function createDebianPackage(
for (const { sourceFilePath, packagedFilePath } of docFiles) {
await fs.copyFile(sourceFilePath, path.join(docdir, packagedFilePath), COPYFILE_FICLONE);
}

if (pkg.manpage) {
// Put manpage file in /usr/share/man/man1/.
const manualDir = path.join(dir, pkg.metadata.debName, 'usr', 'share', 'man', 'man1');
await fs.mkdir(manualDir, { recursive: true });
await fs.copyFile(pkg.manpage.sourceFilePath, path.join(manualDir, pkg.manpage.packagedFilePath), COPYFILE_FICLONE);
}

// Debian packages should contain a 'copyright' file.
// https://www.debian.org/doc/debian-policy/ch-archive.html#s-pkgcopyright
await fs.writeFile(path.join(docdir, 'copyright'), await generateDebianCopyright(pkg));
Expand Down
6 changes: 5 additions & 1 deletion packages/build/src/packaging/package/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export async function createCompressedArchiveContents(archiveRootName: string, p
await fs.mkdir(archiveRoot, { recursive: true });
const docFiles = [
...pkg.otherDocFilePaths,
...pkg.binaries.map(({ license }) => license)
...pkg.binaries.map(({ license }) => license),
];
if (pkg.manpage) {
docFiles.push(pkg.manpage);
}

for (const { sourceFilePath, packagedFilePath } of docFiles) {
await fs.copyFile(sourceFilePath, path.join(archiveRoot, packagedFilePath), COPYFILE_FICLONE);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/build/src/packaging/package/package-information.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface LicenseInformation extends DocumentationFile {
rpmIdentifier: string;
}

type ManPage = DocumentationFile;

// This is filled in by the build config file.
export interface PackageInformation {
binaries: {
Expand All @@ -17,6 +19,7 @@ export interface PackageInformation {
license: LicenseInformation;
}[];
otherDocFilePaths: DocumentationFile[];
manpage?: ManPage;
metadata: {
name: string;
debName: string;
Expand Down
1 change: 1 addition & 0 deletions packages/build/src/packaging/package/redhat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('tarball redhat', () => {
expect(stdout).to.match(/^\/usr\/share\/doc\/foobar-1.0.0\/README$/m);
expect(stdout).to.match(/^\/usr\/share\/licenses\/foobar-1.0.0\/LICENSE_bar$/m);
expect(stdout).to.match(/^\/usr\/share\/licenses\/foobar-1.0.0\/LICENSE_foo$/m);
expect(stdout).to.match(/^\/usr\/share\/man\/man1\/mongosh.1.gz$/m);
});

it('determines and copies created RPM', async() => {
Expand Down
13 changes: 10 additions & 3 deletions packages/build/src/packaging/package/redhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ export async function createRedhatPackage(
const filelistRpm = [
...pkg.binaries.map(({ sourceFilePath, category }) => `%{_${category}dir}/${path.basename(sourceFilePath)}`),
...pkg.binaries.map(({ license }) => `%license ${license.packagedFilePath}`),
...pkg.otherDocFilePaths.map(({ packagedFilePath }) => `%doc ${packagedFilePath}`)
].join('\n');
...pkg.otherDocFilePaths.map(({ packagedFilePath }) => `%doc ${packagedFilePath}`),
];
if (pkg.manpage) {
filelistRpm.push(`%doc ${pkg.manpage.packagedFilePath}`);
}
const version = sanitizeVersion(pkg.metadata.version, 'rpm');
const dir = await generateDirFromTemplate(templateDir, {
...pkg.metadata,
licenseRpm,
installscriptRpm,
filelistRpm,
filelistRpm: filelistRpm.join('\n'),
version
});
// Copy all files that we want to ship into the BUILD directory.
Expand All @@ -56,6 +59,10 @@ export async function createRedhatPackage(
await fs.copyFile(sourceFilePath, path.join(dir, 'BUILD', packagedFilePath), COPYFILE_FICLONE);
}

if (pkg.manpage) {
await fs.copyFile(pkg.manpage.sourceFilePath, path.join(dir, 'BUILD', pkg.manpage.packagedFilePath), COPYFILE_FICLONE);
}

// Create the package.
await execFile('rpmbuild', [
'-bb', path.join(dir, 'SPECS', `${pkg.metadata.rpmName}.spec`),
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/packaging/package/zip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('package zip', () => {
expect(unzip.stderr).to.be.empty;

const lines = unzip.stdout.split('\n');
expect(lines).to.have.length(13);
expect(lines).to.have.length(14);

for (let i = 3; i < 10; i++) {
const filename = /([^\s]+)$/.exec(lines[i])?.[1] ?? '';
Expand Down
10 changes: 10 additions & 0 deletions packages/build/src/packaging/run-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import os from 'os';
import { Config, Platform, validateBuildVariant } from '../config';
import { downloadMongocrypt } from './download-mongocryptd';
import { downloadManpage } from './download-manpage';
import { macOSSignAndNotarize } from './macos-sign';
import { notarizeMsi } from './msi-sign';
import { createPackage, PackageFile } from './package';
Expand All @@ -28,6 +29,15 @@ export async function runPackage(
fsConstants.COPYFILE_FICLONE);
}

const { manpage } = config;
if (manpage) {
await downloadManpage(
manpage.sourceUrl,
manpage.downloadPath,
manpage.fileName
);
}

const runCreatePackage = async(): Promise<PackageFile> => {
return await createPackage(
config.outputDir,
Expand Down
Binary file added packages/build/test/fixtures/manpages.tar.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/build/test/fixtures/pkgconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = {
packagedFilePath: 'README'
},
],
manpage: {
sourceFilePath: path.resolve(__dirname, 'manpages.tar.gz'),
packagedFilePath: 'mongosh.1.gz'
},
metadata: {
version: '1.0.0',
fullName: 'Very dumb dummy package',
Expand Down