1
1
import { csvKeyValuePairs , exit } from '~/utils'
2
2
import docker from '~/docker'
3
+ import setup from '~/setup'
3
4
import Hooks from '~/hooks'
5
+ import Staxfile from '~/staxfile'
4
6
5
7
interface FindOptions {
6
8
warn ?: boolean
@@ -10,6 +12,7 @@ interface FindOptions {
10
12
export default class Container {
11
13
public attributes : Record < string , any >
12
14
private _labels : Record < string , string >
15
+ private _composeFile : string
13
16
private hooks : Hooks
14
17
15
18
constructor ( attributes : Record < string , any > ) {
@@ -25,6 +28,10 @@ export default class Container {
25
28
return this . attributes . ID
26
29
}
27
30
31
+ get staxfile ( ) : string {
32
+ return this . labels [ 'dev.stax.staxfile' ]
33
+ }
34
+
28
35
get app ( ) : string {
29
36
return this . labels [ 'dev.stax.app' ]
30
37
}
@@ -65,6 +72,11 @@ export default class Container {
65
72
return this . labels [ 'com.docker.compose.project.config_files' ]
66
73
}
67
74
75
+ get composeFile ( ) : string {
76
+ this . _composeFile ||= new Staxfile ( this . staxfile ) . compile ( ) . composeFile
77
+ return this . _composeFile
78
+ }
79
+
68
80
static all ( contextName : string ) : Container [ ] {
69
81
return docker . ps ( contextName )
70
82
. map ( attributes => new Container ( attributes ) )
@@ -85,23 +97,23 @@ export default class Container {
85
97
}
86
98
87
99
async down ( ) {
88
- return docker . compose ( this . contextName , 'stop' , this . name )
100
+ return docker . compose ( this . contextName , 'stop' , this . composeFile )
89
101
}
90
102
91
103
async up ( ) {
92
- return docker . compose ( this . contextName , 'start' , this . name , { exit : true } )
104
+ return docker . compose ( this . contextName , 'start' , this . composeFile , { exit : true } )
93
105
}
94
106
95
107
async remove ( ) {
96
- return docker . compose ( this . contextName , 'rm --stop --force --volumes' , this . name )
108
+ return docker . compose ( this . contextName , 'rm --stop --force --volumes' , this . composeFile )
97
109
}
98
110
99
111
async exec ( command : string ) {
100
112
return docker . container ( `exec -it ${ this . name } ${ command } ` )
101
113
}
102
114
103
115
async rebuild ( ) {
104
- await docker . compose ( this . contextName , `up --detach --force-recreate ${ this . name } ` , this . configFile , { exit : true } )
116
+ setup ( this . contextName , this . staxfile )
105
117
this . hooks . onPostBuild ( )
106
118
}
107
119
0 commit comments