Skip to content

Commit

Permalink
add test script to execute ghwc in docker+snapshot
Browse files Browse the repository at this point in the history
Adds a test script (hack/run-against-snapshot.sh) that builds the ghwc
binary into a Docker image, extracts a snapshot created by ghwc-snapshot
into a tmpdir, and runs the ghwc Docker image after bind-mounting the
snapshot tmpdir as /host.

This allows us to test ghw against a snapshot static filesystem from a
user's machine (Linux only for now)

Issue #66
  • Loading branch information
jaypipes committed Feb 2, 2020
1 parent 678ce64 commit d5fce6c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.13-stretch as builder
WORKDIR /go/src/github.com/jaypipes/ghw

# Force the go compiler to use modules.
ENV GO111MODULE=on
ENV GOPROXY=direct

# go.mod and go.sum go into their own layers.
COPY go.mod .
COPY go.sum .

# This ensures `go mod download` happens only when go.mod and go.sum change.
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build -o ghwc ./cmd/ghwc/

FROM alpine:3.7
RUN apk add --no-cache ethtool

WORKDIR /bin

COPY --from=builder /go/src/github.com/jaypipes/ghw/ghwc /bin

CMD ghwc
1 change: 1 addition & 0 deletions cmd/ghw-snapshot/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +build linux
//
// Use and distribution licensed under the Apache license version 2.
//
Expand Down
26 changes: 26 additions & 0 deletions hack/run-against-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

SNAPSHOT_FILEPATH=${SNAPSHOT_FILEPATH:-$1}

if [[ ! -f $SNAPSHOT_FILEPATH ]]; then
echo "Cannot find snapshot file. Please call $0 with path to snapshot or set SNAPSHOT_FILEPATH envvar."
exit 1
fi

root_dir=$(cd "$(dirname "$0").."; pwd)
ghwc_image_name="ghwc"
local_git_version=$(git describe --tags --always --dirty)
IMAGE_VERSION=${IMAGE_VERSION:-$local_git_version}

snap_tmp_dir=$(mktemp -d -t ghw-snap-test-XXX)

echo "extracting snapshot $SNAPSHOT_FILEPATH to $snap_tmp_dir ..."
tar -xf $SNAPSHOT_FILEPATH -C $snap_tmp_dir

echo "building Docker image with ghwc ..."

docker build -f $root_dir/Dockerfile -t $ghwc_image_name:$IMAGE_VERSION $root_dir

echo "running ghwc Docker image with volume mount to snapshot dir ..."

docker run -it -v $snap_tmp_dir:/host -e GHW_CHROOT="/host" $ghwc_image_name:$IMAGE_VERSION

0 comments on commit d5fce6c

Please sign in to comment.