Skip to content

Commit 10f3178

Browse files
authored
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?).
1 parent 883cec5 commit 10f3178

File tree

14 files changed

+943
-387
lines changed

14 files changed

+943
-387
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
}

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.PHONY: all test dep build
33

44
dep:
5-
glide install --strip-vendor
5+
dep ensure --update
66

77
build:
88
go build -o functions
@@ -24,6 +24,7 @@ run:
2424
./functions
2525

2626
docker-dep:
27+
# todo: need to create a dep tool image for this (or just ditch this)
2728
docker run --rm -it -v ${CURDIR}:/go/src/github.com/iron-io/functions -w /go/src/github.com/iron-io/functions treeder/glide install -v
2829

2930
docker-build:

api/runner/docker-registry.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package runner
2+
3+
import (
4+
"strings"
5+
)
6+
7+
type dockerRegistry struct {
8+
Name string `json:"name"`
9+
Username string `json:"username"`
10+
Password string `json:"password"`
11+
}
12+
13+
type dockerRegistries []dockerRegistry
14+
15+
func (t dockerRegistries) Find(name string) *dockerRegistry {
16+
for _, v := range t {
17+
if strings.HasSuffix(v.Name, name) {
18+
return &v
19+
}
20+
}
21+
return nil
22+
}

api/runner/runner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ func (r Runner) EnsureImageExists(ctx context.Context, cfg *task.Config) error {
228228
cfg: cfg,
229229
}
230230

231-
_, err := docker.CheckRegistry(ctask.Image(), ctask.DockerAuth())
231+
auth, err := ctask.DockerAuth()
232+
if err != nil {
233+
return err
234+
}
235+
236+
_, err = docker.CheckRegistry(ctask.Image(), auth)
232237
return err
233238
}
234239

api/runner/task.go

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,57 @@ package runner
22

33
import (
44
"context"
5+
"encoding/json"
56
"io"
7+
"os"
8+
"os/user"
9+
"path/filepath"
610
"time"
711

8-
"github.com/fsouza/go-dockerclient"
12+
"github.com/docker/docker/cli/config/configfile"
13+
docker "github.com/fsouza/go-dockerclient"
914
"github.com/iron-io/functions/api/runner/task"
1015
"github.com/iron-io/runner/drivers"
1116
)
1217

18+
var registries dockerRegistries
19+
20+
func init() {
21+
22+
// Attempt to fetch it from an environment variable
23+
regsettings := os.Getenv("DOCKER_AUTH")
24+
25+
if regsettings == "" {
26+
u, err := user.Current()
27+
if err == nil {
28+
var config configfile.ConfigFile
29+
cfile, err := os.Open(filepath.Join(u.HomeDir, ".docker", "config.json"))
30+
if err != nil {
31+
return
32+
}
33+
err = config.LoadFromReader(cfile)
34+
if err != nil {
35+
return
36+
}
37+
38+
var regs []dockerRegistry
39+
for _, auth := range config.AuthConfigs {
40+
regs = append(regs, dockerRegistry{
41+
Username: auth.Username,
42+
Password: auth.Password,
43+
Name: auth.ServerAddress,
44+
})
45+
}
46+
47+
registries = dockerRegistries(regs)
48+
}
49+
} else {
50+
// If we have settings, unmarshal them
51+
json.Unmarshal([]byte(regsettings), &registries)
52+
}
53+
54+
}
55+
1356
type containerTask struct {
1457
ctx context.Context
1558
cfg *task.Config
@@ -31,17 +74,31 @@ func (t *containerTask) Labels() map[string]string {
3174
}
3275
}
3376

34-
func (t *containerTask) Id() string { return t.cfg.ID }
35-
func (t *containerTask) Route() string { return "" }
36-
func (t *containerTask) Image() string { return t.cfg.Image }
37-
func (t *containerTask) Timeout() time.Duration { return t.cfg.Timeout }
38-
func (t *containerTask) IdleTimeout() time.Duration { return t.cfg.IdleTimeout }
39-
func (t *containerTask) Logger() (io.Writer, io.Writer) { return t.cfg.Stdout, t.cfg.Stderr }
40-
func (t *containerTask) Volumes() [][2]string { return [][2]string{} }
41-
func (t *containerTask) WorkDir() string { return "" }
77+
func (t *containerTask) Id() string { return t.cfg.ID }
78+
func (t *containerTask) Route() string { return "" }
79+
func (t *containerTask) Image() string { return t.cfg.Image }
80+
func (t *containerTask) Timeout() time.Duration { return t.cfg.Timeout }
81+
func (t *containerTask) IdleTimeout() time.Duration { return t.cfg.IdleTimeout }
82+
func (t *containerTask) Logger() (io.Writer, io.Writer) { return t.cfg.Stdout, t.cfg.Stderr }
83+
func (t *containerTask) Volumes() [][2]string { return [][2]string{} }
84+
func (t *containerTask) WorkDir() string { return "" }
4285

