Skip to content

Commit 7755000

Browse files
committed
ci: Remove docker containers at end, systematically
1 parent b330c14 commit 7755000

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Docker cleanup action
2-
description: Composite action for removing Docker images
2+
description: Composite action for removing Docker containers and images
33
author: "Devito"
44

55
inputs:
@@ -10,12 +10,22 @@ inputs:
1010
tag:
1111
description: "Tag of the built image to use"
1212
required: true
13+
name:
14+
description: "Name substring used by the docker-run action"
15+
default: ""
1316

1417
runs:
1518
using: "composite"
1619
steps:
1720
- id: dockerclean
18-
name: "Cleanup docker image"
21+
name: "Cleanup Docker resources"
1922
shell: bash
23+
env:
24+
NAME: ${{ inputs.name }}
25+
TAG: ${{ inputs.tag }}
26+
UNIQUE: ${{ inputs.uid }}
2027
run: |
21-
docker image rm -f "${{ inputs.tag }}_${{ inputs.uid }}"
28+
CONTAINER_NAME="ci-${NAME:-${TAG}}-${UNIQUE}"
29+
30+
docker container rm -f "${CONTAINER_NAME}" 2>/dev/null || true
31+
docker image rm -f "${TAG}_${UNIQUE}"

‎.github/actions/readme.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,23 @@ Inputs:
8787

8888
- `uid`: Unique identifier output from docker-build action
8989
- `tag`: Tag of the built image to use
90+
- `name`: Name substring passed to docker-run (optional)
9091

9192
### Notes
9293

9394
- UID must be unique, easily obtained from build action
9495
- Tag must match built image, easily obtained from build action
95-
- Use `if: always()` to always clean up the image, even if the workflow fails
96+
- If set, name must match the optional name passed to docker-run
97+
- Use `if: always()` to clean up the container and image even if the workflow
98+
fails
9699

97100
Example:
98101

99102
```yaml
100103
jobs:
101104
test:
102105
steps:
103-
- name: Cleanup Docker image
106+
- name: Cleanup Docker resources
104107
if: always()
105108
uses: ./.github/actions/docker-clean
106109
with:

0 commit comments

Comments
 (0)