diff --git a/dropgz/README.md b/dropgz/README.md new file mode 100644 index 0000000000..7ca59da397 --- /dev/null +++ b/dropgz/README.md @@ -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`) \ No newline at end of file diff --git a/dropgz/pkg/embed/payload.go b/dropgz/pkg/embed/payload.go index 7e5341a593..b36f8cb479 100644 --- a/dropgz/pkg/embed/payload.go +++ b/dropgz/pkg/embed/payload.go @@ -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") @@ -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)