Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version information for in-VM agent, shim, firecracker-conta… #377

Merged
merged 4 commits into from
Jan 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ GOMOD := $(shell go env GOMOD)
GOSUM := $(GOMOD:.mod=.sum)
SOURCES:=$(shell find . -name '*.go')
DOCKER_IMAGE_TAG?=latest
REVISION := $(shell git rev-parse HEAD)

all: agent

agent: *.go $(GOMOD) $(GOSUM)
ifneq ($(STATIC_AGENT),)
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" $(EXTRAGOARGS) -o agent
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X main.revision=$(REVISION)" $(EXTRAGOARGS) -o agent
else
go build $(EXTRAGOARGS) -o agent
go build $(EXTRAGOARGS) -ldflags "-X main.revision=$(REVISION)" -o agent
endif

test:
Expand Down
22 changes: 20 additions & 2 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -47,20 +48,31 @@ const (
enableSubreaper = 1
)

var (
revision string
)

func main() {
var (
port int
debug bool
port int
debug bool
version bool
)

flag.IntVar(&port, "port", defaultPort, "Vsock port to listen to")
flag.BoolVar(&debug, "debug", false, "Turn on debug mode")
flag.BoolVar(&version, "version", false, "Show the version")
flag.Parse()

if debug {
logrus.SetLevel(logrus.DebugLevel)
}

if version {
showVersion()
return
}

signals := make(chan os.Signal, 32)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, unix.SIGCHLD)

Expand Down Expand Up @@ -155,3 +167,9 @@ func main() {
panic(err)
}
}

func showVersion() {
// Once https://github.com/golang/go/issues/29814 is resolved,
// we can use runtime/debug.BuildInfo instead of calling git(1) from Makefile
fmt.Printf("containerd Firecracker agent (git commit: %s)\n", revision)
}
8 changes: 6 additions & 2 deletions firecracker-control/cmd/containerd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ EXTRAGOARGS:=
SRC := $(shell find . -name '*.go')
GOMOD := $(shell go env GOMOD)
GOSUM := $(GOMOD:.mod=.sum)
REVISION=$(shell git rev-parse HEAD)
VERSION_LDFLAGS="-X github.com/containerd/containerd/version.Revision=$(REVISION)"

all: build

build: firecracker-containerd firecracker-ctr

firecracker-containerd: $(SRC) $(GOMOD) $(GOSUM)
go build $(EXTRAGOARGS) -o firecracker-containerd
go build $(EXTRAGOARGS) \
-ldflags $(VERSION_LDFLAGS) -o firecracker-containerd

firecracker-ctr: $(GOMOD) $(GOSUM)
GOBIN=$(CURDIR) go install -tags=no_cri $(EXTRAGOARGS) github.com/containerd/containerd/cmd/ctr
GOBIN=$(CURDIR) go install -tags=no_cri $(EXTRAGOARGS) \
-ldflags $(VERSION_LDFLAGS) github.com/containerd/containerd/cmd/ctr
mv ctr firecracker-ctr

install: firecracker-containerd firecracker-ctr
Expand Down
4 changes: 3 additions & 1 deletion runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DOCKER_IMAGE_TAG?=latest
GO_CACHE_VOLUME_NAME?=gocache
FIRECRACKER_CONTAINERD_TEST_IMAGE?=localhost/firecracker-containerd-test

REVISION=$(shell git rev-parse HEAD)

INTEG_TEST_SUFFIX := _Isolated
INTEG_TESTNAMES=$(shell docker run --rm \
--network=none \
Expand All @@ -37,7 +39,7 @@ all: runtime
runtime: containerd-shim-aws-firecracker

containerd-shim-aws-firecracker: $(SOURCES) $(GOMOD) $(GOSUM)
go build -o containerd-shim-aws-firecracker $(EXTRAGOARGS)
go build -o containerd-shim-aws-firecracker $(EXTRAGOARGS) -ldflags "-X main.revision=$(REVISION)"

install: containerd-shim-aws-firecracker
install -D -o root -g root -m755 -t $(INSTALLROOT)/bin containerd-shim-aws-firecracker
Expand Down
2 changes: 2 additions & 0 deletions runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

const shimID = "aws.firecracker"

var revision string

func init() {
logrus.SetFormatter(&logrus.TextFormatter{
TimestampFormat: log.RFC3339NanoFixed,
Expand Down
14 changes: 10 additions & 4 deletions runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ func (s *service) StartShim(shimCtx context.Context, containerID, containerdBina
// task is deleted
containerCount = 1
exitAfterAllTasksDeleted = true

log.Info("will start a single-task VM since no VMID has been provided")
} else {
log.WithField("vmID", s.vmID).Info("will start a persistent VM")
}

client, err := ttrpcutil.NewClient(containerdTTRPCAddress)
Expand All @@ -358,6 +354,16 @@ func (s *service) StartShim(shimCtx context.Context, containerID, containerdBina
}
}

// The shim cannot support traditional -version/-v flag because
// - shim.Run() will call flag.Parse(). So our main cannot call flag.Parse() before that.
// - -address is required and NewService() won't be called if the flag is missing.
// So we log the version informaion here instead
str := ""
if exitAfterAllTasksDeleted {
str = " The VM will be torn down after serving a single task."
}
log.WithField("vmID", s.vmID).Infof("successfully started shim (git commit: %s).%s", revision, str)

return fcShim.SocketAddress(shimCtx, s.vmID)
}

Expand Down