mirror of
https://github.com/outbackdingo/debos.git
synced 2026-01-27 10:18:47 +00:00
Enabled additional linters from fakemachine configuration: - errorlint: Error wrapping with %w - misspell: Spelling checks - revive: Code quality checks - whitespace: Formatting checks Fixed all issues including: - Error handling: Added proper error checks for all function returns - Error wrapping: Changed %v to %w for proper error wrapping - Type assertions: Used errors.As instead of direct type assertions - Unused parameters: Renamed to underscore where appropriate - Variable naming: Fixed ALL_CAPS constants and underscored names - Whitespace: Removed unnecessary leading/trailing newlines - Code flow: Removed unnecessary else blocks Renamed types (breaking internal API changes): - DebosState → State - DebosContext → Context - DownloadHttpUrl → DownloadHTTPURL Fixed struct field naming with proper YAML tags: - Url → URL (with yaml:"url" tag) - TlsClientCertPath → TLSClientCertPath (kept yaml:"tls-client-cert-path") - TlsClientKeyPath → TLSClientKeyPath (kept yaml:"tls-client-key-path") - validateUrl → validateURL method Co-authored-by: sjoerdsimons <22603932+sjoerdsimons@users.noreply.github.com>
99 lines
2.2 KiB
Go
99 lines
2.2 KiB
Go
/*
|
|
Pack Action
|
|
|
|
Create tarball with filesystem.
|
|
|
|
# Yaml syntax:
|
|
- action: pack
|
|
file: filename.ext
|
|
compression: gz
|
|
|
|
Mandatory properties:
|
|
|
|
- file -- name of the output tarball, relative to the artifact directory.
|
|
|
|
Optional properties:
|
|
|
|
- compression -- compression type to use. Currently 'bzip2', 'gz', 'lzip', lzma', 'lzop',
|
|
'xz' and 'zstd' compression types are supported. Use 'none' for uncompressed tarball.
|
|
Use 'auto' to pick via file extension. The 'gz' compression type will be used by default.
|
|
*/
|
|
package actions
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/go-debos/debos"
|
|
)
|
|
|
|
var tarOpts = map[string]string{
|
|
"bzip2": "--bzip2",
|
|
"gz": "--gzip",
|
|
"lzip": "--lzip",
|
|
"lzma": "--lzma",
|
|
"lzop": "--lzop",
|
|
"xz": "--xz",
|
|
"zstd": "--zstd",
|
|
"auto": "--auto-compress",
|
|
"none": "",
|
|
}
|
|
|
|
type PackAction struct {
|
|
debos.BaseAction `yaml:",inline"`
|
|
Compression string
|
|
File string
|
|
}
|
|
|
|
func NewPackAction() *PackAction {
|
|
d := PackAction{}
|
|
// Use gz by default
|
|
d.Compression = "gz"
|
|
|
|
return &d
|
|
}
|
|
|
|
func (pf *PackAction) Verify(_ *debos.Context) error {
|
|
_, compressionAvailable := tarOpts[pf.Compression]
|
|
if compressionAvailable {
|
|
return nil
|
|
}
|
|
|
|
possibleTypes := make([]string, 0, len(tarOpts))
|
|
for key := range tarOpts {
|
|
possibleTypes = append(possibleTypes, key)
|
|
}
|
|
|
|
return fmt.Errorf("option 'compression' has an unsupported type: `%s`; possible types are %s",
|
|
pf.Compression, strings.Join(possibleTypes, ", "))
|
|
}
|
|
|
|
func (pf *PackAction) Run(context *debos.Context) error {
|
|
usePigz := false
|
|
if pf.Compression == "gz" {
|
|
if _, err := exec.LookPath("pigz"); err == nil {
|
|
usePigz = true
|
|
}
|
|
}
|
|
outfile := path.Join(context.Artifactdir, pf.File)
|
|
|
|
command := []string{"tar"}
|
|
command = append(command, "cf")
|
|
command = append(command, outfile)
|
|
command = append(command, "--xattrs")
|
|
command = append(command, "--xattrs-include=*.*")
|
|
if usePigz {
|
|
command = append(command, "--use-compress-program=pigz")
|
|
} else if tarOpts[pf.Compression] != "" {
|
|
command = append(command, tarOpts[pf.Compression])
|
|
}
|
|
command = append(command, "-C", context.Rootdir)
|
|
command = append(command, ".")
|
|
|
|
log.Printf("Compressing to %s\n", outfile)
|
|
return debos.Command{}.Run("Packing", command...)
|
|
}
|