11
11
12
12
class ExecuteContainerCommand extends Component
13
13
{
14
+ public $ selected_container = 'default ' ;
15
+
14
16
public $ container ;
15
17
16
18
public Collection $ containers ;
@@ -83,11 +85,14 @@ public function loadContainers()
83
85
$ containers = getCurrentApplicationContainerStatus ($ server , $ this ->resource ->id , includePullrequests: true );
84
86
}
85
87
foreach ($ containers as $ container ) {
86
- $ payload = [
87
- 'server ' => $ server ,
88
- 'container ' => $ container ,
89
- ];
90
- $ this ->containers = $ this ->containers ->push ($ payload );
88
+ // if container state is running
89
+ if (data_get ($ container , 'State ' ) === 'running ' ) {
90
+ $ payload = [
91
+ 'server ' => $ server ,
92
+ 'container ' => $ container ,
93
+ ];
94
+ $ this ->containers = $ this ->containers ->push ($ payload );
95
+ }
91
96
}
92
97
} elseif (data_get ($ this ->parameters , 'database_uuid ' )) {
93
98
if ($ this ->resource ->isRunning ()) {
@@ -100,7 +105,6 @@ public function loadContainers()
100
105
}
101
106
} elseif (data_get ($ this ->parameters , 'service_uuid ' )) {
102
107
$ this ->resource ->applications ()->get ()->each (function ($ application ) {
103
- ray ($ application );
104
108
if ($ application ->isRunning ()) {
105
109
$ this ->containers ->push ([
106
110
'server ' => $ this ->resource ->server ,
@@ -131,21 +135,26 @@ public function loadContainers()
131
135
#[On('connectToContainer ' )]
132
136
public function connectToContainer ()
133
137
{
138
+ if ($ this ->selected_container === 'default ' ) {
139
+ $ this ->dispatch ('error ' , 'Please select a container. ' );
140
+
141
+ return ;
142
+ }
134
143
try {
135
- $ container_name = data_get ($ this ->container , 'container.Names ' );
136
- if (is_null ($ container_name )) {
144
+ $ container = collect ($ this ->containers )-> firstWhere ( 'container.Names ' , $ this -> selected_container );
145
+ if (is_null ($ container )) {
137
146
throw new \RuntimeException ('Container not found. ' );
138
147
}
139
148
$ server = data_get ($ this ->container , 'server ' );
140
149
141
150
if ($ server ->isForceDisabled ()) {
142
151
throw new \RuntimeException ('Server is disabled. ' );
143
152
}
144
-
145
- $ this -> dispatch ( 'send-terminal-command ' ,
146
- true ,
147
- $ container_name ,
148
- $ server-> uuid ,
153
+ $ this -> dispatch (
154
+ 'send-terminal-command ' ,
155
+ isset ( $ container ) ,
156
+ data_get ( $ container , ' container.Names ' ) ,
157
+ data_get ( $ container , ' server. uuid ' )
149
158
);
150
159
151
160
} catch (\Throwable $ e ) {
0 commit comments