Skip to content
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
10 changes: 10 additions & 0 deletions dropgz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Running the dropgz locally

Select the file(for example azure-ipam binary) you want to deploy using the dropgz.

1. Copy the file (i.e azure-ipam) to the directory `/dropgz/pkg/embed/fs`
2. Add the sha of the file to the sum.txt file.(`sha256sum * > sum.txt`)
3. You need to gzip the file, so run the cmd `gzip --verbose --best --recursive azure-ipam` and rename the output .gz file to original file name.
4. Do the step 3 for `sum.txt` file as well.
5. go to dropgz directory and build it. (`go build .`)
6. You can now test the dropgz command locally. (`./dropgz deploy azure-ipam -o ./azure-ipam`)
12 changes: 10 additions & 2 deletions dropgz/pkg/embed/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
)

const (
cwd = "fs"
pathPrefix = cwd + string(filepath.Separator)
cwd = "fs"
pathPrefix = cwd + string(filepath.Separator)
oldFileSuffix = ".old"
)

var ErrArgsMismatched = errors.New("mismatched argument count")
Expand Down Expand Up @@ -86,6 +87,13 @@ func deploy(src, dest string) error {
return err
}
defer rc.Close()
// check if the file exists at dest already and rename it as an old one
if _, err := os.Stat(dest); err == nil {
oldDest := dest + oldFileSuffix
if err = os.Rename(dest, oldDest); err != nil {
return errors.Wrapf(err, "failed to rename the %s to %s", dest, oldDest)
}
}
target, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755) //nolint:gomnd // executable file bitmask
if err != nil {
return errors.Wrapf(err, "failed to create file %s", dest)
Expand Down