Andrey Smirnov b1c0f99c04 chore: add cloud image uploader (AWS AMIs for now)
It generates JSON file in the end with the upload results:

```
{"aws":{"regions":{"eu-central-1":{"arch":{"amd64":{"ami_id":"ami-0f559e06baf488ee1"},"arm64":{"ami_id":"ami-01edd1830a3c5d95c"}}},"eu-west-3":{"arch":{"amd64":{"ami_id":"ami-020f95a280c4c1c55"},"arm64":{"ami_id":"ami-0edcc7d694931a52c"}}}}}}
```

Regions, architectures can be modified as well.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-11-20 08:42:01 -08:00

44 lines
930 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package main
import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
)
// ExtractFileFromTarGz reads a single file data from an archive.
func ExtractFileFromTarGz(filename string, r io.Reader) (io.Reader, error) {
zr, err := gzip.NewReader(r)
if err != nil {
return nil, fmt.Errorf("error initializing gzip: %w", err)
}
tr := tar.NewReader(zr)
for {
hdr, err := tr.Next()
if err != nil {
if err == io.EOF {
break
}
return nil, err
}
if hdr.Name == filename {
if hdr.Typeflag == tar.TypeDir || hdr.Typeflag == tar.TypeSymlink {
return nil, fmt.Errorf("%s is not a file", filename)
}
return tr, nil
}
}
return nil, fmt.Errorf("couldn't find file %s in the archive", filename)
}