Skip to content

Commit caf5524

Browse files
committed
Merge pull request #18 from arschles/minio
feat(*): add support for uploading tarballs to minio
2 parents 7afa12e + a3b361b commit caf5524

5 files changed

Lines changed: 43 additions & 23 deletions

File tree

pkg/confd/confd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ func RunOnce(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
4545
var lasterr error
4646
start := time.Now()
4747
for i := 0; i < limit; i++ {
48-
if out, err := exec.Command("confd", dargs...).CombinedOutput(); err == nil {
48+
out, err := exec.Command("confd", dargs...).CombinedOutput()
49+
if err == nil {
4950
log.Infof(c, "Templates generated for %s on run %d", node, i)
5051
return out, nil
51-
} else {
52-
log.Debugf(c, "Recoverable error: %s", err)
53-
log.Debugf(c, "Output: %q", out)
54-
lasterr = err
5552
}
53+
log.Debugf(c, "Recoverable error: %s", err)
54+
log.Debugf(c, "Output: %q", out)
55+
lasterr = err
5656

5757
time.Sleep(timeout)
5858
log.Infof(c, "Re-trying template build. (Elapsed time: %d)", time.Now().Sub(start)/time.Second)

pkg/etcd/etcd.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*Package etcd is a library for performing common Etcd tasks.
2-
*/
1+
// Package etcd is a library for performing common Etcd tasks.
32
package etcd
43

54
import (
@@ -23,6 +22,12 @@ var (
2322
retrySleep = 200 * time.Millisecond
2423
)
2524

25+
const (
26+
hostEnvVar = "DEIS_ETCD_1_SERVICE_HOST"
27+
portEnvVar = "DEIS_ETCD_1_SERVICE_PORT_CLIENT"
28+
defaultHost = "http://localhost"
29+
)
30+
2631
// Getter describes the Get behavior of an Etcd client.
2732
//
2833
// Usually you will want to use go-etcd/etcd.Client to satisfy this.
@@ -65,7 +70,11 @@ type GetterSetter interface {
6570
// Returns:
6671
// This puts an *etcd.Client into the context.
6772
func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
68-
url := p.Get("url", "http://localhost:4001").(string)
73+
url, ok := p.Get("url", "http://localhost:4001").(string)
74+
if !ok {
75+
fmt.Println("ERROR: 'url' param was not a string")
76+
os.Exit(1)
77+
}
6978

7079
// Backed this out because it's unnecessary so far.
7180
//hosts := p.Get("urls", []string{"http://localhost:4001"}).([]string)
@@ -136,7 +145,7 @@ func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrup
136145
time.Sleep(250 * time.Millisecond)
137146
}
138147
log.Errf(c, "Etcd is not answering after %d attempts.", count)
139-
return false, &cookoo.FatalError{"Could not connect to Etcd."}
148+
return false, &cookoo.FatalError{Message: "Could not connect to Etcd."}
140149
}
141150

142151
// Set sets a value in etcd.
@@ -399,7 +408,7 @@ func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
399408

400409
res, err := client.CreateDir(name, ttl)
401410
if err != nil {
402-
return res, &cookoo.RecoverableError{err.Error()}
411+
return res, &cookoo.RecoverableError{Message: err.Error()}
403412
}
404413

405414
return res, nil

pkg/git/git.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@ func createRepo(c cookoo.Context, repoPath, gitHome string) (bool, error) {
177177
createLock.Lock()
178178
defer createLock.Unlock()
179179

180-
if fi, err := os.Stat(repoPath); err == nil && fi.IsDir() {
180+
fi, err := os.Stat(repoPath)
181+
if err == nil && fi.IsDir() {
181182
// Nothing to do.
182183
log.Infof(c, "Directory %s already exists.", repoPath)
183184
return false, nil
184185
} else if os.IsNotExist(err) {
185-
186186
log.Infof(c, "Creating new directory at %s", repoPath)
187187
// Create directory
188188
if err := os.MkdirAll(repoPath, 0755); err != nil {
@@ -205,9 +205,8 @@ func createRepo(c cookoo.Context, repoPath, gitHome string) (bool, error) {
205205
return true, nil
206206
} else if err == nil {
207207
return false, errors.New("Expected directory, found file.")
208-
} else {
209-
return false, err
210208
}
209+
return false, err
211210
}
212211

213212
//prereceiveHook templates a pre-receive hook for Git.

pkg/sshd/server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/*Package sshd implements an SSH server.
2-
3-
See https://tools.ietf.org/html/rfc4254
4-
5-
This was copied over (and effectively forked from) cookoo-ssh. Mainly this
6-
differs from the cookoo-ssh version in that this does not act like a
7-
stand-alone SSH server.
8-
*/
1+
// Package sshd implements an SSH server.
2+
//
3+
// See https://tools.ietf.org/html/rfc4254
4+
//
5+
// This was copied over (and effectively forked from) cookoo-ssh. Mainly this
6+
// differs from the cookoo-ssh version in that this does not act like a
7+
// stand-alone SSH server.
98
package sshd
109

1110
import (
@@ -169,7 +168,7 @@ func sshConnection(conn net.Conn) string {
169168
rhost, rport, _ := net.SplitHostPort(remote)
170169
lhost, lport, _ := net.SplitHostPort(local)
171170

172-
return fmt.Sprintf("%s %d %s %d", rhost, rport, lhost, lport)
171+
return fmt.Sprintf("%s %s %s %s", rhost, rport, lhost, lport)
173172
}
174173

175174
func sendExitStatus(status uint32, channel ssh.Channel) error {

rootfs/etc/confd/templates/builder

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ else
9595
fi
9696
fi
9797

98+
git archive --format=tar.gz ${GIT_SHA} > ${APP_NAME}.tar.gz
99+
98100
# if minio is in the cluster, use it. otherwise use fetcher
101+
# TODO: figure out something for using S3 also
99102
if [[ -n "$DEIS_MINIO_SERVICE_HOST" && -n "$DEIS_MINIO_SERVICE_PORT" ]]; then
100103
S3EP=${DEIS_MINIO_SERVICE_HOST}:${DEIS_MINIO_SERVICE_PORT}
101104
elif [ -z "$S3EP" ]; then
@@ -109,6 +112,16 @@ sed -i -- "s#repo_name#$META_NAME#g" /etc/${SLUG_NAME}.yaml
109112
sed -i -- "s#puturl#$PUSH_URL#g" /etc/${SLUG_NAME}.yaml
110113
sed -i -- "s#tar-url#$TAR_URL#g" /etc/${SLUG_NAME}.yaml
111114

115+
ACCESS_KEY=`cat /var/run/secrets/object/store/access-key-id`
116+
ACCESS_SECRET=`cat /var/run/secrets/object/store/access-secret-key`
117+
mkdir -p /var/minio-conf
118+
CONFIG_DIR=/var/minio-conf
119+
echo "mc -C $CONFIG_DIR config host add "http://$S3EP" $ACCESS_KEY $ACCESS_SECRET"
120+
mc -C $CONFIG_DIR --quiet config host add "http://$S3EP" $ACCESS_KEY $ACCESS_SECRET
121+
mc -C $CONFIG_DIR --quiet mb "${S3EP}/git"
122+
mc -C $CONFIG_DIR --quiet cp ${APP_NAME}.tar.gz $TAR_URL
123+
echo "stored tarfile in $TAR_URL"
124+
112125
kubectl create -f /etc/${SLUG_NAME}.yaml
113126

114127
#check for image creation or slug existence in S3EP

0 commit comments

Comments
 (0)