4386
func (t *containerTask) Close() {}
4487
func (t *containerTask) WriteStat(drivers.Stat) {}
4588

46-
// FIXME: for now just use empty creds => public docker hub image
47-
func (t *containerTask) DockerAuth() docker.AuthConfiguration { return docker.AuthConfiguration{} }
89+
// Implementing the docker.AuthConfiguration interface. Pulling in
90+
// the docker repo password from environment variables
91+
func (t *containerTask) DockerAuth() (docker.AuthConfiguration, error) {
92+
reg, _, _ := drivers.ParseImage(t.Image())
93+
authconfig := docker.AuthConfiguration{}
94+
95+
if customAuth := registries.Find(reg); customAuth != nil {
96+
authconfig = docker.AuthConfiguration{
97+
Password: customAuth.Password,
98+
ServerAddress: customAuth.Name,
99+
Username: customAuth.Username,
100+
}
101+
}
102+
103+
return authconfig, nil
104+
}

circle.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ machine:
33
CHECKOUT_DIR: $HOME/$CIRCLE_PROJECT_REPONAME
44
GOPATH: $HOME/go
55
GOROOT: $HOME/golang/go
6-
PATH: $GOROOT/bin:$PATH
6+
PATH: $GOROOT/bin:$GOPATH/bin:/$PATH
77
GH_IRON: $GOPATH/src/github.com/iron-io
88
GO_PROJECT: ../go/src/github.com/iron-io/$CIRCLE_PROJECT_REPONAME
99
services:
@@ -19,19 +19,15 @@ dependencies:
1919
- wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
2020
- mkdir -p $HOME/golang
2121
- tar -C $HOME/golang -xvzf go1.8.linux-amd64.tar.gz
22-
- wget https://github.com/Masterminds/glide/releases/download/v0.12.3/glide-v0.12.3-linux-amd64.tar.gz
23-
- tar -C $HOME/bin -xvzf glide-v0.12.3-linux-amd64.tar.gz --strip=1
22+
- go get -u github.com/golang/dep/...
2423
override:
2524
- which go && go version
26-
- glide --version
2725
- make dep:
2826
pwd: $GO_PROJECT
2927

3028
test:
3129
override:
32-
- make docker-test:
33-
pwd: $GO_PROJECT
34-
- make test-datastore:
30+
- make test:
3531
pwd: $GO_PROJECT
3632
- make test-build-arm:
3733
pwd: $GO_PROJECT

clients/build.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def clone(lang)
8888
puts "SKIPPING GO, it's manual for now."
8989
# This is using https://goswagger.io/ instead
9090
# TODO: run this build command instead: this works if run manually
91-
# glide install -v && docker run --rm -it -v $HOME/dev/go:/go -w /go/src/github.com/iron-io/functions_go quay.io/goswagger/swagger generate client -f https://raw.githubusercontent.com/iron-io/functions/master/docs/swagger.yml -A functions
91+
# dep ensure --update && docker run --rm -it -v $HOME/dev/go:/go -w /go/src/github.com/iron-io/functions_go quay.io/goswagger/swagger generate client -f https://raw.githubusercontent.com/iron-io/functions/master/docs/swagger.yml -A functions
9292
else
9393
gen = JSON.parse(HTTP.post("https://generator.swagger.io/api/gen/clients/#{l}",
9494
json: {

docs/operating/kubernetes/kubernetes-production/functions-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ metadata:
44
name: functions-config
55
data:
66
MQ_URL: redis://redis-master.default
7-
DB_URL: postgres://postgres:mysecretpassword@postgresql-master.default/?sslmode=disable
7+
DB_URL: postgres://postgres:mysecretpassword@postgresql-master.default/?sslmode=disable

docs/operating/kubernetes/kubernetes-production/functions-deployment.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ spec:
3131
name: functions-config
3232
key: DB_URL
3333
volumeMounts:
34-
- mountPath: "/var/run/docker.sock"
35-
name: docker-socket
36-
readOnly: false
34+
- mountPath: "/var/run/docker.sock"
35+
name: docker-socket
36+
readOnly: false
3737
ports:
3838
- name: http-server
3939
containerPort: 8080

fn/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ docker: vendor
1010
docker push iron/fn
1111

1212
vendor:
13-
glide install -v
13+
dep ensure --update
1414

1515
test:
16-
go test -v $(shell glide nv)
16+
go test $(go list ./... | grep -v /vendor/)
1717

1818
release:
1919
GOOS=linux go build -o fn_linux

0 commit comments

Comments
 (0)