Skip to content

Commit ac3477f

Browse files
authored
fix(docker): set entrypoint to slice{""} (#307)
1 parent 4fd65b2 commit ac3477f

File tree

4 files changed

+76
-32
lines changed

4 files changed

+76
-32
lines changed

.github/workflows/integration-tests.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,31 @@ permissions: read-all
88
concurrency:
99
group: build-${{ github.event.pull_request.number || github.ref }}-${{github.workflow}}
1010
cancel-in-progress: true
11-
jobs:
1211

12+
jobs:
1313
build:
1414
name: PR unit tests
15-
runs-on: macos-latest
15+
strategy:
16+
matrix:
17+
os: [ubuntu-latest, macos-latest]
18+
runs-on: ${{ matrix.os }}
19+
1620
steps:
17-
21+
- name: install podman
22+
if: ${{ matrix.os == 'macos-latest' }}
23+
run: |
24+
brew install podman
25+
podman machine init
26+
podman machine start
27+
echo "DOCKER_HOST=unix:///Users/runner/.local/share/containers/podman/machine/podman-machine-default/podman.sock" >> $GITHUB_ENV
28+
1829
- name: Set up Go
1930
uses: actions/setup-go@v2
2031
with:
2132
go-version: ^1.17
2233
id: go
34+
35+
- uses: imjasonh/[email protected]
2336

2437
- name: Check out code into the Go module directory
2538
uses: actions/checkout@v2

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ORG := github.com/GoogleContainerTools
2626
PROJECT := container-structure-test
2727
REPOPATH ?= $(ORG)/$(PROJECT)
2828
RELEASE_BUCKET ?= $(PROJECT)
29+
DOCKER ?=docker
2930

3031
VERSION_PACKAGE := $(REPOPATH)/pkg/version
3132

@@ -81,4 +82,4 @@ test: $(BUILD_DIR)/$(PROJECT)
8182
./tests/structure_test_tests.sh
8283

8384
image:
84-
docker build -t gcr.io/gcp-runtimes/container-structure-test:latest .
85+
$(DOCKER) build -t gcr.io/gcp-runtimes/container-structure-test:latest .

pkg/drivers/docker_driver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (d *DockerDriver) SetEnv(envVars []unversioned.EnvVar) error {
8484
Image: d.currentImage,
8585
Env: env,
8686
Cmd: []string{utils.NoopCommand},
87-
Entrypoint: []string{},
87+
Entrypoint: []string{""},
8888
AttachStdout: true,
8989
AttachStderr: true,
9090
},
@@ -302,7 +302,7 @@ func (d *DockerDriver) runAndCommit(env []string, command []string) (string, err
302302
Image: d.currentImage,
303303
Env: env,
304304
Cmd: command,
305-
Entrypoint: []string{},
305+
Entrypoint: []string{""},
306306
AttachStdout: true,
307307
AttachStderr: true,
308308
},
@@ -348,7 +348,7 @@ func (d *DockerDriver) exec(env []string, command []string) (string, string, int
348348
Image: d.currentImage,
349349
Env: env,
350350
Cmd: command,
351-
Entrypoint: []string{},
351+
Entrypoint: []string{""},
352352
AttachStdout: true,
353353
AttachStderr: true,
354354
},

tests/structure_test_tests.sh

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,49 @@ test_config_dir="${test_dir}/${go_architecture}"
3131
# If a configuration folder for the architecture doesn't exist, default to amd64
3232
test -d ${test_config_dir} || test_config_dir="${test_dir}/amd64"
3333

34-
echo "##"
35-
echo "# Build the newest 'container structure test' binary"
36-
echo "##"
34+
35+
function HEADER() {
36+
local msg="$1"
37+
echo ""
38+
echo "###############"
39+
echo "# $msg"
40+
echo "###############"
41+
echo ""
42+
}
43+
44+
HEADER "Determine the runtime"
45+
46+
DOCKER=""
47+
if which docker > /dev/null; then
48+
DOCKER=$(which docker)
49+
echo "Using docker at $(which docker)"
50+
elif which podman > /dev/null; then
51+
DOCKER=$(which podman)
52+
echo "Using podman at $(which podman)"
53+
else
54+
echo "Could not find a runtime to run tests"
55+
exit 1
56+
fi
57+
58+
docker() {
59+
$DOCKER $@
60+
}
61+
62+
63+
HEADER "Build the newest 'container structure test' binary"
64+
3765
cp -f "${test_dir}/Dockerfile" "${test_dir}/../Dockerfile"
38-
make
39-
make cross
40-
make image
66+
make DOCKER=$DOCKER
67+
make DOCKER=$DOCKER cross
68+
make DOCKER=$DOCKER image
4169

4270
# Run the ubuntu tests, they should always pass on 20.04
4371
test_image="ubuntu:20.04"
4472
docker pull "$test_image" > /dev/null
4573

46-
echo "##"
47-
echo "# Positive Test Case"
48-
echo "##"
74+
75+
HEADER "Positive Test Case"
76+
4977
res=$(./out/container-structure-test test --image "$test_image" --config "${test_config_dir}/ubuntu_20_04_test.yaml")
5078
code=$?
5179
if ! [[ ("$res" =~ "PASS" && "$code" == "0") ]];
@@ -57,14 +85,13 @@ else
5785
echo "PASS: Success test case passed"
5886
fi
5987

60-
echo "##"
61-
echo "# Metadata Test Case"
62-
echo "##"
88+
89+
HEADER "Metadata Test Case"
6390
# test image metadata
6491
run_metadata_tests=true
6592
if $run_metadata_tests ;
6693
then
67-
test_metadata_image=debian8-with-metadata:latest
94+
test_metadata_image=test.local/debian8-with-metadata:latest
6895
test_metadata_tar=debian8-with-metadata.tar
6996
test_metadata_dir=debian8-with-metadata
7097
docker build -q -f "$test_dir"/Dockerfile.metadata --tag "$test_metadata_image" "$test_dir" > /dev/null
@@ -93,8 +120,8 @@ then
93120
fi
94121

95122
mkdir -p "$test_metadata_dir"
96-
tar -C "$test_metadata_dir" -xvf "$test_metadata_tar" > /dev/null
97-
test_metadata_json=$(grep 'Config":"\K[^"]+' -Po "$test_metadata_dir/manifest.json")
123+
tar -C "$test_metadata_dir" -xf "$test_metadata_tar" > /dev/null
124+
test_metadata_json=$(jq -r '.[0].Config' "$test_metadata_dir/manifest.json")
98125
res=$(./out/container-structure-test test --driver host --force --metadata "$test_metadata_dir/$test_metadata_json" --config "${test_config_dir}/ubuntu_20_04_metadata_test.yaml")
99126
code=$?
100127
if ! [[ ("$res" =~ "PASS" && "$code" == "0") ]];
@@ -111,9 +138,9 @@ then
111138
docker rmi "$test_metadata_image" > /dev/null
112139
fi
113140

114-
echo "##"
115-
echo "# Failure Test Case"
116-
echo "##"
141+
142+
HEADER "Failure Test Case"
143+
117144
# Run some bogus tests, they should fail as expected
118145
res=$(./out/container-structure-test test --image "$test_image" --config "${test_config_dir}/ubuntu_20_04_failure_test.yaml")
119146
code=$?
@@ -127,15 +154,13 @@ else
127154
fi
128155

129156

130-
echo "###"
131-
echo "# OCI layout test case"
132-
echo "###"
133157

134-
go install github.com/google/go-containerregistry/cmd/crane/cmd
135-
tmp="$(mktemp -d)"
158+
HEADER "OCI layout test case"
136159

160+
go install github.com/google/go-containerregistry/cmd/crane
161+
tmp="$(mktemp -d)"
137162

138-
crane pull "$test_image" --format=oci "$tmp" --platform=linux/${go_architecture}
163+
crane pull "$test_image" --format=oci "$tmp" --platform="linux/$go_architecture"
139164

140165

141166
res=$(./out/container-structure-test test --image-from-oci-layout="$tmp" --config "${test_config_dir}/ubuntu_20_04_test.yaml" 2>&1)
@@ -150,7 +175,7 @@ else
150175
echo "PASS: oci failing test case"
151176
fi
152177

153-
res=$(./out/container-structure-test test --image-from-oci-layout="$tmp" --default-image-tag="test.local/library/$test_image" --config "${test_config_dir}/ubuntu_20_04_test.yaml" 2>&1)
178+
res=$(./out/container-structure-test test --image-from-oci-layout="$tmp" --default-image-tag="test.local/$test_image" --config "${test_config_dir}/ubuntu_20_04_test.yaml" 2>&1)
154179
code=$?
155180
if ! [[ ("$res" =~ "PASS" && "$code" == "0") ]];
156181
then
@@ -161,3 +186,8 @@ then
161186
else
162187
echo "PASS: oci success test case"
163188
fi
189+
190+
if [ $failures -gt 0 ]; then
191+
echo "Some tests did not pass. $failures"
192+
exit 1
193+
fi

0 commit comments

Comments
 (0)