Skip to content

Commit

Permalink
Refactor test for GitHub Actions
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Nov 22, 2020
1 parent dec4da0 commit e22c19d
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 135 deletions.
180 changes: 180 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
name: test

on:
push:
branches:
- "ghactions-test" #remove when merged
- 'master'
tags:
- 'v*'
- 'dockerfile/*'
pull_request:
branches:
- 'master'

env:
REPO_SLUG_ORIGIN: "moby/buildkit:latest"

jobs:
test-base:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Cache integration-tests
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/integration-tests
key: ${{ runner.os }}-buildkit-integration-tests-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-integration-tests-
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
-
name: Build integration-tests
run: |
./hack/build_ci_first_pass integration-tests
env:
CACHE_DIR: /tmp/.buildkit-cache/integration-tests
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

test:
runs-on: ubuntu-latest
needs: [ test-base ]
strategy:
fail-fast: false
matrix:
include:
-
pkg: ./client
flags: -v --timeout=20m
skip-it: 0
typ: integration
-
pkg: ./cmd/buildctl
flags: -v
skip-it: 0
typ: integration
-
pkg: ./worker/containerd
flags: -v
skip-it: 0
typ: integration
-
pkg: ''
flags: -v
skip-it: 1
typ: integration gateway
-
pkg: ./frontend
flags: -v
skip-it: 0
typ: ''
-
pkg: ./frontend/dockerfile
flags: -v --parallel=6 --timeout=20m
skip-it: 0
typ: ''
-
pkg: ./frontend/dockerfile
flags: -v
skip-it: 0
typ: dockerfile
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Cache integration-tests
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/integration-tests
key: ${{ runner.os }}-buildkit-integration-tests-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-integration-tests-
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
-
name: Test ${{ matrix.pkg }} ${{ matrix.typ }}
run: |
./hack/test ${{ matrix.typ }}
env:
TEST_COVERAGE: 1
TESTPKGS: ${{ matrix.pkg }}
TESTFLAGS: ${{ matrix.flags }}
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-it }}
CACHE_DIR: /tmp/.buildkit-cache/integration-tests
-
name: Upload coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage/coverage.txt
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

os:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
#- ubuntu-latest
#- macOS-latest
- windows-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.13
-
name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Go mod
run: |
go mod download
-
name: Test
env:
TMPDIR: ${{ runner.temp }}
SKIP_INTEGRATION_TESTS: 1
run: |
go test -coverprofile=coverage.txt -covermode=atomic ./...
shell: bash
-
name: Upload coverage
uses: codecov/codecov-action@v1
with:
file: coverage.txt
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1
43 changes: 0 additions & 43 deletions .github/workflows/windows.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
coverage
release-out
.certs
.tmp
33 changes: 18 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: minimal
env:
global:
- DOCKER_CHANNEL="stable"
- DOCKER_CLI_EXPERIMENTAL="enabled"
- PLATFORMS="linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le"
- PREFER_BUILDCTL="1"

Expand All @@ -18,7 +19,8 @@ before_install:
- docker info

install:
- docker run --rm --privileged linuxkit/binfmt:v0.8
- docker buildx create --name builder --driver docker-container --driver-opt image=$REPO_SLUG_ORIGIN --use
- docker run --rm --privileged tonistiigi/binfmt:latest --install all
- docker run --name buildkit -d --privileged -p 1234:1234 $REPO_SLUG_ORIGIN --debug --addr tcp://0.0.0.0:1234 --oci-worker-gc=false
- sudo docker cp buildkit:/usr/bin/buildctl /usr/bin/
- export BUILDKIT_HOST=tcp://0.0.0.0:1234
Expand All @@ -30,23 +32,26 @@ jobs:
include:
- stage: building
name: "Build"
script: ./hack/login_ci_cache && ./hack/build_ci_first_pass
script:
- ./hack/login_ci_cache
- ./hack/build_ci_first_pass binaries
- ./hack/build_ci_first_pass integration-tests
- stage: testing
name: "Client integration tests"
script:
script:
- TESTPKGS=./client TESTFLAGS='-v --timeout=20m' ./hack/test integration
- TESTPKGS=./cmd/buildctl ./hack/test integration
- TESTPKGS=./worker/containerd ./hack/test integration
- script:
- ./hack/lint
- SKIP_INTEGRATION_TESTS=1 ./hack/test integration gateway
- ./hack/validate-vendor
- ./hack/validate-generated-files
- ./hack/validate-shfmt
- TESTPKGS=./frontend ./hack/test
- ./hack/lint
- SKIP_INTEGRATION_TESTS=1 ./hack/test integration gateway
- ./hack/validate-vendor
- ./hack/validate-generated-files
- ./hack/validate-shfmt
- TESTPKGS=./frontend ./hack/test
name: "Unit Tests & Lint & Vendor & Proto"
- script:
- TESTPKGS=./frontend/dockerfile TESTFLAGS='-v --parallel=6 --timeout=20m' ./hack/test
- TESTPKGS=./frontend/dockerfile TESTFLAGS='-v --parallel=5 --timeout=30m' ./hack/test
name: "Dockerfile integration tests"
- script: TESTPKGS=./frontend/dockerfile ./hack/test dockerfile
name: "External Dockerfile tests"
Expand Down Expand Up @@ -79,9 +84,9 @@ jobs:
skip_cleanup: true
file_glob: true
on:
repo: moby/buildkit
tags: true
condition: $TRAVIS_TAG =~ ^v[0-9]
repo: moby/buildkit
tags: true
condition: $TRAVIS_TAG =~ ^v[0-9]
- provider: script
script: ./frontend/dockerfile/cmd/dockerfile-frontend/hack/release master mainline $DF_REPO_SLUG_TARGET push
on:
Expand All @@ -106,8 +111,6 @@ jobs:
repo: moby/buildkit
branch: master
condition: $TRAVIS_EVENT_TYPE == "cron"


