Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/${SHORT_NAME}:${VERSION}
MC_IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/mc:${VERSION}
MC_INTEGRATION_IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/mc-integration:${VERSION}

TEST_PACKAGES := $(shell ${DEV_ENV_CMD} glide nv)

all: build docker-build docker-push

bootstrap:
Expand All @@ -39,6 +41,9 @@ build:
mkdir -p ${BINDIR}
${DEV_ENV_PREFIX} -e CGO_ENABLED=0 ${DEV_ENV_IMAGE} go build -a -installsuffix cgo -ldflags '-s' -o $(BINDIR)/boot boot.go || exit 1

test:
${DEV_ENV_CMD} go test ${TEST_PACKAGES}

docker-build: build-server
# copy the server binary from where it was built to the final image's file system.
# note that the minio server is built as a dependency of this build target.
Expand Down Expand Up @@ -114,7 +119,4 @@ mc-integration-docker-build:
mc-integration-docker-push:
make -C mc/integration docker-push

test:
@echo "Implement functional tests in _tests directory"

.PHONY: all build docker-compile kube-up kube-down deploy mc kube-mc
80 changes: 73 additions & 7 deletions boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ package main

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
"text/template"

"github.com/deis/minio/src/healthsrv"
"github.com/deis/pkg/aboutme"
"github.com/deis/pkg/utils"
minio "github.com/minio/minio-go"
)

const (
localMinioInsecure = true
localMinioHost = "localhost"
localMinioPort = 9000
)

var (
errHealthSrvExited = errors.New("healthcheck server exited with unknown status")
errMinioExited = errors.New("Minio server exited with unknown status")
)

// Secret is a secret for the remote object storage
Expand Down Expand Up @@ -67,7 +82,7 @@ const templv2 = `{
}
}`

func run(cmd string) {
func run(cmd string) error {
var cmdBuf bytes.Buffer
tmpl := template.Must(template.New("cmd").Parse(cmd))
if err := tmpl.Execute(&cmdBuf, nil); err != nil {
Expand All @@ -78,10 +93,9 @@ func run(cmd string) {
var cmdl *exec.Cmd
cmdl = exec.Command("sh", "-c", cmdString)
if _, _, err := utils.RunCommandWithStdoutStderr(cmdl); err != nil {
log.Fatal(err)
} else {
fmt.Println("ok")
return err
}
return nil
}

func readSecrets() (string, string) {
Expand All @@ -92,10 +106,26 @@ func readSecrets() (string, string) {
return strings.TrimSpace(string(keyID)), strings.TrimSpace(string(accessKey))
}

func newMinioClient(host string, port int, accessKey, accessSecret string, insecure bool) (minio.CloudStorageClient, error) {
return minio.New(
fmt.Sprintf("%s:%d", host, port),
accessKey,
accessSecret,
insecure,
)
}

func main() {
pod, err := aboutme.FromEnv()
checkError(err)
key, access := readSecrets()

minioClient, err := newMinioClient(localMinioHost, localMinioPort, key, access, localMinioInsecure)
if err != nil {
log.Printf("Error creating minio client (%s)", err)
os.Exit(1)
}

secrets := []Secret{
{
Host: pod.IP,
Expand All @@ -104,18 +134,54 @@ func main() {
},
}
t := template.New("MinioTpl")

t, err = t.Parse(templv2)

checkError(err)

err = os.MkdirAll(configdir, 0755)
checkError(err)
output, err := os.Create(configdir + "config.json")
err = t.Execute(output, secrets)
checkError(err)
os.Args[0] = "minio"
mc := strings.Join(os.Args, " ")
run(mc)
runErrCh := make(chan error)
log.Printf("starting Minio server")
go func() {
if err := run(mc); err != nil {
runErrCh <- err
} else {
runErrCh <- errMinioExited
}
}()

healthSrvHost := os.Getenv("HEALTH_SERVER_HOST")
if healthSrvHost == "" {
healthSrvHost = healthsrv.DefaultHost
}
healthSrvPort, err := strconv.Atoi(os.Getenv("HEALTH_SERVER_PORT"))
if err != nil {
healthSrvPort = healthsrv.DefaultPort
}

log.Printf("starting health check server on %s:%d", healthSrvHost, healthSrvPort)

healthSrvErrCh := make(chan error)
go func() {
if err := healthsrv.Start(healthSrvHost, healthSrvPort, minioClient); err != nil {
healthSrvErrCh <- err
} else {
healthSrvErrCh <- errHealthSrvExited
}
}()

select {
case err := <-runErrCh:
log.Printf("Minio server error (%s)", err)
os.Exit(1)
case err := <-healthSrvErrCh:
log.Printf("Healthcheck server error (%s)", err)
os.Exit(1)
}
}

func checkError(err error) {
Expand Down
15 changes: 15 additions & 0 deletions boot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"testing"
)

func TestNewMinioClient(t *testing.T) {
client, err := newMinioClient("localhost", 8095, "access_key", "access_secret_key", false)
if err != nil {
t.Fatalf("unexpected error creating minio client (%s)", err)
}
if client == nil {
t.Fatalf("returned client was nil but not expected to be")
}
}
Loading