-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpush.ts
63 lines (51 loc) · 1.59 KB
/
push.ts
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
58
59
60
61
62
63
import { ux } from '@oclif/core'
import {execSync} from 'node:child_process'
import DockerImagesCmd from '../abstracts/base-cmd-abstract-docker-images.js'
import {AppSettings} from "../app-settings.js";
export default class PushCmd extends DockerImagesCmd {
static description = 'Push images referenced in a compose file to a remote repository.'
static examples = [
'$ ce-dev push --template example.compose.yml',
]
/**
* @inheritdoc
*/
async run(): Promise<void> {
const { flags } = await this.parse(PushCmd)
this.composeTemplate = this.getPathFromRelative(flags.template)
this.composeConfig = this.loadComposeConfig(this.composeTemplate)
if (flags.username) {
this.dockerUsername = flags.username
}
if (flags.password) {
this.dockerPassword = flags.password
}
if (flags.anonymous) {
this.dockerLogin = false
}
if (flags.registry.length > 0) {
this.dockerRegistry = flags.registry
}
if (this.dockerLogin) {
this.login()
}
this.push()
}
/**
* Push generated images.
*
* @return void
*/
private push(): void {
let version = AppSettings.ceDevVersion + '.x'
if (this.developmentMode) {
version = 'devel-' + version
}
for (const name of Object.keys(this.composeConfig.services)) {
const containerName = this.composeConfig['x-ce_dev'].project_name + '-' + name
ux.action.start('Pushing image ' + containerName)
execSync(this.dockerBin + ' push ' + this.dockerRegistry + '/' + containerName + ':' + version, {stdio: 'inherit'})
ux.action.stop()
}
}
}