/**
* @license
* Copyright 2018 Balena Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 Bluebird from 'bluebird';
import * as Dockerode from 'dockerode';
import * as Plugin from './plugin';
export declare type ErrorHandler = (error: Error) => void;
/**
* This class is responsible for interfacing with the docker daemon to
* start and monitor a build. Most use cases will require a call to
* registerHooks(...) and a call to createBuildStream(...). Everything
* else can be done with the hook architecture.
*
*/
export default class Builder {
private docker;
private constructor();
static fromDockerode(docker: Dockerode): Builder;
static fromDockerOpts(dockerOpts: Dockerode.DockerOptions): Builder;
/**
* Start a build with the docker daemon, and return the stream to the caller.
* The stream can be written to, and the docker daemon will interpret that
* as a tar archive to build. The stream can also be read from, and the data
* returned will be the output of the docker daemon build.
*
* @returns A bi-directional stream connected to the docker daemon
*/
createBuildStream(buildOpts: {
[key: string]: any;
}, hooks?: Plugin.BuildHooks, handler?: ErrorHandler): NodeJS.ReadWriteStream;
/**
* Given a path, this function will create a tar stream containing all of the files,
* and stream it to the docker daemon. It will then return a stream connected to
* the output of the docker daemon.
*
* @param dirPath Directory path to send to the docker daemon
* @param buildOpts Build options to pass to the docker daemon
*
* @returns Promise of a stream connected to the docker daemon
*/
buildDir(dirPath: string, buildOpts: {
[key: string]: any;
}, hooks: Plugin.BuildHooks, handler?: ErrorHandler): Bluebird;
/**
* Internal function to call a hook, if it has been registered for the build.
*
* @param args The arguments to pass to the hook. The values will be
* unwrapped before being passed to the callback.
*
* @returns Promise that resolves to the return value of the hook function,
* or to undefined if the a hook function is not provided.
*/
private callHook;
}