How to use resin-multibuild - 7 common examples

To help you get started, we’ve selected a few resin-multibuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balena-io / balena-cli / lib / utils / compose_ts.ts View on Github external
export function validateSpecifiedDockerfile(
	projectPath: string,
	dockerfilePath: string = '',
): string {
	if (!dockerfilePath) {
		return dockerfilePath;
	}
	const { isAbsolute, join, normalize, parse, posix } = require('path');
	const { existsSync } = require('fs');
	const { contains, toNativePath, toPosixPath } = MultiBuild.PathUtils;

	// reminder: native windows paths may start with a drive specificaton,
	// e.g. 'C:\absolute' or 'C:relative'.
	if (isAbsolute(dockerfilePath) || posix.isAbsolute(dockerfilePath)) {
		exitWithExpectedError(stripIndent`
			Error: absolute Dockerfile path detected:
			"${dockerfilePath}"
			The Dockerfile path should be relative to the source folder.
		`);
	}
	const nativeProjectPath = normalize(projectPath);
	const nativeDockerfilePath = join(projectPath, toNativePath(dockerfilePath));

	if (!contains(nativeProjectPath, nativeDockerfilePath)) {
		// Note that testing the existence of nativeDockerfilePath in the
		// filesystem (after joining its path to the source folder) is not
github balena-io / balena-cli / lib / utils / ignore.ts View on Github external
*
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import * as _ from 'lodash';
import { fs } from 'mz';
import * as path from 'path';
import * as MultiBuild from 'resin-multibuild';

import dockerIgnore = require('@zeit/dockerignore');
import ignore from 'ignore';

const { toPosixPath } = MultiBuild.PathUtils;

export enum IgnoreFileType {
	DockerIgnore,
	GitIgnore,
}

interface IgnoreEntry {
	pattern: string;
	// The relative file path from the base path of the build context
	filePath: string;
}

export class FileIgnorer {
	private dockerIgnoreEntries: IgnoreEntry[];
	private gitIgnoreEntries: IgnoreEntry[];
github balena-io / balena-cli / lib / utils / compose_ts.ts View on Github external
return await new Promise((resolve, reject) => {
		const buildTasks = MultiBuild.performResolution(
			tasks,
			deviceInfo.arch,
			deviceInfo.deviceType,
			{ error: [reject] },
		);
		// Do one task at a time (Bluebird.each instead of Bluebird.all)
		// in order to reduce peak memory usage. Resolves to buildTasks.
		Bluebird.each(buildTasks, buildTask => {
			// buildStream is falsy for "external" tasks (image pull)
			if (!buildTask.buildStream) {
				return buildTask;
			}
			// Consume each task.buildStream in order to trigger the
			// resolution events that define fields like:
			//     task.dockerfile, task.dockerfilePath,
			//     task.projectType, task.resolved
github balena-io / balena-cli / lib / utils / compose_ts.ts View on Github external
async function parseRegistrySecrets(
	secretsFilename: string,
): Promise {
	const { fs } = await import('mz');
	try {
		let isYaml = false;
		if (/.+\.ya?ml$/i.test(secretsFilename)) {
			isYaml = true;
		} else if (!/.+\.json$/i.test(secretsFilename)) {
			throw new Error('Filename must end with .json, .yml or .yaml');
		}
		const raw = (await fs.readFile(secretsFilename)).toString();
		const registrySecrets = new MultiBuild.RegistrySecretValidator().validateRegistrySecrets(
			isYaml ? require('js-yaml').safeLoad(raw) : JSON.parse(raw),
		);
		MultiBuild.addCanonicalDockerHubEntry(registrySecrets);
		return registrySecrets;
	} catch (error) {
		return exitWithExpectedError(
			`Error validating registry secrets file "${secretsFilename}":\n${
				error.message
			}`,
		);
	}
}
github balena-io / balena-cli / lib / utils / compose_ts.ts View on Github external
async function parseRegistrySecrets(
	secretsFilename: string,
): Promise {
	const { fs } = await import('mz');
	try {
		let isYaml = false;
		if (/.+\.ya?ml$/i.test(secretsFilename)) {
			isYaml = true;
		} else if (!/.+\.json$/i.test(secretsFilename)) {
			throw new Error('Filename must end with .json, .yml or .yaml');
		}
		const raw = (await fs.readFile(secretsFilename)).toString();
		const registrySecrets = new MultiBuild.RegistrySecretValidator().validateRegistrySecrets(
			isYaml ? require('js-yaml').safeLoad(raw) : JSON.parse(raw),
		);
		MultiBuild.addCanonicalDockerHubEntry(registrySecrets);
		return registrySecrets;
	} catch (error) {
		return exitWithExpectedError(
			`Error validating registry secrets file "${secretsFilename}":\n${
				error.message
			}`,
		);
	}
}
github balena-io / balena-cli / lib / utils / device / deploy.ts View on Github external
await Bluebird.map(buildTasks, async (task: BuildTask) => {
		task.dockerOpts = {
			cachefrom: images,
			labels: {
				'io.resin.local.image': '1',
				'io.resin.local.service': task.serviceName,
			},
			t: generateImageName(task.serviceName),
			nocache: opts.nocache,
			forcerm: true,
		};
		if (task.external) {
			task.dockerOpts.authconfig = await getAuthConfigObj(
				task.imageName!,
				opts.registrySecrets,
			);
		} else {
			task.dockerOpts.registryconfig = opts.registrySecrets;
		}
	});
}
github balena-io / balena-cli / lib / utils / compose_ts.ts View on Github external
export async function makeBuildTasks(
	composition: Composition,
	tarStream: Readable,
	deviceInfo: DeviceInfo,
	logger: Logger,
): Promise {
	const buildTasks = await MultiBuild.splitBuildStream(composition, tarStream);

	logger.logDebug('Found build tasks:');
	_.each(buildTasks, task => {
		let infoStr: string;
		if (task.external) {
			infoStr = `image pull [${task.imageName}]`;
		} else {
			infoStr = `build [${task.context}]`;
		}
		logger.logDebug(`    ${task.serviceName}: ${infoStr}`);
	});

	logger.logDebug(
		`Resolving services with [${deviceInfo.deviceType}|${deviceInfo.arch}]`,
	);