game-ci / game-ci/unity-builder
Many times container stuck when action cancelled. Provide some behaviour for cleaning frozen containers from docker.
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 313
- Avg merge
- 1h 39m
- Merged PRs (30d)
- 1
Description
**Context**
Cancelling run from actions dashboard
**Suggested solution**
I suggest to check all containers before starting current and do something like described here: https://stackoverflow.com/questions/40744000/remove-all-docker-containers-except-one
**We can check in couple ways:**
- just by timeout (e.g. we know that regular build runs about 25 minutes, so if container lives more than 30-40 – kill it)
- or maybe kill all `unity containers` which runs for now (it means I will not start two tasks in the one docker at the same time, so if I starting new one and there still couple of older – they all are dead
Also I should to be able provide list of names my own containers that should stay leave in this docker
Or maybe not check `others` but just kill all `unity` containers.
**Example of implementation:**
```C#
class Docker {
static async build(buildParameters, silent = false) {
const {path, dockerfile, baseImage} = buildParameters;
const {version} = baseImage;
const tag = ImageTag.createForAction(version);
// something like this should be added to docker before run
const cleanupCommand = `docker close $(docker ps -a -q | grep -v "{my_other_containers_ids}")`;
await exec(cleanupCommand, null, {silent});
//-––––
const command = `docker build ${path} \
--file ${dockerfile} \
--build-arg IMAGE=${baseImage} \
--tag ${tag}`;
await exec(command, null, {silent});
return tag;
}
static async run(image, parameters, silent = false) {
//-----
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.