Skip to content

Commit

Permalink
Log aws.firecracker's version since supporting -version is hard
Browse files Browse the repository at this point in the history
Because the shim's flag parsing is owned by containerd's shim package,
supporting -version/-v is not straightforward. Instead the binary logs
the version.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed Jan 9, 2020
1 parent 6bef84d commit f0ec5f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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
6 changes: 6 additions & 0 deletions runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func NewService(shimCtx context.Context, id string, remotePublisher shim.Publish
return nil, err
}

// The shim cannot support -version flag since
// - flag.Parse() is called by shim.Run(). So our main() cannot call flag.Parse()
// - NewService() won't be called when the TTRPC address is not specified by the flags
// Instead we log the version informaion
s.logger.Infof("successfully started %s (%s) for VM %s", shimID, revision, vmID)

return s, nil
}

Expand Down

0 comments on commit f0ec5f6

Please sign in to comment.