Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

(FEAT) Run Lumogon on ARM (Raspberry Pi) [WIP] #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -4,6 +4,8 @@ endif

PACKAGE_NAME = github.com/puppetlabs/lumogon

DOCKER_IMAGE_NAME ?= puppet/lumogon

LDFLAGS += -X "$(PACKAGE_NAME)/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "$(PACKAGE_NAME)/version.BuildVersion=development"
LDFLAGS += -X "$(PACKAGE_NAME)/version.BuildSHA=$(shell git rev-parse HEAD)"
Expand All @@ -27,7 +29,7 @@ dependencies: bootstrap
glide install

test: lint vet
go test -v -cover `glide novendor` -ldflags '$(TESTLDFLAGS)'
GOOS= GOARCH= go test -v -cover `glide novendor` -ldflags '$(TESTLDFLAGS)'

watch: bootstrap
goconvey
Expand All @@ -37,7 +39,7 @@ build: bootstrap
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o bin/lumogon lumogon.go

image: bootstrap
docker build -t puppet/lumogon -f ./Dockerfile.build .
docker build -t $(DOCKER_IMAGE_NAME) -f ./Dockerfile.build .

todo:
grep -rnw "TODO" .
Expand All @@ -46,7 +48,7 @@ lint: bootstrap $(GOPATH)/src/github.com/golang/lint/golint
golint `glide novendor`

vet: bootstrap
go vet `glide novendor`
GOOS= GOARCH= go vet `glide novendor`

licenses: $(GOPATH)/bin/licenses
@licenses $(PACKAGE_NAME) | grep $(PACKAGE_NAME)/vendor
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ make all

Note that this build process isn't widely tested away from macOS yet but will eventually work everywhere.

### Building for ARM (Raspberry Pi)

You can build a Lumogon container that will run on ARM based platforms (tested on the Raspberry Pi) as follows:
```
GOARCH=arm GOOS=linux DOCKER_IMAGE_NAME=yourname/lumogon-arm make all
```

## Giving us feedback

