Skip to content

Commit

Permalink
fix(worker): fix pulling docker images from third party registries
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Mar 2, 2021
1 parent 086c8d2 commit e718694
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
6 changes: 5 additions & 1 deletion worker/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func RunContainer(name, image string, commands [][]string, env []string, dir str
return err
}
defer close(logch)
var shell string

resp, err := createContainer(cli, name, image, dir, []string{"/bin/bash"}, env)
if err != nil {
Expand All @@ -34,6 +35,9 @@ func RunContainer(name, image string, commands [][]string, env []string, dir str
logch <- []byte(err.Error())
return err
}
shell = "sh"
} else {
shell = "bash"
}
}
defer cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true})
Expand All @@ -52,7 +56,7 @@ func RunContainer(name, image string, commands [][]string, env []string, dir str
}
str := yellow("\r==> " + strings.Join(command, " ") + "\n\r")
logch <- []byte(str)
command = []string{"bash", "-ci", strings.Join(command, " ")}
command = []string{shell, "-ci", strings.Join(command, " ")}
conn, execID, err := exec(cli, containerID, command, env)
if err != nil {
logch <- []byte(err.Error())
Expand Down
18 changes: 0 additions & 18 deletions worker/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"path"
Expand Down Expand Up @@ -100,23 +99,6 @@ func PullImage(image string, config *config.Registry) error {
opts.RegistryAuth = base64.URLEncoding.EncodeToString(authJSON)
}

if config.Addr != "" && !strings.Contains(config.Addr, "docker.io") {
pimage := fmt.Sprintf("%s/%s", config.Addr, image)

out, err := cli.ImagePull(ctx, pimage, opts)
if err == nil {
defer out.Close()
ioutil.ReadAll(out)
return nil
}
}

if !strings.Contains(image, "/") && !strings.HasPrefix(image, "docker.io") {
image = fmt.Sprintf("docker.io/library/%s", image)
} else if strings.Contains(image, "/") && !strings.HasPrefix(image, "docker.io") {
image = fmt.Sprintf("docker.io/%s", image)
}

out, err := cli.ImagePull(ctx, image, opts)
if err == nil {
defer out.Close()
Expand Down

0 comments on commit e718694

Please sign in to comment.