Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeClientSharedCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Shared
NodeClientSharedCode
Commits
06f4fcdc
Commit
06f4fcdc
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
ExerciseDockerCompose => Add dangling image removing
parent
e8b67ee2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
helpers/Dojo/ExerciseDockerCompose.ts
+52
-41
52 additions, 41 deletions
helpers/Dojo/ExerciseDockerCompose.ts
with
52 additions
and
41 deletions
helpers/Dojo/ExerciseDockerCompose.ts
+
52
−
41
View file @
06f4fcdc
...
...
@@ -3,6 +3,7 @@ import { TypedEmitter } from 'tiny-typed-emitter';
import
ExerciseRunningEvents
from
'
../../types/Dojo/ExerciseRunningEvents
'
;
import
{
spawn
}
from
'
child_process
'
;
import
ExerciseCheckerError
from
'
../../../shared/types/Dojo/ExerciseCheckerError
'
;
import
{
ChildProcessWithoutNullStreams
}
from
'
node:child_process
'
;
class
ExerciseDockerCompose
{
...
...
@@ -28,6 +29,20 @@ class ExerciseDockerCompose {
});
}
private
registerChildProcess
(
childProcess
:
ChildProcessWithoutNullStreams
,
resolve
:
(
value
:
(
number
|
PromiseLike
<
number
>
))
=>
void
,
reject
:
(
reason
?:
unknown
)
=>
void
)
{
childProcess
.
stdout
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
false
,
false
);
});
childProcess
.
stderr
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
true
,
false
);
});
childProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
code
!==
null
?
resolve
(
code
)
:
reject
();
});
}
run
(
doDown
:
boolean
=
false
)
{
(
async
()
=>
{
let
containerExitCode
:
number
=
-
1
;
...
...
@@ -52,17 +67,7 @@ class ExerciseDockerCompose {
}
});
dockerCompose
.
stdout
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
false
,
true
);
});
dockerCompose
.
stderr
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
true
,
true
);
});
dockerCompose
.
on
(
'
exit
'
,
(
code
)
=>
{
code
!==
null
?
resolve
(
code
)
:
reject
();
});
this
.
registerChildProcess
(
dockerCompose
,
resolve
,
reject
);
});
}
catch
(
error
)
{
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_RUN
'
,
`Error while running the docker compose file`
,
true
);
...
...
@@ -77,7 +82,7 @@ class ExerciseDockerCompose {
try
{
this
.
events
.
emit
(
'
step
'
,
'
COMPOSE_LOGS
'
,
'
Linked services logs acquisition
'
);
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
await
new
Promise
<
number
>
((
resolve
,
reject
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
'
####################################################### Other Services Logs #######################################################
\n
'
,
false
,
false
);
...
...
@@ -86,17 +91,7 @@ class ExerciseDockerCompose {
shell
:
true
});
dockerCompose
.
stdout
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
false
,
false
);
});
dockerCompose
.
stderr
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
true
,
false
);
});
dockerCompose
.
on
(
'
exit
'
,
(
code
)
=>
{
code
!==
null
?
resolve
()
:
reject
();
});
this
.
registerChildProcess
(
dockerCompose
,
resolve
,
reject
);
});
}
catch
(
error
)
{
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_LOGS
'
,
`Error while getting the linked services logs`
,
true
);
...
...
@@ -112,33 +107,49 @@ class ExerciseDockerCompose {
try
{
this
.
events
.
emit
(
'
step
'
,
'
COMPOSE_DOWN
'
,
'
Stopping and removing containers
'
);
await
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
await
new
Promise
<
number
>
((
resolve
,
reject
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
'
####################################################### Stop and remove containers #######################################################
\n
'
,
false
,
false
);
const
dockerCompose
=
spawn
(
`
${
dockerComposeCommand
}
down --volumes`
,
{
const
dockerCompose
=
spawn
(
`
${
dockerComposeCommand
}
down --volumes
--rmi
`
,
{
cwd
:
this
.
executionFolder
,
shell
:
true
});
dockerCompose
.
stdout
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
false
,
false
);
this
.
registerChildProcess
(
dockerCompose
,
resolve
,
reject
);
});
}
catch
(
error
)
{
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_DOWN
'
,
`Error stop and remove containers`
,
true
);
this
.
events
.
emit
(
'
finished
'
,
false
,
ExerciseCheckerError
.
DOCKER_COMPOSE_DOWN_ERROR
);
return
;
}
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_DOWN
'
,
`Containers stopped and removed`
,
false
);
}
}
dockerCompose
.
stderr
.
on
(
'
data
'
,
(
data
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
data
.
toString
(),
true
,
false
);
});
// Remove images if asked
{
if
(
doDown
)
{
try
{
this
.
events
.
emit
(
'
step
'
,
'
COMPOSE_REMOVE_DANGLING
'
,
'
Removing dangling images
'
);
dockerCompose
.
on
(
'
exit
'
,
(
code
)
=>
{
code
!==
null
?
resolve
()
:
reject
();
await
new
Promise
<
number
>
((
resolve
,
reject
)
=>
{
this
.
events
.
emit
(
'
logs
'
,
'
####################################################### Remove dangling images #######################################################
\n
'
,
false
,
false
);
const
dockerCompose
=
spawn
(
`docker image prune --force`
,
{
cwd
:
this
.
executionFolder
,
shell
:
true
});
this
.
registerChildProcess
(
dockerCompose
,
resolve
,
reject
);
});
}
catch
(
error
)
{
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_
DOWN
'
,
`Error stop and remove container
s`
,
true
);
this
.
events
.
emit
(
'
finished
'
,
false
,
ExerciseCheckerError
.
DOCKER_COMPOSE_
DOWN
_ERROR
);
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_
REMOVE_DANGLING
'
,
`Error while removing dangling image
s`
,
true
);
this
.
events
.
emit
(
'
finished
'
,
false
,
ExerciseCheckerError
.
DOCKER_COMPOSE_
REMOVE_DANGLING
_ERROR
);
return
;
}
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_
DOWN
'
,
`Containers stopped and
removed`
,
false
);
this
.
events
.
emit
(
'
endStep
'
,
'
COMPOSE_
REMOVE_DANGLING
'
,
`Dangling images
removed`
,
false
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment