This repository was archived by the owner on Dec 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshell.ts
More file actions
57 lines (51 loc) · 1.7 KB
/
shell.ts
File metadata and controls
57 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as inquirer from 'inquirer'
import BaseCmd from '../base-cmd-abstract'
import {execSync} from 'child_process'
import {flags} from '@oclif/command'
export default class ShellCmd extends BaseCmd {
static description = 'Open a shell session on the given container.'
static examples = [
'$ ce-dev shell example-app',
]
static flags = {
help: flags.help({char: 'h'}),
}
static args = [
{
name: 'container',
required: false,
description: 'Name of the container to target. Use `docker ps` to see available containers.',
},
]
async run(): Promise<any> {
this.ensureActiveComposeFile()
const {args} = this.parse(ShellCmd)
let container = args.container
if (!container) {
const running = this.getProjectRunningContainersCeDev()
if (running.length === 0) {
this.warn('No running containers can be targetted. Exiting.')
this.exit(1)
}
// Single container, just use this.
if (running.length === 1) {
container = running[0]
} else {
const response: any = await inquirer.prompt([{
name: 'container',
message: 'Select a container to target',
type: 'list',
choices: running,
}])
container = response.container
}
}
try {
execSync(this.dockerBin + ' exec ' + container + ' [ -d "/home/ce-dev/deploy/live.local" ]')
execSync(this.dockerBin + ' exec -it -u ce-dev -w /home/ce-dev/deploy/live.local ' + container + ' sudo su ce-dev || exit 0', {stdio: 'inherit'})
}
catch {
execSync(this.dockerBin + ' exec -it -u ce-dev -w /home/ce-dev ' + container + ' sudo su ce-dev || exit 0', {stdio: 'inherit'})
}
}
}