Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove existing file during build-disk #1857

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
username: ${{ secrets.ELEMENTAL_BOT_GITHUB_USERNAME }}
password: ${{ secrets.ELEMENTAL_BOT_GITHUB_TOKEN }}
- name: Build toolkit image
run: |
make TOOLKIT_REPO=ghcr.io/${{ github.workspace }}/${{ github.repository }}/elemental-cli VERSION=$(git describe --abbrev=0 --tags) build push-toolkit
make PLATFORM=linux/arm64,linux/amd64 TOOLKIT_REPO=ghcr.io/${{ github.workspace }}/${{ github.repository }}/elemental-cli VERSION=latest build push-toolkit
- name: Build green example
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ build-iso: build-os
@echo Building ${ARCH} ISO
mkdir -p $(ROOT_DIR)/build
$(DOCKER) run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(ROOT_DIR)/build:/build \
--entrypoint /usr/bin/elemental $(REPO):$(VERSION) --debug build-iso --bootloader-in-rootfs -n elemental-$(FLAVOR).$(ARCH) \
--entrypoint /usr/bin/elemental ${TOOLKIT_REPO}:${VERSION} --debug build-iso --bootloader-in-rootfs -n elemental-$(FLAVOR).$(ARCH) \
--local --platform $(PLATFORM) --squash-no-compression -o /build $(REPO):$(VERSION)

.PHONY: clean-iso
Expand Down
3 changes: 0 additions & 3 deletions cmd/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ func NewBuildDisk(root *cobra.Command, addCheckRoot bool) *cobra.Command {
spec.Recovery.Source = imgSource
}

// TODO add logic for an already existing output file

builder := action.NewBuildDiskAction(cfg, spec)

return builder.BuildDiskRun()
},
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/action/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ func (b *BuildDiskAction) CreateRAWDisk(e *elemental.Elemental, rawImg string) e
return err
}

// Check if disk already exists
if exists, _ := utils.Exists(b.cfg.Fs, rawImg); exists {
b.cfg.Logger.Warnf("Overwriting already existing %s", rawImg)
err := b.cfg.Fs.Remove(rawImg)
if err != nil {
return elementalError.NewFromError(err, elementalError.RemoveFile)
}
}

// Ensamble disk with all partitions
err = b.CreateDiskImage(rawImg, images...)
if err != nil {
Expand Down