Skip to content

Commit 1332866

Browse files
ilopezlunadoringeman
authored andcommitted
Download GGUF, package as Docker Model and push it to Hub (docker#87)
* Use username + pass auth if DOCKER_USERNAME & DOCKER_PASSWORD are defined * Added GHA to package and push a model * Install certs * Don't initialize client twice
1 parent b39106b commit 1332866

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

cmd/mdltool/main.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ func main() {
6262
os.Exit(1)
6363
}
6464

65-
// Create the client
66-
client, err := distribution.NewClient(
65+
// Create the client with auth if environment variables are set
66+
clientOpts := []distribution.Option{
6767
distribution.WithStoreRootPath(absStorePath),
68-
distribution.WithUserAgent("model-distribution-tool/"+version),
69-
)
68+
distribution.WithUserAgent("model-distribution-tool/" + version),
69+
}
70+
71+
if username := os.Getenv("DOCKER_USERNAME"); username != "" {
72+
if password := os.Getenv("DOCKER_PASSWORD"); password != "" {
73+
clientOpts = append(clientOpts, distribution.WithRegistryAuth(username, password))
74+
}
75+
}
7076

77+
client, err := distribution.NewClient(clientOpts...)
7178
if err != nil {
7279
fmt.Fprintf(os.Stderr, "Error creating client: %v\n", err)
7380
os.Exit(1)
@@ -176,10 +183,23 @@ func cmdPackage(args []string) int {
176183
fmt.Fprintf(os.Stderr, "Continuing anyway, but this may cause issues.\n")
177184
}
178185

179-
// Parse the reference
180-
target, err := registry.NewClient(
186+
// Prepare registry client options
187+
registryClientOpts := []registry.ClientOption{
181188
registry.WithUserAgent("model-distribution-tool/" + version),
182-
).NewTarget(reference)
189+
}
190+
191+
// Add auth if available
192+
if username := os.Getenv("DOCKER_USERNAME"); username != "" {
193+
if password := os.Getenv("DOCKER_PASSWORD"); password != "" {
194+
registryClientOpts = append(registryClientOpts, registry.WithAuthConfig(username, password))
195+
}
196+
}
197+
198+
// Create registry client once with all options
199+
registryClient := registry.NewClient(registryClientOpts...)
200+
201+
// Parse the reference
202+
target, err := registryClient.NewTarget(reference)
183203
if err != nil {
184204
fmt.Fprintf(os.Stderr, "Error parsing reference: %v\n", err)
185205
return 1

0 commit comments

Comments
 (0)