mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package tgzstream
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/hanzoai/cd/util/io/files"
|
|
)
|
|
|
|
func CloseAndDelete(f *os.File) {
|
|
if f == nil {
|
|
return
|
|
}
|
|
if err := f.Close(); err != nil {
|
|
log.Warnf("error closing file %q: %s", f.Name(), err)
|
|
}
|
|
if err := os.Remove(f.Name()); err != nil {
|
|
log.Warnf("error removing file %q: %s", f.Name(), err)
|
|
}
|
|
}
|
|
|
|
// CompressFiles will create a tgz file with all contents of appPath
|
|
// directory excluding globs in the excluded array. Returns the file
|
|
// alongside its sha256 hash to be used as checksum. It is the
|
|
// responsibility of the caller to close the file.
|
|
func CompressFiles(appPath string, included []string, excluded []string) (*os.File, int, string, error) {
|
|
appName := filepath.Base(appPath)
|
|
tempDir, err := files.CreateTempDir(os.TempDir())
|
|
if err != nil {
|
|
return nil, 0, "", fmt.Errorf("error creating tempDir for compressing files: %w", err)
|
|
}
|
|
tgzFile, err := os.CreateTemp(tempDir, appName)
|
|
if err != nil {
|
|
return nil, 0, "", fmt.Errorf("error creating app temp tgz file: %w", err)
|
|
}
|
|
hasher := sha256.New()
|
|
filesWritten, err := files.Tgz(appPath, included, excluded, tgzFile, hasher)
|
|
if err != nil {
|
|
CloseAndDelete(tgzFile)
|
|
return nil, 0, "", fmt.Errorf("error creating app tgz file: %w", err)
|
|
}
|
|
checksum := hex.EncodeToString(hasher.Sum(nil))
|
|
hasher.Reset()
|
|
|
|
// reposition the offset to the beginning of the file for proper reads
|
|
_, err = tgzFile.Seek(0, io.SeekStart)
|
|
if err != nil {
|
|
CloseAndDelete(tgzFile)
|
|
return nil, 0, "", fmt.Errorf("error processing tgz file: %w", err)
|
|
}
|
|
return tgzFile, filesWritten, checksum, nil
|
|
}
|