api: Add flags to configure address and image asset path

This commit is contained in:
Dalton Hubble
2015-12-13 17:44:39 -08:00
parent 176b763b61
commit f3a804f098
12 changed files with 62 additions and 36 deletions

View File

@@ -2,4 +2,4 @@ FROM alpine:latest
MAINTAINER Dalton Hubble <dalton.hubble@coreos.com>
COPY bin/server /server
EXPOSE 8080
CMD ["./server"]
ENTRYPOINT ["./server"]

1
Godeps/_workspace/src/github.com/coreos/pkg generated vendored Submodule

Submodule Godeps/_workspace/src/github.com/coreos/pkg added at 2c77715c4d

View File

@@ -7,14 +7,8 @@ build:
build-docker:
./docker-build
build-aci:
./acifile
run-docker:
docker run -p 8080:8080 --name=bcs --rm -v $(shell echo $$PWD)/static:/static dghubble/bcs:latest
run-rkt:
rkt --insecure-options=image run --no-overlay bin/bcs-0.0.1-linux-amd64.aci
./docker-run
run-pixiecore:
./scripts/pixiecore

13
acifile
View File

@@ -1,13 +0,0 @@
#!/bin/bash -e
acbuild begin
acbuild set-name dghubble/bcs
acbuild copy bin/server /server
acbuild set-exec /server
acbuild port add www tcp 8080
acbuild label add version 0.0.1
acbuild label add arch amd64
acbuild label add os linux
acbuild annotation add authors "Dalton Hubble <dalton.hubble@coreos.com>"
acbuild write bin/bcs-0.0.1-linux-amd64.aci
acbuild end

View File

@@ -4,15 +4,25 @@ import (
"net/http"
)
// Config configures the api Server.
type Config struct {
// Path to static image assets
ImagePath string
// Adapter which provides BootConfigs
BootAdapter BootAdapter
}
// Server serves iPXE/Pixiecore boot configs and hosts images.
type Server struct {
imagePath string
bootConfigs BootAdapter
}
// NewServer returns a new Server which uses the given BootAdapter.
func NewServer(bootConfigs BootAdapter) *Server {
func NewServer(config *Config) *Server {
return &Server{
bootConfigs: bootConfigs,
imagePath: config.ImagePath,
bootConfigs: config.BootAdapter,
}
}
@@ -21,9 +31,9 @@ func (s *Server) HTTPHandler() http.Handler {
mux := http.NewServeMux()
// iPXE
mux.Handle("/ipxe/", ipxeMux(s.bootConfigs))
// Pixiecore API Server
// Pixiecore
mux.Handle(pixiecorePath, pixiecoreHandler(s.bootConfigs))
// Kernel and Initrd Images
mux.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("static"))))
mux.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(s.imagePath))))
return mux
}

1
build
View File

@@ -3,6 +3,7 @@
# allow builds outside the standard GOPATH via symlink
export GOPATH=${PWD}/Godeps/_workspace
export GOBIN=${PWD}/bin
mkdir -p $GOPATH/src/github.com/coreos
# directory or symlink must be present
[ -d $GOPATH/src/github.com/coreos/coreos-baremetal ] || ln -s ${PWD} $GOPATH/src/github.com/coreos/coreos-baremetal

View File

@@ -3,12 +3,15 @@ package main
import (
"log"
"net/http"
"flag"
"os"
"fmt"
"net/url"
"github.com/coreos/coreos-baremetal/api"
"github.com/coreos/pkg/flagutil"
)
const address = ":8080"
// Example Boot Configs
var CoreOSStable = &api.BootConfig{
@@ -44,14 +47,41 @@ var CoreOSLocalAutoLogin = &api.BootConfig{
}
func main() {
flags := flag.NewFlagSet("bootcfg", flag.ExitOnError)
address := flags.String("address", "127.0.0.1:8080", "HTTP listen address")
imagesPath := flags.String("images-path", "./images", "Path to static image assets")
if err := flags.Parse(os.Args[1:]); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := flagutil.SetFlagsFromEnv(flags, "BOOTCFG"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
// validate arguments
if url, err := url.Parse(*address); err != nil || url.String() == "" {
log.Fatal("A valid HTTP listen address is required")
}
if finfo, err := os.Stat(*imagesPath); err != nil || !finfo.IsDir() {
log.Fatal("A path to an image assets directory is required")
}
// load some boot configs
bootAdapter := api.NewMapBootAdapter()
bootAdapter.AddUUID("8a549bf5-075c-4372-8b0d-ce7844faa48c", CoreOSLocalAutoLogin )
bootAdapter.SetDefault(CoreOSLocal)
// api server
server := api.NewServer(bootAdapter)
log.Printf("Starting boot config server")
err := http.ListenAndServe(address, server.HTTPHandler())
config := &api.Config{
ImagePath: *imagesPath,
BootAdapter: bootAdapter,
}
// API server
server := api.NewServer(config)
log.Printf("Starting boot config server on %s", *address)
err := http.ListenAndServe(*address, server.HTTPHandler())
if err != nil {
log.Fatal("ListenAndServe: ", err)
}

View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
REPO=dghubble/bcs
REPO=dghubble/bootcfg
GIT_SHA=$(git rev-parse HEAD)
docker build -q --rm=true -t $REPO:$GIT_SHA .

View File

@@ -1,7 +1,7 @@
#!/bin/bash -e
REPO=dghubble/bcs
QUAY_REPO=quay.io/dghubble/bcs
REPO=dghubble/bootcfg
QUAY_REPO=quay.io/dghubble/bootcfg
GIT_SHA=$(git rev-parse HEAD)
# quay.io

3
docker-run Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash -e
docker run -p 8080:8080 --name=bootcfg --rm -v $PWD/images:/images dghubble/bootcfg:latest -address=0.0.0.0:8080

2
run
View File

@@ -8,4 +8,4 @@ mkdir -p $GOPATH/src/github.com/coreos
# directory or symlink must be present
[ -d $GOPATH/src/github.com/coreos/coreos-baremetal ] || ln -s ${PWD} $GOPATH/src/github.com/coreos/coreos-baremetal
go run cmd/main.go
go run cmd/main.go "$@"

View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
CONFIG_SERVICE=bcs
CONFIG_SERVICE=bootcfg
CONFIG_SERVICE_IP=$(docker inspect --format {{.NetworkSettings.IPAddress}} ${CONFIG_SERVICE})
CONFIG_SERVICE_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' ${CONFIG_SERVICE})