-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test script to execute ghwc in docker+snapshot
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
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |