File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name : Docker cleanup action
2- description : Composite action for removing Docker images
2+ description : Composite action for removing Docker containers and images
33author : " Devito"
44
55inputs :
@@ -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
1417runs :
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}"
Original file line number Diff line number Diff 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
97100Example :
98101
99102` ` ` yaml
100103jobs:
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:
You can’t perform that action at this time.
0 commit comments