Skip to content

Commit

Permalink
ci: memory-tested image vish/stress is single-arch image for amd64
Browse files Browse the repository at this point in the history
since vish/stress is a single-arch image for amd64, we need to provide
aarch64-specific image, including Dockefile from which the image was built,
source code of lightweight memory stress utility(stress/main.go), etc.

Fixes: kata-containers#567

Signed-off-by: Penny Zheng <[email protected]>
  • Loading branch information
Pennyzct committed Sep 5, 2018
1 parent b6c700d commit 4a57af1
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion integration/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const (

// StressImage is the vish/stress image
StressImage = "vish/stress"

// StressDockerFile is the dockerfile to build vish/stress image
StressDockerFile = "src/github.com/kata-containers/tests/stress/."
)

// cidDirectory is the directory where container ID files are created.
Expand Down Expand Up @@ -424,7 +427,8 @@ func dockerDiff(args ...string) (string, string, int) {

// dockerBuild builds an image from a Dockerfile
func dockerBuild(args ...string) (string, string, int) {
return runDockerCommand("build", args...)
// 10 minutes should be enough to build a image
return runDockerCommandWithTimeout(600, "build", args...)
}

// dockerExport will export a container’s filesystem as a tar archive
Expand Down
28 changes: 25 additions & 3 deletions integration/docker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package docker

import (
"os"
"path/filepath"
"runtime"
"testing"

. "github.com/kata-containers/tests"
Expand Down Expand Up @@ -34,9 +37,28 @@ func TestIntegration(t *testing.T) {
}

for _, i := range images {
_, _, exitCode := dockerPull(i)
if exitCode != 0 {
t.Fatalf("failed to pull docker image: %s\n", i)
// vish/stress is single-arch image only for amd64
if i == StressImage && runtime.GOARCH == "arm64" {
//check if vish/stress has already been built
argsImage := []string{"--format", "'{{.Repository}}:{{.Tag}}'", StressImage}
imagesStdout, _, imagesExitcode := dockerImages(argsImage...)
if imagesExitcode != 0 {
t.Fatalf("failed to docker images --format '{{.Repository}}:{{.Tag}}' %s\n", StressImage)
}
if imagesStdout == "" {
gopath := os.Getenv("GOPATH")
entirePath := filepath.Join(gopath, StressDockerFile)
argsBuild := []string{"-t", StressImage, entirePath}
_, _, buildExitCode := dockerBuild(argsBuild...)
if buildExitCode != 0 {
t.Fatalf("failed to build stress image in %s\n", runtime.GOARCH)
}
}
} else {
_, _, exitCode := dockerPull(i)
if exitCode != 0 {
t.Fatalf("failed to pull docker image: %s\n", i)
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions stress/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2018 ARM Limited
#
# SPDX-License-Identifier: Apache-2.0

FROM golang:1.10.3-alpine3.8

MAINTAINER [email protected]

ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin

RUN apk add --no-cache musl-dev git gcc
RUN go get -u github.com/golang/dep/cmd/dep

RUN mkdir -p $GOPATH/src/stress/
WORKDIR $GOPATH/src/stress
RUN dep init
ADD main.go .
RUN dep ensure
RUN go build -o stress . && go install

ENTRYPOINT ["stress"]
35 changes: 35 additions & 0 deletions stress/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright (c) 2018 ARM Limited
//
// SPDX-License-Identifier: Apache-2.0

package main

import (
"flag"

"code.cloudfoundry.org/bytefmt"
)

var (
argMemTotal = flag.String("mem-total", "0", "total memory to be consumed. Memory will be consumed via multiple allocations.")
argMemStepSize = flag.String("mem-alloc-size", "4K", "amount of memory to be consumed in each allocation")
buffer [][]byte
)

func main() {
flag.Parse()
total, _ := bytefmt.ToBytes(*argMemTotal)
stepSize, _ := bytefmt.ToBytes(*argMemStepSize)
allocateMemory(total, stepSize)
}

func allocateMemory(total, stepSize uint64) {
for i := uint64(1); i*stepSize <= total; i++ {
newBuffer := make([]byte, stepSize)
for i := range newBuffer {
newBuffer[i] = 0
}
buffer = append(buffer, newBuffer)
}
}
201 changes: 201 additions & 0 deletions vendor/code.cloudfoundry.org/bytefmt/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/code.cloudfoundry.org/bytefmt/NOTICE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a57af1

Please sign in to comment.