@devcontainers/cli
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -26,3 +26,3 @@ import { ResolverResult, DockerResolverParameters } from './utils'; | ||
}; | ||
export declare function buildAndExtendDockerCompose(config: DevContainerFromDockerComposeConfig, projectName: string, params: DockerResolverParameters, localComposeFiles: string[], envFile: string | undefined, composeGlobalArgs: string[], runServices: string[], noCache: boolean, overrideFilePath: string, overrideFilePrefix: string, additionalCacheFroms?: string[]): Promise<{ | ||
export declare function buildAndExtendDockerCompose(config: DevContainerFromDockerComposeConfig, projectName: string, params: DockerResolverParameters, localComposeFiles: string[], envFile: string | undefined, composeGlobalArgs: string[], runServices: string[], noCache: boolean, overrideFilePath: string, overrideFilePrefix: string, additionalCacheFroms?: string[], noBuild?: boolean): Promise<{ | ||
collapsedFeaturesConfig: CollapsedFeaturesConfig | undefined; | ||
@@ -29,0 +29,0 @@ additionalComposeOverrideFiles: string[]; |
@@ -40,3 +40,2 @@ "use strict"; | ||
const containerFeatures_1 = require("./containerFeatures"); | ||
const containerFeaturesConfiguration_1 = require("../spec-configuration/containerFeaturesConfiguration"); | ||
const product_1 = require("../spec-utils/product"); | ||
@@ -153,3 +152,3 @@ const path_1 = __importDefault(require("path")); | ||
exports.getBuildInfoForService = getBuildInfoForService; | ||
async function buildAndExtendDockerCompose(config, projectName, params, localComposeFiles, envFile, composeGlobalArgs, runServices, noCache, overrideFilePath, overrideFilePrefix, additionalCacheFroms) { | ||
async function buildAndExtendDockerCompose(config, projectName, params, localComposeFiles, envFile, composeGlobalArgs, runServices, noCache, overrideFilePath, overrideFilePrefix, additionalCacheFroms, noBuild) { | ||
var _a, _b; | ||
@@ -240,25 +239,27 @@ const { common, dockerCLI, dockerComposeCLI: dockerComposeCLIFunc } = params; | ||
} | ||
args.push('build'); | ||
if (noCache) { | ||
args.push('--no-cache', '--pull'); | ||
} | ||
if (runServices.length) { | ||
args.push(...runServices); | ||
if (runServices.indexOf(config.service) === -1) { | ||
args.push(config.service); | ||
if (!noBuild) { | ||
args.push('build'); | ||
if (noCache) { | ||
args.push('--no-cache', '--pull'); | ||
} | ||
} | ||
try { | ||
if (params.isTTY) { | ||
const infoParams = { ...(0, dockerUtils_1.toPtyExecParameters)(params, await dockerComposeCLIFunc()), output: (0, log_1.makeLog)(output, log_1.LogLevel.Info) }; | ||
await (0, dockerUtils_1.dockerComposePtyCLI)(infoParams, ...args); | ||
if (runServices.length) { | ||
args.push(...runServices); | ||
if (runServices.indexOf(config.service) === -1) { | ||
args.push(config.service); | ||
} | ||
} | ||
else { | ||
const infoParams = { ...(0, dockerUtils_1.toExecParameters)(params, await dockerComposeCLIFunc()), output: (0, log_1.makeLog)(output, log_1.LogLevel.Info), print: 'continuous' }; | ||
await (0, dockerUtils_1.dockerComposeCLI)(infoParams, ...args); | ||
try { | ||
if (params.isTTY) { | ||
const infoParams = { ...(0, dockerUtils_1.toPtyExecParameters)(params, await dockerComposeCLIFunc()), output: (0, log_1.makeLog)(output, log_1.LogLevel.Info) }; | ||
await (0, dockerUtils_1.dockerComposePtyCLI)(infoParams, ...args); | ||
} | ||
else { | ||
const infoParams = { ...(0, dockerUtils_1.toExecParameters)(params, await dockerComposeCLIFunc()), output: (0, log_1.makeLog)(output, log_1.LogLevel.Info), print: 'continuous' }; | ||
await (0, dockerUtils_1.dockerComposeCLI)(infoParams, ...args); | ||
} | ||
} | ||
catch (err) { | ||
throw err instanceof errors_1.ContainerError ? err : new errors_1.ContainerError({ description: 'An error occurred building the Docker Compose images.', originalError: err, data: { fileWithError: localComposeFiles[0] } }); | ||
} | ||
} | ||
catch (err) { | ||
throw err instanceof errors_1.ContainerError ? err : new errors_1.ContainerError({ description: 'An error occurred building the Docker Compose images.', originalError: err, data: { fileWithError: localComposeFiles[0] } }); | ||
} | ||
return { | ||
@@ -276,6 +277,15 @@ collapsedFeaturesConfig: extendImageBuildInfo === null || extendImageBuildInfo === void 0 ? void 0 : extendImageBuildInfo.collapsedFeaturesConfig, | ||
output.write(`Restoring ${file} from persisted storage`); | ||
return file; | ||
return { | ||
foundLabel: true, | ||
fileExists: true, | ||
file | ||
}; | ||
} | ||
else { | ||
output.write(`Expected ${file} to exist, but it did not`, log_1.LogLevel.Error); | ||
return { | ||
foundLabel: true, | ||
fileExists: false, | ||
file | ||
}; | ||
} | ||
@@ -286,3 +296,5 @@ } | ||
} | ||
return undefined; | ||
return { | ||
foundLabel: false | ||
}; | ||
} | ||
@@ -318,4 +330,4 @@ async function startContainer(params, buildParams, config, projectName, composeFiles, envFile, container, idLabels) { | ||
output.write(`PersistedPath=${persistedFolder}, ContainerHasLabels=${!!labels}`); | ||
let didRestoreFromPersistedShare = false; | ||
if (container) { | ||
let didRestoreFromPersistedShare = false; | ||
if (labels) { | ||
@@ -329,35 +341,23 @@ // update args for `docker-compose up` to use cached overrides | ||
const persistedStartFile = await checkForPersistedFile(buildCLIHost, output, files, featuresStartOverrideFilePrefix); | ||
if (persistedBuildFile && persistedStartFile) { | ||
if ((persistedBuildFile.fileExists || !persistedBuildFile.foundLabel) // require build file if in label | ||
&& persistedStartFile.fileExists // always require start file | ||
) { | ||
didRestoreFromPersistedShare = true; | ||
// Push path to compose arguments | ||
composeGlobalArgs.push('-f', persistedBuildFile); | ||
composeGlobalArgs.push('-f', persistedStartFile); | ||
} | ||
} | ||
if (!didRestoreFromPersistedShare) { | ||
const imageName = container.Config.Image; | ||
let cache; | ||
const imageDetails = () => cache || (cache = (0, utils_1.inspectDockerImage)(params, imageName, false)); | ||
const labelDetails = async () => { return { definition: undefined, version: undefined }; }; | ||
const featuresConfig = await (0, containerFeaturesConfiguration_1.generateFeaturesConfig)(params.common, (await (0, utils_1.createFeaturesTempFolder)(params.common)), config, labelDetails, containerFeaturesConfiguration_1.getContainerFeaturesFolder); | ||
if (featuresConfig) { | ||
const collapsedFeaturesConfig = (0, containerFeaturesConfiguration_1.collapseFeaturesConfig)(featuresConfig); | ||
// Save override docker-compose file to disk. | ||
// Persisted folder is a path that will be maintained between sessions | ||
// Note: As a fallback, persistedFolder is set to the build's tmpDir() directory | ||
const overrideFilePath = await writeFeaturesComposeOverrideFile(container.Config.Image, originalImageName, collapsedFeaturesConfig, config, buildParams, composeFiles, imageDetails, service, idLabels, params.additionalMounts, persistedFolder, featuresStartOverrideFilePrefix, buildCLIHost, output); | ||
if (overrideFilePath) { | ||
// Add file path to override file as parameter | ||
composeGlobalArgs.push('-f', overrideFilePath); | ||
if (persistedBuildFile.fileExists) { | ||
composeGlobalArgs.push('-f', persistedBuildFile.file); | ||
} | ||
if (persistedStartFile.fileExists) { | ||
composeGlobalArgs.push('-f', persistedStartFile.file); | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
if (!container || !didRestoreFromPersistedShare) { | ||
const noBuild = !!container; //if we have an existing container, just recreate override files but skip the build | ||
const infoParams = { ...params, common: { ...params.common, output: infoOutput } }; | ||
const { collapsedFeaturesConfig, additionalComposeOverrideFiles } = await buildAndExtendDockerCompose(config, projectName, infoParams, localComposeFiles, envFile, composeGlobalArgs, (_c = config.runServices) !== null && _c !== void 0 ? _c : [], (_d = params.buildNoCache) !== null && _d !== void 0 ? _d : false, persistedFolder, featuresBuildOverrideFilePrefix, params.additionalCacheFroms); | ||
const { collapsedFeaturesConfig, additionalComposeOverrideFiles } = await buildAndExtendDockerCompose(config, projectName, infoParams, localComposeFiles, envFile, composeGlobalArgs, (_c = config.runServices) !== null && _c !== void 0 ? _c : [], (_d = params.buildNoCache) !== null && _d !== void 0 ? _d : false, persistedFolder, featuresBuildOverrideFilePrefix, params.additionalCacheFroms, noBuild); | ||
additionalComposeOverrideFiles.forEach(overrideFilePath => composeGlobalArgs.push('-f', overrideFilePath)); | ||
let cache; | ||
const imageDetails = () => cache || (cache = (0, utils_1.inspectDockerImage)(params, originalImageName, true)); | ||
const updatedImageName = await (0, containerFeatures_1.updateRemoteUserUID)(params, config, originalImageName, imageDetails, service.user); | ||
const updatedImageName = noBuild ? originalImageName : await (0, containerFeatures_1.updateRemoteUserUID)(params, config, originalImageName, imageDetails, service.user); | ||
// Save override docker-compose file to disk. | ||
@@ -364,0 +364,0 @@ // Persisted folder is a path that will be maintained between sessions |
{ | ||
"name": "@devcontainers/cli", | ||
"description": "Dev Containers CLI", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"bin": { | ||
@@ -6,0 +6,0 @@ "devcontainer": "devcontainer.js" |
Sorry, the diff of this file is not supported yet
1452422
12351