Skip to content

Commit

Permalink
Use gha cache on CI
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Oct 5, 2021
1 parent 78e8856 commit ec65f41
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 197 deletions.
156 changes: 37 additions & 119 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ env:
REPO_SLUG_TARGET: "moby/buildkit"
DF_REPO_SLUG_TARGET: "docker/dockerfile-upstream"
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm64,linux/s390x,linux/ppc64le,linux/riscv64"
CACHEKEY_INTEGRATION_TESTS: "integration-tests"
CACHEKEY_BINARIES: "binaries"
CACHEKEY_CROSS: "cross"
CACHE_GHA_SCOPE_IT: "integration-tests"
CACHE_GHA_SCOPE_BINARIES: "binaries"
CACHE_GHA_SCOPE_CROSS: "cross"

jobs:
base:
Expand All @@ -32,21 +32,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Cache ${{ env.CACHEKEY_INTEGRATION_TESTS }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_INTEGRATION_TESTS }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_INTEGRATION_TESTS }}-
-
name: Cache ${{ env.CACHEKEY_BINARIES }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -55,28 +42,21 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
buildkitd-flags: --debug
-
name: Build ${{ env.CACHEKEY_BINARIES }}
name: Build ${{ env.CACHE_GHA_SCOPE_BINARIES }}
run: |
./hack/build_ci_first_pass binaries
env:
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
CACHEDIR_TO: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}-new
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
-
name: Build ${{ env.CACHEKEY_INTEGRATION_TESTS }}
name: Build ${{ env.CACHE_GHA_SCOPE_IT }}
run: |
./hack/build_ci_first_pass integration-tests
env:
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}
CACHEDIR_TO: /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}-new
-
# FIXME: Temp fix for https://github.com/moby/buildkit/issues/1850
name: Move cache
run: |
rm -rf /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
mv /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}-new /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
rm -rf /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}
mv /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}-new /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }}

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -109,21 +89,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Cache ${{ env.CACHEKEY_INTEGRATION_TESTS }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_INTEGRATION_TESTS }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_INTEGRATION_TESTS }}-
-
name: Cache ${{ env.CACHEKEY_BINARIES }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -132,6 +99,7 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
buildkitd-flags: --debug
-
name: Test pkg=${{ matrix.pkg }} ; typ=${{ matrix.typ }} ; skipit=${{ matrix.skip-integration-tests }} ; worker=${{ matrix.worker }}
run: |
Expand All @@ -145,7 +113,7 @@ jobs:
TEST_COVERAGE: 1
TESTPKGS: ${{ matrix.pkg }}
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_INTEGRATION_TESTS }} /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_IT }} type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }}
-
name: Upload coverage file
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -236,13 +204,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Cache ${{ env.CACHEKEY_CROSS }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -251,21 +214,16 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
buildkitd-flags: --debug
-
name: Cross
run: |
./hack/cross
env:
PLATFORMS: ${{ env.PLATFORMS }},darwin/amd64,darwin/arm64,windows/amd64,windows/arm64
RUNC_PLATFORMS: ${{ env.PLATFORMS }}
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
CACHEDIR_TO: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}-new
-
# FIXME: Temp fix for https://github.com/moby/buildkit/issues/1850
name: Move cache
run: |
rm -rf /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
mv /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}-new /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }}
CACHE_TO: type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }}

release-base:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -305,21 +263,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Cache image${{ matrix.target-stage }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/image${{ matrix.target-stage }}
key: ${{ runner.os }}-buildkit-image${{ matrix.target-stage }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-image${{ matrix.target-stage }}-
-
name: Cache ${{ env.CACHEKEY_CROSS }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -328,6 +273,7 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
buildkitd-flags: --debug
-
name: Login to DockerHub
if: needs.release-base.outputs.push == 'push'
Expand All @@ -341,14 +287,8 @@ jobs:
./hack/images "${{ needs.release-base.outputs.tag }}" "$REPO_SLUG_TARGET" "${{ needs.release-base.outputs.push }}"
env:
TARGET: ${{ matrix.target-stage }}
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }} /tmp/.buildkit-cache/image${{ matrix.target-stage }}
CACHEDIR_TO: /tmp/.buildkit-cache/image${{ matrix.target-stage }}-new
-
# FIXME: Temp fix for https://github.com/moby/buildkit/issues/1850
name: Move cache
run: |
rm -rf /tmp/.buildkit-cache/image${{ matrix.target-stage }}
mv /tmp/.buildkit-cache/image${{ matrix.target-stage }}-new /tmp/.buildkit-cache/image${{ matrix.target-stage }}
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }} type=gha,scope=image${{ matrix.target-stage }}
CACHE_TO: type=gha,scope=image${{ matrix.target-stage }}

