@rocketmakers/shell-commands
Advanced tools
| /// <reference types="node" /> | ||
| import { IShellOptions } from './shell'; | ||
| export declare namespace DockerCompose { | ||
| /** | ||
| * Determines whether `docker compose` (v2) is supported or if we need to use the legacy `docker-compose` command | ||
| */ | ||
| function isV2Supported(): Promise<boolean>; | ||
| /** | ||
| * Executes a docker compose command either with v1 or v2 based on availability. | ||
| * | ||
| * The v2 version is preferred since it's included in docker CLI but for the time being it's not on linux. | ||
| * @param args The arguments to pass to the compose command | ||
| * @param options The optional {@link IShellOptions} to include | ||
| */ | ||
| function exec(args: string[], options?: IShellOptions): Promise<string>; | ||
| /** | ||
| * Builds containers using a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param uniqueProjectName The name to give to the project rather than using the current directory name | ||
| * @param env Optional environment variables to use | ||
| */ | ||
| function build(composePath: string, uniqueProjectName: string, env?: NodeJS.ProcessEnv): Promise<string>; | ||
| /** | ||
| * Builds a single service named in a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param uniqueProjectName The name to give to the project rather than using the current directory name | ||
| * @param serviceName The name of the service to build from the config file | ||
| * @param env Optional environment variables to use | ||
| */ | ||
| function buildService(composePath: string, uniqueProjectName: string, serviceName: string, env?: NodeJS.ProcessEnv): Promise<string>; | ||
| /** | ||
| * Gets a list of services included in a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param env Optional environment variables to use | ||
| * @returns The list of services as a string array | ||
| */ | ||
| function getServices(composePath: string, env?: NodeJS.ProcessEnv): Promise<string[]>; | ||
| } |
@@ -5,22 +5,64 @@ "use strict"; | ||
| const yml = require("js-yaml"); | ||
| const docker_1 = require("./docker"); | ||
| const logger_1 = require("./logger"); | ||
| const prerequisites_1 = require("./prerequisites"); | ||
| const shell_1 = require("./shell"); | ||
| const logger = (0, logger_1.createLogger)('docker-compose'); | ||
| var DockerCompose; | ||
| (function (DockerCompose) { | ||
| const exe = 'docker-compose'; | ||
| prerequisites_1.Prerequisites.register({ | ||
| command: exe, | ||
| description: 'Defining and running groups of docker containers', | ||
| docsUrl: 'https://docs.docker.com/compose/', | ||
| }); | ||
| prerequisites_1.Prerequisites.register(docker_1.Docker.prerequisite); | ||
| /** | ||
| * Determines whether `docker compose` (v2) is supported or if we need to use the legacy `docker-compose` command | ||
| */ | ||
| async function isV2Supported() { | ||
| logger.debug('Checking for v2 docker compose support'); | ||
| const output = await shell_1.Shell.execOutput('docker', ['compose', 'version'], { allowFail: true }); | ||
| logger.debug(`Output from "docker compose version": '${output}'`); | ||
| return output.includes('Docker Compose version'); | ||
| } | ||
| DockerCompose.isV2Supported = isV2Supported; | ||
| /** | ||
| * Executes a docker compose command either with v1 or v2 based on availability. | ||
| * | ||
| * The v2 version is preferred since it's included in docker CLI but for the time being it's not on linux. | ||
| * @param args The arguments to pass to the compose command | ||
| * @param options The optional {@link IShellOptions} to include | ||
| */ | ||
| async function exec(args, options = {}) { | ||
| if (await isV2Supported()) { | ||
| return shell_1.Shell.exec('docker', ['compose', ...args], options); | ||
| } | ||
| logger.warn('Docker compose v2 not supported - falling back to v1'); | ||
| return shell_1.Shell.exec('docker-compose', args, options); | ||
| } | ||
| DockerCompose.exec = exec; | ||
| /** | ||
| * Builds containers using a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param uniqueProjectName The name to give to the project rather than using the current directory name | ||
| * @param env Optional environment variables to use | ||
| */ | ||
| function build(composePath, uniqueProjectName, env) { | ||
| return shell_1.Shell.exec(exe, ['--project-name', uniqueProjectName, '-f', composePath, 'build'], { env }); | ||
| return exec(['--project-name', uniqueProjectName, '-f', composePath, 'build'], { env }); | ||
| } | ||
| DockerCompose.build = build; | ||
| /** | ||
| * Builds a single service named in a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param uniqueProjectName The name to give to the project rather than using the current directory name | ||
| * @param serviceName The name of the service to build from the config file | ||
| * @param env Optional environment variables to use | ||
| */ | ||
| function buildService(composePath, uniqueProjectName, serviceName, env) { | ||
| return shell_1.Shell.exec(exe, ['--project-name', uniqueProjectName, '-f', composePath, 'build', serviceName], { env }); | ||
| return exec(['--project-name', uniqueProjectName, '-f', composePath, 'build', serviceName], { env }); | ||
| } | ||
| DockerCompose.buildService = buildService; | ||
| /** | ||
| * Gets a list of services included in a given docker-compose config file | ||
| * @param composePath The path to the config file | ||
| * @param env Optional environment variables to use | ||
| * @returns The list of services as a string array | ||
| */ | ||
| async function getServices(composePath, env) { | ||
| const configStr = await shell_1.Shell.exec(exe, ['-f', composePath, 'config'], { log: false, output: true, env }); | ||
| const configStr = await exec(['-f', composePath, 'config'], { log: false, output: true, env }); | ||
| const config = yml.safeLoad(configStr); | ||
@@ -27,0 +69,0 @@ return Object.keys(config.services); |
+5
-0
@@ -10,2 +10,7 @@ export declare namespace Docker { | ||
| } | ||
| const prerequisite: { | ||
| command: string; | ||
| description: string; | ||
| docsUrl: string; | ||
| }; | ||
| /** | ||
@@ -12,0 +17,0 @@ * Tag a local image with a remote tag. |
+3
-2
@@ -9,7 +9,8 @@ "use strict"; | ||
| const exe = 'docker'; | ||
| prerequisites_1.Prerequisites.register({ | ||
| Docker.prerequisite = { | ||
| command: exe, | ||
| description: 'Running software in containers', | ||
| docsUrl: 'https://docs.docker.com/', | ||
| }); | ||
| }; | ||
| prerequisites_1.Prerequisites.register(Docker.prerequisite); | ||
| /** | ||
@@ -16,0 +17,0 @@ * Tag a local image with a remote tag. |
+1
-1
| { | ||
| "name": "@rocketmakers/shell-commands", | ||
| "version": "5.2.1", | ||
| "version": "5.3.0", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "directories": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 12 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 12 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
242257
1.62%5980
1.36%