Skip to content

Commit

Permalink
Allow deleting intermediate images
Browse files Browse the repository at this point in the history
fixes #1320
  • Loading branch information
subhoghoshX authored and jelly committed Nov 21, 2023
1 parent 7efa394 commit 82e8ca3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ImageDeleteModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function sortTags(a, b) {
export const ImageDeleteModal = ({ imageWillDelete, onAddNotification }) => {
const Dialogs = useDialogs();
const repoTags = imageWillDelete.RepoTags ? imageWillDelete.RepoTags : [];
const isIntermediateImage = repoTags.length === 0;

const [tags, setTags] = useState(repoTags.sort(sortTags).reduce((acc, item, i) => {
acc[item] = (i === 0);
Expand Down Expand Up @@ -55,7 +56,7 @@ export const ImageDeleteModal = ({ imageWillDelete, onAddNotification }) => {
if (all)
client.delImage(imageWillDelete.isSystem, imageWillDelete.Id, false)
.catch(ex => {
Dialogs.show(<ForceRemoveModal name={imageWillDelete.RepoTags[0]}
Dialogs.show(<ForceRemoveModal name={isIntermediateImage ? _("intermediate image") : repoTags[0]}
handleForceRemove={handleForceRemoveImage}
reason={ex.message} />);
});
Expand All @@ -75,7 +76,7 @@ export const ImageDeleteModal = ({ imageWillDelete, onAddNotification }) => {
}
};

const imageName = repoTags[0]?.split(":")[0].split("/").at(-1) ?? "";
const imageName = repoTags[0]?.split(":")[0].split("/").at(-1) ?? _("intermediate");

let isAllSelected = null;
if (checkedTags.length === repoTags.length)
Expand All @@ -90,9 +91,9 @@ export const ImageDeleteModal = ({ imageWillDelete, onAddNotification }) => {
onClose={Dialogs.close}
title={cockpit.format(_("Delete $0 image?"), imageName)}
footer={<>
<Button id="btn-img-delete" variant="danger" isDisabled={checkedTags.length === 0}
<Button id="btn-img-delete" variant="danger" isDisabled={!isIntermediateImage && checkedTags.length === 0}
onClick={() => handleRemoveImage(checkedTags, checkedTags.length === repoTags.length)}>
{_("Delete tagged images")}
{isIntermediateImage ? _("Delete image") : _("Delete tagged images")}
</Button>
<Button variant="link" onClick={Dialogs.close}>{_("Cancel")}</Button>
</>}
Expand Down
23 changes: 23 additions & 0 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,29 @@ class TestApplication(testlib.MachineCase):
b.click(".pf-v5-c-modal-box .btn-cancel")
b.wait_not_present(".pf-v5-c-modal-box")

# Delete intermediate images
intermediate_image_sel = "#containers-images tbody:last-child:contains('<none>:<none>')"
b.click(".listing-action button:contains('Show intermediate images')")
b.click(intermediate_image_sel + " .pf-v5-c-dropdown__toggle")
b.click(intermediate_image_sel + " button.btn-delete")
self.confirm_modal("Delete")
b.wait_not_present(intermediate_image_sel)
# Delete intermediate image which is in use
tmpdir = self.execute(auth, "mktemp -d").strip()
self.execute(auth, f"echo 'FROM {IMG_REGISTRY}\nRUN ls' > {tmpdir}/Dockerfile")
IMG_INTERMEDIATE = 'localhost/test-intermediate'
self.execute(auth, f"podman build -t {IMG_INTERMEDIATE} {tmpdir}")
b.click(f'#containers-images tbody tr:contains("{IMG_INTERMEDIATE}") .ct-container-create')
b.wait_visible('div.pf-v5-c-modal-box header:contains("Create container")')
b.click("#create-image-create-btn")
self.execute(auth, f"podman untag {IMG_INTERMEDIATE}")
b.click(intermediate_image_sel + " .pf-v5-c-dropdown__toggle")
b.click(intermediate_image_sel + " button.btn-delete")
self.confirm_modal("Delete")
self.confirm_modal("Force delete")
b.wait_not_in_text("#containers-images", "<none>:<none>")
b.wait_not_in_text("#containers-containers", IMG_INTERMEDIATE)

def testCommitUser(self):
self._testCommit(False)

Expand Down

0 comments on commit 82e8ca3

Please sign in to comment.