Skip to content

Commit

Permalink
Add docker host override
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 15, 2024
1 parent 80236de commit 18e60ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
27 changes: 17 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -30,6 +30,7 @@ type ConfigDest struct {
User string `json:"user"`
Password string `json:"password"`
Http bool `json:"http"`
Host string `json:"host"`
}

type Config struct {
Expand All @@ -38,6 +39,7 @@ type Config struct {
FromUser string `json:"from_user"`
FromPassword string `json:"from_password"`
FromHttp bool `json:"from_http"`
FromHost string `json:"from_host"`
Dests []ConfigDest `json:"dests"`
Architecture string `json:"arch"`
Os string `json:"os"`
Expand All @@ -60,13 +62,13 @@ func main0() error {
var args0 []byte
if os.Args[1] == "-" {
var err error
args0, err = ioutil.ReadAll(os.Stdin)
args0, err = io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("error reading config from stdin: %w", err)
}
} else {
var err error
args0, err = ioutil.ReadFile(os.Args[1])
args0, err = os.ReadFile(os.Args[1])
if err != nil {
return fmt.Errorf("error reading config at %s: %w", os.Args[1], err)
}
Expand Down Expand Up @@ -143,7 +145,10 @@ func main0() error {
sourceRef,
&imagecopy.Options{
SourceCtx: &types.SystemContext{
DockerInsecureSkipTLSVerify: noHttpVerify,
DockerInsecureSkipTLSVerify: noHttpVerify,
DockerDaemonHost: config.FromHost,
DockerDaemonInsecureSkipTLSVerify: config.FromHttp,
OCIInsecureSkipTLSVerify: config.FromHttp,
DockerAuthConfig: &types.DockerAuthConfig{
Username: config.FromUser,
Password: config.FromPassword,
Expand Down Expand Up @@ -202,11 +207,10 @@ func main0() error {
}

for i, dest := range config.Dests {
if dest.Ref == "" {
log.Printf("Warning! Missing ref in dest %d, skipping", i)
continue
}
destString := dest.Ref
if destString == "" {
panic(fmt.Sprintf("Missing ref in dest %d", i))
}
for k, v := range map[string]string{
"hash": hash,
"short_hash": hash[:8],
Expand All @@ -215,7 +219,7 @@ func main0() error {
}
destRef, err := alltransports.ParseImageName(destString)
if err != nil {
return fmt.Errorf("invalid dest image ref %s: %w", dest.Ref, err)
return fmt.Errorf("invalid dest image ref %s: %w", destString, err)
}

log.Printf("Pushing to %s...", destString)
Expand All @@ -224,7 +228,10 @@ func main0() error {
noHttpVerify = types.OptionalBoolTrue
}
destSysCtx := types.SystemContext{
DockerInsecureSkipTLSVerify: noHttpVerify,
DockerInsecureSkipTLSVerify: noHttpVerify,
DockerDaemonHost: dest.Host,
DockerDaemonInsecureSkipTLSVerify: dest.Http,
OCIInsecureSkipTLSVerify: dest.Http,
DockerAuthConfig: &types.DockerAuthConfig{
Username: dest.User,
Password: dest.Password,
Expand Down
15 changes: 14 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ This is an example, where I have a Go binary `hello` in my current directory.
{
"from": "alpine.tar",
"from_pull": "docker://alpine:3.17.0",
"dest": "docker://localhost:5000/hello:latest",
"dests": [
{
"ref": "docker-daemon:hello:latest",
"host": "unix:///var/run/docker2.sock"
}
],
"files": [
{
"source": "hello",
Expand Down Expand Up @@ -148,6 +153,10 @@ The json file has these options:

True if this dest is over http (disable tls validation)

- `host`

If using the `docker-daemon` transport which doesn't support host specification, override the default docker daemon.

- `files`

Files to add to the image. This is an array of objects with these fields:
Expand Down Expand Up @@ -190,6 +199,10 @@ The json file has these options:

True if `from_pull` source is over http (disable tls validation)

- `from_host`

If using the `docker-daemon` transport which doesn't support host specification, override the default docker daemon.

- `add_env`

Record with string key-value pairs. Add additional default environment values
Expand Down

0 comments on commit 18e60ad

Please sign in to comment.