We'd love to hear from you. We have a [Slack channel](https://puppetcommunity.slack.com/messages/C5CT7GMKQ) for talking about Lumogon and please do open issues against [the repository](https://github.com/puppetlabs/lumogon/issues).
2 changes: 1 addition & 1 deletion capabilities/ospackages/dpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var dpkgCapability = dockeradapter.DockerAPICapability{
Description: dpkgDescription,
Type: "dockerapi",
Payload: nil,
SupportedOS: map[string]int{"ubuntu": 1, "debian": 1},
SupportedOS: map[string]int{"ubuntu": 1, "debian": 1, "raspbian": 1},
},
Harvest: func(capability *dockeradapter.DockerAPICapability, client dockeradapter.Harvester, id string, target types.TargetContainer) {
logging.Stderr("[Dpkg] Harvesting packages from target %s [%s], harvester id: %s", target.Name, target.ID, id)
Expand Down
29 changes: 29 additions & 0 deletions dockeradapter/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dockeradapter

import (
"context"
"regexp"

"github.com/puppetlabs/lumogon/logging"
"github.com/puppetlabs/lumogon/utils"
)

// LocalImageID returns the imageID sha256 hex for the local container
func LocalImageID(ctx context.Context, client Inspector) (*string, error) {
localContainerID, err := utils.GetLocalContainerID("/proc/self/cgroup")
if err != nil {
logging.Stderr("[LocalImageID] unable to determine local ContainerID: %v", err)
return nil, err
}
var imageIDRegex = regexp.MustCompile(`^sha256:([a-z0-9]+)`)

json, err := client.ContainerInspect(ctx, localContainerID)
if err != nil {
logging.Stderr("[LocalImageID] error inspecting local container [ID: %s]: %v", localContainerID)
return nil, err
}

imageID := imageIDRegex.FindStringSubmatch(json.Image)[1]
logging.Stderr("[LocalImageID] found local imageID: %s", imageID)
return &imageID, nil
}
9 changes: 5 additions & 4 deletions harvester/attached.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// channel, when a result is received it will attempt to remove that associated
// attached container which performed the harvest before sending the result to the
// collector via the main results channel, resultsCh.
func RunAttachedHarvester(ctx context.Context, wg *sync.WaitGroup, targets []*types.TargetContainer, capabilities []types.AttachedCapability, resultsCh chan types.ContainerReport, opts types.ClientOptions, client dockeradapter.Client) error {
func RunAttachedHarvester(ctx context.Context, wg *sync.WaitGroup, targets []*types.TargetContainer, capabilities []types.AttachedCapability, resultsCh chan types.ContainerReport, opts types.ClientOptions, client dockeradapter.Client, imageID *string) error {
defer logging.Stderr("[Attached Harvester] Exiting")
defer wg.Done()
logging.Stderr("[Attached Harvester] Running")
Expand Down Expand Up @@ -56,7 +56,7 @@ func RunAttachedHarvester(ctx context.Context, wg *sync.WaitGroup, targets []*ty

logging.Stderr("[Attached Harvester] Creating [%d] harvesting containers", len(validTargets))
for _, target := range validTargets {
go createAndRunHarvester(ctx, client, *target, opts, rpcReceiverResultsCh)
go createAndRunHarvester(ctx, client, *target, opts, rpcReceiverResultsCh, imageID)
}

doneChannel := make(chan int)
Expand Down Expand Up @@ -85,11 +85,12 @@ func RunAttachedHarvester(ctx context.Context, wg *sync.WaitGroup, targets []*ty
// createAndRunHarvester creates and runs a container attached to the namespace of the target
// container which will run the harvest command to run the harvest functions from any registered
// AttachedCapabilities.
func createAndRunHarvester(ctx context.Context, client dockeradapter.Client, target types.TargetContainer, opts types.ClientOptions, rpcReceiverResultsCh chan types.ContainerReport) {
func createAndRunHarvester(ctx context.Context, client dockeradapter.Client, target types.TargetContainer, opts types.ClientOptions, rpcReceiverResultsCh chan types.ContainerReport, imageID *string) {
logging.Stderr("[Attached Harvester] Creating attached container for target %s", target)
harvester := NewAttachedContainer(client, types.ClientOptions{KeepHarvesters: opts.KeepHarvesters})
// TODO get image name from the current container or set alternate default for non-container use
harvester.GetImage("puppet/lumogon")
// harvester.GetImage("puppet/lumogon")
harvester.imageName = *imageID
harvester.Attach(target)
harvester.Run()
}
8 changes: 7 additions & 1 deletion scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (s *Scheduler) Run(r registry.IRegistry) {
defer cancel()
resultsChannel := make(chan types.ContainerReport)

schedulerImageID, err := dockeradapter.LocalImageID(ctx, s.client)
if err != nil {
logging.Stderr("[Scheduler] unable to determine local containerID [%v]", err)
os.Exit(1)
}

targets, err := dockeradapter.NormaliseTargets(ctx, s.args, s.client)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to normalise target containers: %s.\nExiting...", err)
Expand All @@ -86,7 +92,7 @@ func (s *Scheduler) Run(r registry.IRegistry) {
go collector.RunCollector(ctx, &wg, expectedResultCount, resultsChannel, storageBackend)

wg.Add(1)
go harvester.RunAttachedHarvester(ctx, &wg, s.targets, r.AttachedCapabilities(), resultsChannel, *s.opts, s.client)
go harvester.RunAttachedHarvester(ctx, &wg, s.targets, r.AttachedCapabilities(), resultsChannel, *s.opts, s.client, schedulerImageID)

wg.Add(1)
go harvester.RunDockerAPIHarvester(ctx, &wg, s.targets, r.DockerAPICapabilities(), resultsChannel, s.client)
Expand Down