-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomasz Gągor
authored and
Tomasz Gągor
committed
Dec 17, 2024
1 parent
d4cfce9
commit ed73884
Showing
15 changed files
with
306 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ __pycache__ | |
.venv | ||
*.pyc | ||
*.Dockerfile | ||
*.tar | ||
.poetry-version | ||
*.bak | ||
*.old | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package config | ||
|
||
type Flags struct { | ||
Build bool | ||
BuildFile string | ||
Delete bool | ||
DryRun bool | ||
Build bool | ||
PrintVersion bool | ||
Push bool | ||
Delete bool | ||
Threads int | ||
Squash bool | ||
Tag string | ||
Threads int | ||
Verbose bool | ||
PrintVersion bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package parser | ||
|
||
import "fmt" | ||
|
||
func ByteCountSI(b uint64) string { | ||
const unit = 1000 | ||
if b < unit { | ||
return fmt.Sprintf("%d B", b) | ||
} | ||
div, exp := int64(unit), 0 | ||
for n := b / unit; n >= unit; n /= unit { | ||
div *= unit | ||
exp++ | ||
} | ||
return fmt.Sprintf("%.1f %cB", | ||
float64(b)/float64(div), "kMGTPE"[exp]) | ||
} | ||
|
||
func ByteCountIEC(b uint64) string { | ||
const unit = 1024 | ||
if b < unit { | ||
return fmt.Sprintf("%d B", b) | ||
} | ||
div, exp := int64(unit), 0 | ||
for n := b / unit; n >= unit; n /= unit { | ||
div *= unit | ||
exp++ | ||
} | ||
return fmt.Sprintf("%.1f %ciB", | ||
float64(b)/float64(div), "KMGTPE"[exp]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/tgagor/template-dockerfiles/pkg/cmd" | ||
"github.com/tgagor/template-dockerfiles/pkg/util" | ||
) | ||
|
||
type DockerInspect []struct { | ||
Config struct { | ||
Env []string `json:"Env"` | ||
Cmd []string `json:"Cmd"` | ||
Volumes map[string]struct{} `json:"Volumes"` | ||
WorkingDir string `json:"WorkingDir"` | ||
Entrypoint []string `json:"Entrypoint"` | ||
Labels map[string]string `json:"Labels"` | ||
} `json:"Config"` | ||
Size uint64 | ||
} | ||
|
||
func inspectImg(image string) (DockerInspect, error) { | ||
out, err := cmd.New("docker").Arg("inspect").Arg("--format").Arg("json").Arg(image).Output() | ||
util.FailOnError(err) | ||
|
||
// Create a variable to hold the unmarshaled data | ||
var inspect DockerInspect | ||
|
||
// Unmarshal the JSON data into the DockerInspect structure | ||
|
||
if err := json.Unmarshal([]byte(out), &inspect); err != nil { | ||
log.Error().Err(err).Msg("Error parsing JSON.") | ||
os.Exit(1) | ||
} | ||
|
||
return inspect, nil | ||
} | ||
|
||
// func imgSize(image string) string { | ||
// out, err := cmd.New("docker").Arg("inspect").Arg("--format").Arg("json").Arg(image).Output() | ||
// util.FailOnError(err) | ||
// } |
Oops, something went wrong.