Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tests run as root, directly on the host * can't really find a good way around this * at one point i had the tests build + run the task with the docker CLI, with some ugly volume mount shenanigans, but assertions need to be made against the outputs, and they're owned by root in this case anyway * changed setup-cgroups to just no-op if /sys/fs/cgroup already exists so it doesn't mess around with the host * main entrypoint is scripts/test * builds tests using go test -c and runs them with sudo * builds latest buildkit from master via the submodule * this submodule can be removed in favor of using a released archive once a new version is out which supports named oci outputs * fixed a few bugs that the tests found along the way! * manifest.json -> metadata.json (d'oh) * XDG_RUNTIME_PATH -> XDG_RUNTIME_DIR (d'oh) * build args flag was completely wrong (d'oh) * build args file choked on trailing linebreak Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
- Loading branch information
Showing
15 changed files
with
235 additions
and
25 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,5 @@ | ||
# created by scripts/test | ||
scripts/.tests | ||
bin/buildctl | ||
bin/buildkitd | ||
bin/buildkit-runc |
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,3 @@ | ||
[submodule "buildkit"] | ||
path = buildkit | ||
url = https://github.com/moby/buildkit |
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
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
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
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
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,138 @@ | ||
package task_test | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
task "github.com/concourse/builder-task" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type TaskSuite struct { | ||
suite.Suite | ||
|
||
rootDir string | ||
req task.Request | ||
} | ||
|
||
func (s *TaskSuite) SetupSuite() { | ||
binDir, err := filepath.Abs("bin") | ||
s.NoError(err) | ||
|
||
// inject setup-cgroups and other utilities into the $PATH | ||
// | ||
// this is also a good place to install buildkitd/buildctl | ||
err = os.Setenv("PATH", binDir+":"+os.Getenv("PATH")) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) SetupTest() { | ||
var err error | ||
s.rootDir, err = ioutil.TempDir("", "builder-task-test") | ||
s.NoError(err) | ||
|
||
s.req = task.Request{ | ||
ResponsePath: filepath.Join(s.rootDir, "response.json"), | ||
Config: task.Config{ | ||
Repository: "builder-task-test", | ||
}, | ||
} | ||
} | ||
|
||
func (s *TaskSuite) TearDownTest() { | ||
err := os.RemoveAll(s.rootDir) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) TestMissingRepositoryValidation() { | ||
s.req.Config.Repository = "" | ||
|
||
_, err := task.Build(s.rootDir, s.req) | ||
s.EqualError(err, "config: repository must be specified") | ||
} | ||
|
||
func (s *TaskSuite) TestBasicBuild() { | ||
s.req.Config.ContextPath = "testdata/basic" | ||
|
||
_, err := task.Build(s.rootDir, s.req) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) TestBuildArgs() { | ||
s.req.Config.ContextPath = "testdata/build-args" | ||
s.req.Config.BuildArgs = []string{ | ||
"some_arg=some_value", | ||
"some_other_arg=some_other_value", | ||
} | ||
|
||
// the Dockerfile itself asserts that the arg has been received | ||
_, err := task.Build(s.rootDir, s.req) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) TestBuildArgsFile() { | ||
s.req.Config.ContextPath = "testdata/build-args" | ||
s.req.Config.BuildArgsFile = "testdata/build-args/build_args_file" | ||
|
||
// the Dockerfile itself asserts that the arg has been received | ||
_, err := task.Build(s.rootDir, s.req) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) TestBuildArgsStaticAndFile() { | ||
s.req.Config.ContextPath = "testdata/build-args" | ||
s.req.Config.BuildArgs = []string{"some_arg=some_value"} | ||
s.req.Config.BuildArgsFile = "testdata/build-args/build_arg_file" | ||
|
||
// the Dockerfile itself asserts that the arg has been received | ||
_, err := task.Build(s.rootDir, s.req) | ||
s.NoError(err) | ||
} | ||
|
||
func (s *TaskSuite) TestUnpackRootfs() { | ||
s.req.Config.ContextPath = "testdata/unpack-rootfs" | ||
s.req.Config.UnpackRootfs = true | ||
|
||
_, err := task.Build(s.rootDir, s.req) | ||
s.NoError(err) | ||
|
||
meta, err := s.imageMetadata() | ||
s.NoError(err) | ||
|
||
rootfsContent, err := ioutil.ReadFile(s.imagePath("rootfs", "Dockerfile")) | ||
s.NoError(err) | ||
|
||
expectedContent, err := ioutil.ReadFile("testdata/unpack-rootfs/Dockerfile") | ||
s.NoError(err) | ||
|
||
s.Equal(rootfsContent, expectedContent) | ||
|
||
s.Equal(meta.User, "banana") | ||
s.Equal(meta.Env, []string{"PATH=/darkness", "BA=nana"}) | ||
} | ||
|
||
func (s *TaskSuite) imagePath(path ...string) string { | ||
return filepath.Join(append([]string{s.rootDir, "image"}, path...)...) | ||
} | ||
|
||
func (s *TaskSuite) imageMetadata() (task.ImageMetadata, error) { | ||
metadataPayload, err := ioutil.ReadFile(s.imagePath("metadata.json")) | ||
if err != nil { | ||
return task.ImageMetadata{}, err | ||
} | ||
|
||
var meta task.ImageMetadata | ||
err = json.Unmarshal(metadataPayload, &meta) | ||
if err != nil { | ||
return task.ImageMetadata{}, err | ||
} | ||
|
||
return meta, nil | ||
} | ||
|
||
func TestSuite(t *testing.T) { | ||
suite.Run(t, &TaskSuite{}) | ||
} |
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,24 @@ | ||
#!/bin/bash | ||
|
||
set -e -u -x | ||
|
||
cd $(dirname $0)/.. | ||
|
||
if ! [ -e bin/buildctl ] || ! [ -e bin/buildkitd ]; then | ||
dest=$(pwd) | ||
pushd buildkit | ||
make | ||
make DESTDIR=$dest install | ||
popd | ||
|
||
# once a new version of buildkit is out, remove the submodule and do the | ||
# following instead | ||
# | ||
# BUILDKIT_VERSION=0.6.1 | ||
# BUILDKIT_URL=https://github.com/moby/buildkit/releases/download/v$BUILDKIT_VERSION/buildkit-v$BUILDKIT_VERSION.linux-amd64.tar.gz | ||
|
||
# curl -fsSL "$BUILDKIT_URL" | tar zxf - | ||
fi | ||
|
||
go test -c -o scripts/.tests | ||
sudo scripts/.tests "$@" |
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
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 @@ | ||
FROM scratch |
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,5 @@ | ||
FROM busybox | ||
ARG some_arg | ||
ARG some_other_arg | ||
RUN test "$some_arg" = "some_value" | ||
RUN test "$some_other_arg" = "some_other_value" |
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 @@ | ||
some_other_arg=some_other_value |
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,2 @@ | ||
some_arg=some_value | ||
some_other_arg=some_other_value |
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,5 @@ | ||
FROM scratch | ||
USER banana | ||
ADD Dockerfile /Dockerfile | ||
ENV PATH=/darkness | ||
ENV BA=nana |