before_deploy:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![GoDoc](https://godoc.org/github.com/moby/buildkit?status.svg)](https://godoc.org/github.com/moby/buildkit/client/llb)
[![Build Status](https://travis-ci.com/moby/buildkit.svg?branch=master)](https://travis-ci.com/moby/buildkit)
[![Go Report Card](https://goreportcard.com/badge/github.com/moby/buildkit)](https://goreportcard.com/report/github.com/moby/buildkit)
[![codecov](https://codecov.io/gh/moby/buildkit/branch/master/graph/badge.svg)](https://codecov.io/gh/moby/buildkit)

BuildKit is a toolkit for converting source code to build artifacts in an efficient, expressive and repeatable manner.

Expand Down
71 changes: 48 additions & 23 deletions hack/build_ci_first_pass
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
#!/usr/bin/env bash

. $(dirname $0)/util
TYP=$1

. $(dirname $0)/util
set -e

if [ -z "$TRAVIS_COMMIT" ]; then
echo "TRAVIS_COMMIT_REQURED"
exit 0
fi
usage() {
echo "usage: ./hack/build_ci_first_pass <typ>"
exit 1
}

progressFlag=""
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi
if [ -z "$TYP" ]; then
usage
fi

importCacheFlags=""
exportCacheFlags=""
exportFlags=""

if [ -f /tmp/buildkit-ci-cache-repo ]; then
exportCacheFlags="--export-cache=type=inline"
exportFlags="--output=type=image,push=true,name=$(cat /tmp/buildkit-ci-cache-repo)"
if [ "$TRAVIS" = "true" ]; then
if [ -z "$TRAVIS_COMMIT" ]; then
echo "Travis commit required"
exit 0
fi
if [ -f /tmp/buildkit-ci-cache-repo ]; then
exportCacheFlags="--cache-to=type=inline"
exportFlags="--output=type=image,push=true,name=$(cat /tmp/buildkit-ci-cache-repo)"
fi
if [ "$TYP" = "binaries" ]; then
importCacheFlags="--cache-from=type=registry,ref=cicache.buildk.it/moby/buildkit/master:binaries --cache-from=type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests"
exportFlags="$exportFlags:binaries"
elif [ "$TYP" = "integration-tests" ]; then
importCacheFlags="--cache-from=type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests"
exportFlags="$exportFlags:integration-tests"
fi
elif [ "$GITHUB_ACTIONS" = "true" ]; then
context="."
if [ -n "$cacheref" ]; then
importCacheFlags="--cache-from=type=local,src=$cacheref"
exportCacheFlags="--cache-to=type=local,dest=$cacheref"
fi
fi

set -x
buildctl build $progressFlag --frontend=dockerfile.v0 \
$currentcontextBuildctl \
--opt target=binaries \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:binaries \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests \
$exportCacheFlags $exportFlags:binaries

buildctl build $progressFlag --frontend=dockerfile.v0 \
$currentcontextBuildctl \
--opt target=integration-tests-base \
--import-cache type=registry,ref=cicache.buildk.it/moby/buildkit/master:integration-tests \
$exportCacheFlags $exportFlags:integration-tests
case $TYP in
"binaries")
buildxCmd build $importCacheFlags $exportCacheFlags $exportFlags \
--target "binaries" \
$currentcontext
;;
"integration-tests")
buildxCmd build $importCacheFlags $exportCacheFlags $exportFlags \
--target "integration-tests-base" \
$currentcontext
;;
*)
echo >&2 "Unknown type $TYP"
exit 1
;;
esac
Loading

0 comments on commit e22c19d

Please sign in to comment.