mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Switching to new dep tool (#616)
* making things work * #506 - Add ability to login to a private docker registry * Rolling back "make things work" to test them out more. * Rolling back "make things work" to test them out more. * credentials from docker/config.json if ENV is missing * should get docker auth info just in the init * update glide lock * update glide * Switched to new go dep tool, glide is too frikin annoying. * Updated circle builds to use dep * Added GOPATH/bin to path. * Added GOPATH/bin to path. * Using regular make test, instead of docker one (not sure why it was using the docker one?).
This commit is contained in:
@@ -2,14 +2,57 @@ package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/docker/docker/cli/config/configfile"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
)
|
||||
|
||||
var registries dockerRegistries
|
||||
|
||||
func init() {
|
||||
|
||||
// Attempt to fetch it from an environment variable
|
||||
regsettings := os.Getenv("DOCKER_AUTH")
|
||||
|
||||
if regsettings == "" {
|
||||
u, err := user.Current()
|
||||
if err == nil {
|
||||
var config configfile.ConfigFile
|
||||
cfile, err := os.Open(filepath.Join(u.HomeDir, ".docker", "config.json"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = config.LoadFromReader(cfile)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var regs []dockerRegistry
|
||||
for _, auth := range config.AuthConfigs {
|
||||
regs = append(regs, dockerRegistry{
|
||||
Username: auth.Username,
|
||||
Password: auth.Password,
|
||||
Name: auth.ServerAddress,
|
||||
})
|
||||
}
|
||||
|
||||
registries = dockerRegistries(regs)
|
||||
}
|
||||
} else {
|
||||
// If we have settings, unmarshal them
|
||||
json.Unmarshal([]byte(regsettings), ®istries)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type containerTask struct {
|
||||
ctx context.Context
|
||||
cfg *task.Config
|
||||
@@ -31,17 +74,31 @@ func (t *containerTask) Labels() map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *containerTask) Id() string { return t.cfg.ID }
|
||||
func (t *containerTask) Route() string { return "" }
|
||||
func (t *containerTask) Image() string { return t.cfg.Image }
|
||||
func (t *containerTask) Timeout() time.Duration { return t.cfg.Timeout }
|
||||
func (t *containerTask) IdleTimeout() time.Duration { return t.cfg.IdleTimeout }
|
||||
func (t *containerTask) Logger() (io.Writer, io.Writer) { return t.cfg.Stdout, t.cfg.Stderr }
|
||||
func (t *containerTask) Volumes() [][2]string { return [][2]string{} }
|
||||
func (t *containerTask) WorkDir() string { return "" }
|
||||
func (t *containerTask) Id() string { return t.cfg.ID }
|
||||
func (t *containerTask) Route() string { return "" }
|
||||
func (t *containerTask) Image() string { return t.cfg.Image }
|
||||
func (t *containerTask) Timeout() time.Duration { return t.cfg.Timeout }
|
||||
func (t *containerTask) IdleTimeout() time.Duration { return t.cfg.IdleTimeout }
|
||||
func (t *containerTask) Logger() (io.Writer, io.Writer) { return t.cfg.Stdout, t.cfg.Stderr }
|
||||
func (t *containerTask) Volumes() [][2]string { return [][2]string{} }
|
||||
func (t *containerTask) WorkDir() string { return "" }
|
||||
|
||||
func (t *containerTask) Close() {}
|
||||
func (t *containerTask) WriteStat(drivers.Stat) {}
|
||||
|
||||
// FIXME: for now just use empty creds => public docker hub image
|
||||
func (t *containerTask) DockerAuth() docker.AuthConfiguration { return docker.AuthConfiguration{} }
|
||||
// Implementing the docker.AuthConfiguration interface. Pulling in
|
||||
// the docker repo password from environment variables
|
||||
func (t *containerTask) DockerAuth() (docker.AuthConfiguration, error) {
|
||||
reg, _, _ := drivers.ParseImage(t.Image())
|
||||
authconfig := docker.AuthConfiguration{}
|
||||
|
||||
if customAuth := registries.Find(reg); customAuth != nil {
|
||||
authconfig = docker.AuthConfiguration{
|
||||
Password: customAuth.Password,
|
||||
ServerAddress: customAuth.Name,
|
||||
Username: customAuth.Username,
|
||||
}
|
||||
}
|
||||
|
||||
return authconfig, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user