Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 62b12b1

Browse files
committed
setup tests
Signed-off-by: CrazyMax <[email protected]>
1 parent ad7cda4 commit 62b12b1

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed

.github/workflows/build.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,118 @@ on:
1616
env:
1717
# FIXME: Use docker/dockerfile when moved to docker org
1818
REPO_SLUG: "crazymax/dockerfile"
19+
CACHE_GHA_SCOPE_IT: "integration-tests"
1920

2021
jobs:
22+
base:
23+
runs-on: ubuntu-latest
24+
steps:
25+
-
26+
name: Checkout
27+
uses: actions/checkout@v2
28+
-
29+
name: Expose GitHub Runtime
30+
uses: crazy-max/ghaction-github-runtime@v1
31+
-
32+
name: Set up QEMU
33+
uses: docker/setup-qemu-action@v1
34+
-
35+
name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v1
37+
with:
38+
buildkitd-flags: --debug
39+
-
40+
name: Build integration base
41+
run: |
42+
./hack/buildkit-it-base
43+
env:
44+
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
45+
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
46+
47+
test:
48+
needs:
49+
- base
50+
runs-on: ubuntu-latest
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
pkg:
55+
- .
56+
channel:
57+
- mainline
58+
- labs
59+
type:
60+
- integration
61+
- dockerfile
62+
include:
63+
- pkg: ./...
64+
skip-integration-tests: 1
65+
type: integration
66+
steps:
67+
-
68+
name: Checkout
69+
uses: actions/checkout@v2
70+
-
71+
name: Expose GitHub Runtime
72+
uses: crazy-max/ghaction-github-runtime@v1
73+
-
74+
name: Set up QEMU
75+
uses: docker/setup-qemu-action@v1
76+
-
77+
name: Set up Docker Buildx
78+
uses: docker/setup-buildx-action@v1
79+
with:
80+
buildkitd-flags: --debug
81+
-
82+
name: Test
83+
run: |
84+
./hack/test ${{ matrix.type }}
85+
mv ./coverage/coverage.txt ./coverage/coverage-${{ github.job }}-$(echo "${{ matrix.channel }}-${{ matrix.skip-integration-tests }}-${{ matrix.type }}-${{ matrix.worker }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]').txt
86+
env:
87+
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
88+
CHANNEL: ${{ matrix.channel }}
89+
TEST_COVERAGE: 1
90+
TEST_PKGS: ${{ matrix.pkg }}
91+
TEST_FLAGS: -v --parallel=6 --timeout=20m
92+
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
93+
-
94+
name: Upload coverage file
95+
uses: actions/upload-artifact@v2
96+
with:
97+
name: coverage
98+
path: ./coverage
99+
100+
upload-coverage:
101+
needs:
102+
- test
103+
runs-on: ubuntu-latest
104+
steps:
105+
-
106+
name: Download coverage files
107+
uses: actions/download-artifact@v2
108+
with:
109+
name: coverage
110+
path: ./coverage
111+
-
112+
name: List coverage files
113+
uses: actions/github-script@v3
114+
id: files
115+
with:
116+
result-encoding: string
117+
script: |
118+
return require('fs').readdirSync('./coverage', {withFileTypes: true})
119+
.filter(item => !item.isDirectory())
120+
.map(item => `./coverage/${item.name}`)
121+
.join(',');
122+
-
123+
name: Send to Codecov
124+
uses: codecov/codecov-action@v2
125+
with:
126+
files: ${{ steps.files.outputs.result }}
127+
21128
build:
129+
needs:
130+
- test
22131
runs-on: ubuntu-latest
23132
strategy:
24133
fail-fast: false

hack/_util

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
dockerCmd() {
4+
(set -x ; docker "$@")
5+
}
6+
7+
: ${CACHE_FROM=}
8+
: ${CACHE_TO=}
9+
10+
buildkitPkg=github.com/moby/buildkit
11+
# FIXME: Doesn't seem to be possible to use a ref from a pseudo-ver in go.mod as build context so we need to use a hardcoded one for now.
12+
buildkitVersion=ffe2301031c8f8bfb8d5fc5034e5e509c5624913
13+
# Returns buildkit ref from go.mod (can be v0.9.3 or ffe2301031c8 for pseudo-ver)
14+
#buildkitVersion=$(go list -mod=readonly -u -m -f '{{.Version}}' $buildkitPkg)
15+
#if [[ "${buildkitVersion}" == *-*-* ]]; then
16+
# # if a pseudo-version, figure out just the SHA
17+
# buildkitVersion=$(echo "${buildkitVersion}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
18+
#fi
19+
buildkitRef="https://${buildkitPkg}.git#${buildkitVersion}"
20+
21+
cacheFromFlag=""
22+
cacheToFlag=""
23+
if [ -n "$CACHE_FROM" ]; then
24+
cacheFromFlag="--cache-from=$CACHE_FROM"
25+
fi
26+
if [ -n "$CACHE_TO" ]; then
27+
cacheToFlag="--cache-to=$CACHE_TO"
28+
fi

hack/buildkit-it-base

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
OUTPUT=$1
4+
5+
. $(dirname $0)/_util
6+
set -eu -o pipefail
7+
8+
outputFlag="--output=$OUTPUT"
9+
if [ -z "$OUTPUT" ]; then
10+
outputFlag="--output=type=cacheonly"
11+
fi
12+
13+
# build buildkit integration test base from buildkit ref
14+
# https://github.com/moby/buildkit/blob/ffe2301031c8f8bfb8d5fc5034e5e509c5624913/Dockerfile#L228
15+
dockerCmd buildx build $cacheFromFlag $cacheToFlag $outputFlag \
16+
--target "integration-tests-base" \
17+
$buildkitRef

hack/test

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
3+
. $(dirname $0)/_util
4+
set -eu -o pipefail
5+
6+
: ${CHANNEL=mainline}
7+
8+
: ${TEST_INTEGRATION=}
9+
: ${TEST_DOCKERFILE=}
10+
: ${TEST_DOCKERD=}
11+
: ${TEST_DOCKERD_BINARY=$(which dockerd)}
12+
: ${TEST_COVERAGE=}
13+
: ${TEST_KEEP_CACHE=}
14+
15+
if [ "$TEST_DOCKERD" == "1" ] && ! file $TEST_DOCKERD_BINARY | grep "statically linked" >/dev/null; then
16+
echo "dockerd binary needs to be statically linked"
17+
exit 1
18+
fi
19+
20+
if [ "$#" == 0 ]; then TEST_INTEGRATION=1; fi
21+
22+
while test $# -gt 0; do
23+
case "$1" in
24+
dockerfile)
25+
TEST_DOCKERFILE=1
26+
;;
27+
integration)
28+
TEST_INTEGRATION=1
29+
;;
30+
*)
31+
echo "unknown arg $1"
32+
;;
33+
esac
34+
shift
35+
done
36+
37+
coverageVol=""
38+
coverageFlags=""
39+
if [ "$TEST_COVERAGE" = "1" ]; then
40+
covdir="$(pwd)/coverage"
41+
mkdir -p "$covdir"
42+
coverageVol="-v $covdir:/coverage"
43+
coverageFlags="-coverprofile=/coverage/coverage.txt -covermode=atomic"
44+
fi
45+
46+
iid="dfile-frontend-tests"
47+
48+
# build buildkit integration test base container and output to docker
49+
$(dirname $0)/buildkit-it-base "type=docker,name=$iid"
50+
51+
cacheVolume="dfile-frontend-test-cache"
52+
if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
53+
dockerCmd create -v /root/.cache -v /root/.cache/registry -v /go/pkg/mod --name "$cacheVolume" alpine
54+
fi
55+
56+
createFlags="--rm --privileged --volumes-from=$cacheVolume -v /tmp $coverageVol -e BUILDKIT_RUN_NETWORK_INTEGRATION_TESTS=1 -e BUILDKIT_CNI_INIT_LOCK_PATH=/run/buildkit_cni_bridge.lock -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry"
57+
58+
if [ "$TEST_INTEGRATION" == 1 ]; then
59+
cid=$(dockerCmd create $createFlags $iid go test $coverageFlags ${TEST_FLAGS:--v} ${TEST_PKGS:-.})
60+
dockerCmd cp . "$cid:/src"
61+
if [ "$TEST_DOCKERD" = "1" ]; then
62+
dockerCmd cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/
63+
fi
64+
dockerCmd start -a $cid
65+
fi
66+
67+
if [ "$TEST_DOCKERFILE" == 1 ]; then
68+
buildtags=$(cat ./release/$CHANNEL/tags)
69+
tarout=$(mktemp -t dockerfile-frontend.XXXXXXXXXX)
70+
71+
# build dockerfile frontend
72+
dockerCmd buildx build --build-arg "CHANNEL=$CHANNEL" --output "type=oci,dest=$tarout" .
73+
74+
if [ -s "$tarout" ]; then
75+
cid=$(dockerCmd create $createFlags -v /tmp $coverageVol -e FRONTEND_GATEWAY_ONLY=local:/$CHANNEL.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TEST_FLAGS:-v} ${TEST_PKGS:-.})
76+
dockerCmd cp . "$cid:/src"
77+
dockerCmd cp "$tarout" "$cid:/$CHANNEL.tar"
78+
if [ "$TEST_DOCKERD" = "1" ]; then
79+
dockerCmd cp "$TEST_DOCKERD_BINARY" "$cid:/usr/bin/"
80+
fi
81+
dockerCmd start -a "$cid"
82+
fi
83+
rm "$tarout"
84+
fi
85+
86+
if [ "$TEST_KEEP_CACHE" != "1" ]; then
87+
dockerCmd rm -v $cacheVolume
88+
fi

0 commit comments

Comments
 (0)