Skip to content

Commit

Permalink
support running tests as non-root
Browse files Browse the repository at this point in the history
also, just go down to latest released buildkit instead of building from
master, since building it is too complicated to do in a task (requires
docker) and the reason for needing it is kind of questionable in the
first place

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
  • Loading branch information
vito committed Aug 22, 2019
1 parent 54afb69 commit 75df8d5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,6 @@ scripts/.tests
bin/buildctl
bin/buildkitd
bin/buildkit-runc
bin/rootlessctl
bin/rootlesskit
bin/rootlesskit-docker-proxy
6 changes: 3 additions & 3 deletions .gitmodules
@@ -1,3 +1,3 @@
[submodule "buildkit"]
path = buildkit
url = https://github.com/moby/buildkit
[submodule "rootlesskit"]
path = rootlesskit
url = https://github.com/rootless-containers/rootlesskit
1 change: 0 additions & 1 deletion buildkit
Submodule buildkit deleted from 763379
1 change: 1 addition & 0 deletions rootlesskit
Submodule rootlesskit added at 93164c
37 changes: 21 additions & 16 deletions scripts/test
@@ -1,24 +1,29 @@
#!/bin/bash

set -e -u -x
set -e -u

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 -
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 -fL "$BUILDKIT_URL" | tar zxf -
fi

if [ "$(id -u)" != "0" ]; then
if ! which newuidmap >/dev/null || ! which newgidmap >/dev/null; then
echo "newuidmap and newgidmap must be installed"
exit 1
fi

if ! [ -e bin/rootlesskit ]; then
pushd rootlesskit
make
popd

cp rootlesskit/bin/* bin/
fi
fi

go test -c -o scripts/.tests
sudo scripts/.tests "$@"
go test "$@"
12 changes: 7 additions & 5 deletions task.go
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/concourse/go-archive/tarfs"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/layout"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -78,7 +77,7 @@ func Build(rootPath string, req Request) (Response, error) {
if _, err := os.Stat(imageDir); err == nil {
ociImagePath = filepath.Join(imageDir, "image.tar")
buildctlArgs = append(buildctlArgs,
"--output", "type=oci,name="+cfg.ImageName()+",dest="+ociImagePath,
"--output", "type=oci,dest="+ociImagePath,
)
}

Expand Down Expand Up @@ -153,9 +152,12 @@ func unpackRootfs(dest string, ociImagePath string, cfg Config) error {
}
}

if m.Annotations != nil && m.Annotations[ocispec.AnnotationRefName] != cfg.Tag {
continue
}
// TODO: is this even a sensible approach?
//
// note: depends on newer buildkit with support for named oci output
// if m.Annotations != nil && m.Annotations[ocispec.AnnotationRefName] != cfg.Tag {
// continue
// }

if unpacked != "" {
logrus.WithFields(logrus.Fields{
Expand Down

0 comments on commit 75df8d5

Please sign in to comment.