binaries:
runs-on: ubuntu-latest
Expand All @@ -358,21 +298,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Cache ${{ env.CACHEKEY_BINARIES }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_BINARIES }}-
-
name: Cache ${{ env.CACHEKEY_CROSS }}
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
key: ${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-${{ env.CACHEKEY_CROSS }}-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -381,13 +308,14 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
buildkitd-flags: --debug
-
name: Build ${{ needs.release-base.outputs.tag }}
run: |
./hack/release-tar "${{ needs.release-base.outputs.tag }}" release-out
env:
PLATFORMS: ${{ env.PLATFORMS }},darwin/amd64,darwin/arm64,windows/amd64,windows/arm64
CACHEDIR_FROM: /tmp/.buildkit-cache/${{ env.CACHEKEY_BINARIES }} /tmp/.buildkit-cache/${{ env.CACHEKEY_CROSS }}
CACHE_FROM: type=gha,scope=${{ env.CACHE_GHA_SCOPE_BINARIES }} type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }}
-
name: Move artifacts
run: |
Expand Down Expand Up @@ -444,6 +372,9 @@ jobs:
-
name: Checkout
uses: actions/checkout@v2
-
name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -452,14 +383,7 @@ jobs:
uses: docker/setup-buildx-action@v1
with:
driver-opts: image=${{ env.REPO_SLUG_ORIGIN }}
-
name: Cache layers
uses: actions/cache@v2
with:
path: /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}
key: ${{ runner.os }}-buildkit-frontend-${{ needs.frontend-base.outputs.typ }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildkit-frontend-${{ needs.frontend-base.outputs.typ }}-
buildkitd-flags: --debug
-
name: Login to DockerHub
uses: docker/login-action@v1
Expand All @@ -472,18 +396,12 @@ jobs:
run: |
./frontend/dockerfile/cmd/dockerfile-frontend/hack/release "${{ needs.frontend-base.outputs.typ }}" "${{ needs.frontend-base.outputs.tag }}" "$DF_REPO_SLUG_TARGET" "${{ needs.frontend-base.outputs.push }}"
env:
CACHEDIR_FROM: /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}
CACHEDIR_TO: /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}-new
CACHE_FROM: type=gha,scope=frontend-${{ needs.frontend-base.outputs.typ }}
CACHE_TO: type=gha,scope=frontend-${{ needs.frontend-base.outputs.typ }}
-
name: Build ${{ needs.frontend-base.outputs.typ }}/labs
if: needs.frontend-base.outputs.typ == 'master'
run: |
./frontend/dockerfile/cmd/dockerfile-frontend/hack/release "${{ needs.frontend-base.outputs.typ }}" labs "$DF_REPO_SLUG_TARGET" "${{ needs.frontend-base.outputs.push }}"
env:
CACHEDIR_FROM: /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}
-
# FIXME: Temp fix for https://github.com/moby/buildkit/issues/1850
name: Move cache
run: |
rm -rf /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}
mv /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}-new /tmp/.buildkit-cache/frontend-${{ needs.frontend-base.outputs.typ }}
CACHE_FROM: type=gha,scope=frontend-${{ needs.frontend-base.outputs.typ }}
19 changes: 4 additions & 15 deletions frontend/dockerfile/cmd/dockerfile-frontend/hack/release
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ if [ "$PUSH" = "push" ]; then
pushFlag="push=true"
fi

importCacheFlags=""
exportCacheFlags=""
if [ "$GITHUB_ACTIONS" = "true" ]; then
if [ -n "$cacheRefFrom" ]; then
importCacheFlags="--cache-from=type=local,src=$cacheRefFrom"
fi
if [ -n "$cacheRefTo" ]; then
exportCacheFlags="--cache-to=type=local,dest=$cacheRefTo"
fi
fi

case $TYP in
"master")
tagf=./frontend/dockerfile/release/$TAG/tags
Expand All @@ -90,7 +79,7 @@ case $TYP in
pushTag=${pushTag}-$TAG
fi

buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--platform "$PLATFORMS" \
--build-arg "CHANNEL=$TAG" \
--build-arg "BUILDTAGS=$buildTags" \
Expand All @@ -108,7 +97,7 @@ case $TYP in
fi
buildTags=$(cat $tagf)

buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--platform "$PLATFORMS" \
--build-arg "CHANNEL=$TAG" \
--build-arg "BUILDTAGS=$buildTags" \
Expand All @@ -135,7 +124,7 @@ case $TYP in

tmp=$(mktemp -d -t buildid.XXXXXXXXXX)
dt=$(date +%Y%m%d)
buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--platform "$PLATFORMS" \
--target "buildid" \
--build-arg "CHANNEL=$TAG" \
Expand All @@ -150,7 +139,7 @@ case $TYP in
buildid=$(cat $tmp/buildid)
echo "buildid: $buildid"

buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--platform "$PLATFORMS" \
--build-arg "CHANNEL=$TAG" \
--build-arg "BUILDTAGS=$buildTags" \
Expand Down
15 changes: 2 additions & 13 deletions hack/build_ci_first_pass
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,14 @@ if [ -z "$TYP" ]; then
usage
fi

importCacheFlags=""
exportCacheFlags=""
if [ "$GITHUB_ACTIONS" = "true" ]; then
if [ -n "$cacheRefFrom" ]; then
importCacheFlags="--cache-from=type=local,src=$cacheRefFrom"
fi
if [ -n "$cacheRefTo" ]; then
exportCacheFlags="--cache-to=type=local,dest=$cacheRefTo"
fi
fi

case $TYP in
"binaries")
buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--target "binaries" \
$currentcontext
;;
"integration-tests")
buildxCmd build $importCacheFlags $exportCacheFlags \
buildxCmd build $cacheFromFlags $cacheToFlags \
--target "integration-tests-base" \
$currentcontext
;;
Expand Down
Loading

0 comments on commit ec65f41

Please sign in to comment.