From 0077c05f983daf0213129a6fded96f877fa9bb97 Mon Sep 17 00:00:00 2001 From: Cristovao Cordeiro Date: Tue, 15 Aug 2023 14:58:22 +0200 Subject: [PATCH] tests: remove azblob tests and add pushing to artifactory --- .github/workflows/build.yml | 33 +------- hack/azblob_test/Dockerfile | 16 ---- hack/azblob_test/docker-bake.hcl | 15 ---- hack/azblob_test/run_test.sh | 26 ------ hack/azblob_test/test.sh | 131 ------------------------------ hack/azblob_test/test1/Dockerfile | 7 -- hack/azblob_test/test2/Dockerfile | 9 -- 7 files changed, 4 insertions(+), 233 deletions(-) delete mode 100644 hack/azblob_test/Dockerfile delete mode 100644 hack/azblob_test/docker-bake.hcl delete mode 100755 hack/azblob_test/run_test.sh delete mode 100755 hack/azblob_test/test.sh delete mode 100644 hack/azblob_test/test1/Dockerfile delete mode 100644 hack/azblob_test/test2/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bfdb436d6acb..a642b9eb382f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -215,32 +215,6 @@ jobs: ARTIFACTORY_APT_AUTH_CONF: ${{ secrets.ARTIFACTORY_APT_AUTH_CONF }} ARTIFACTORY_BASE64_GPG: ${{ secrets.ARTIFACTORY_BASE64_GPG }} - test-azblob: - runs-on: ubuntu-20.04 - needs: - - base - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Expose GitHub Runtime - uses: crazy-max/ghaction-github-runtime@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - version: ${{ env.BUILDX_VERSION }} - driver-opts: image=${{ env.REPO_SLUG_ORIGIN }} - buildkitd-flags: --debug - - - name: Test - run: | - hack/azblob_test/run_test.sh - env: - ARTIFACTORY_APT_AUTH_CONF: ${{ secrets.ARTIFACTORY_APT_AUTH_CONF }} - ARTIFACTORY_BASE64_GPG: ${{ secrets.ARTIFACTORY_BASE64_GPG }} - test-os: runs-on: ${{ matrix.os }} strategy: @@ -382,6 +356,7 @@ jobs: TARGET: ${{ matrix.target-stage }} RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }} CACHE_TO: type=gha,scope=image${{ matrix.target-stage }} + REGISTRY_TARGET: ${{ startsWith(github.ref, 'refs/tags/v') && secrets.ARTIFACTORY_REGISTRY_REPO || env.REPO_SLUG_TARGET }} steps: - name: Checkout @@ -411,7 +386,7 @@ jobs: - name: Build local image for testing run: | - ./hack/images local "$REPO_SLUG_TARGET" "nopush" + ./hack/images local "$REGISTRY_TARGET" "nopush" env: # have CACHE_FROM here cause the "env" context is not available at the job level CACHE_FROM: "type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }} type=gha,scope=image${{ matrix.target-stage }}" @@ -427,13 +402,13 @@ jobs: ./hack/canonical_test/run_test.sh env: - IMG_NAME: '${{ env.REPO_SLUG_TARGET }}:local' + IMG_NAME: '${{ env.REGISTRY_TARGET }}:local' - name: Push ${{ needs.release-base.outputs.tag }} to GHCR if: needs.release-base.outputs.push == 'push' run: | docker buildx use ${{ steps.setup-buildx-builder.outputs.name }} - ./hack/images "${{ needs.release-base.outputs.tag }}" "$REPO_SLUG_TARGET" push + ./hack/images "${{ needs.release-base.outputs.tag }}" "$REGISTRY_TARGET" push env: # have CACHE_FROM here cause the "env" context is not available at the job level CACHE_FROM: "type=gha,scope=${{ env.CACHE_GHA_SCOPE_CROSS }} type=gha,scope=image${{ matrix.target-stage }}" diff --git a/hack/azblob_test/Dockerfile b/hack/azblob_test/Dockerfile deleted file mode 100644 index 37d5d2d8eff1..000000000000 --- a/hack/azblob_test/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM moby/buildkit AS buildkit - -FROM debian:bullseye-slim -RUN apt-get update \ - && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ - && apt-get install -y --no-install-recommends ca-certificates containerd curl nodejs npm procps \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && npm install -g azurite@3.18.0 \ - && mkdir /test \ - && mkdir /tmp/azurite \ - && curl -sL https://aka.ms/InstallAzureCLIDeb | bash - -COPY --link --from=buildkit /usr/bin/buildkitd /usr/bin/buildctl /bin/ - -COPY --link . /test diff --git a/hack/azblob_test/docker-bake.hcl b/hack/azblob_test/docker-bake.hcl deleted file mode 100644 index a0997f874078..000000000000 --- a/hack/azblob_test/docker-bake.hcl +++ /dev/null @@ -1,15 +0,0 @@ -target "buildkit" { - context = "../../" - cache-from = ["type=gha,scope=binaries"] - secret = [ - "id=ARTIFACTORY_APT_AUTH_CONF", - "id=ARTIFACTORY_BASE64_GPG" - ] -} - -target "default" { - contexts = { - buildkit = "target:buildkit" - } - tags = ["moby/buildkit:azblobtest"] -} diff --git a/hack/azblob_test/run_test.sh b/hack/azblob_test/run_test.sh deleted file mode 100755 index cfcae8ba6a97..000000000000 --- a/hack/azblob_test/run_test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -ex - -function cleanup() { - docker rmi moby/buildkit:azblobtest -} - -trap cleanup EXIT -cd "$(dirname "$0")" - -docker buildx bake --load \ - --set buildkit.secrets=id=ARTIFACTORY_APT_AUTH_CONF \ - --set buildkit.secrets=id=ARTIFACTORY_BASE64_GPG - -AZURE_ACCOUNT_NAME=azblobcacheaccount -AZURE_ACCOUNT_URL=azblobcacheaccount.blob.localhost.com -AZURE_ACCOUNT_KEY=$(echo "azblobcacheaccountkey" | base64) - -docker run \ - --rm \ - --privileged \ - --add-host ${AZURE_ACCOUNT_URL}:127.0.0.1 \ - -e AZURE_ACCOUNT_NAME=${AZURE_ACCOUNT_NAME} \ - -e AZURE_ACCOUNT_KEY=${AZURE_ACCOUNT_KEY} \ - -e AZURE_ACCOUNT_URL=${AZURE_ACCOUNT_URL} \ - moby/buildkit:azblobtest \ - /test/test.sh diff --git a/hack/azblob_test/test.sh b/hack/azblob_test/test.sh deleted file mode 100755 index adffaf0f03c8..000000000000 --- a/hack/azblob_test/test.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash -ex - -# Refer to https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azurite Azurite documentation -rm -rf /tmp/azurite - -export AZURITE_ACCOUNTS="${AZURE_ACCOUNT_NAME}:${AZURE_ACCOUNT_KEY}" -BLOB_PORT=10000 - -azurite --silent --location /tmp/azurite --debug /tmp/azurite/azurite.debug --blobPort ${BLOB_PORT} & -timeout 15 bash -c "until echo > /dev/tcp/localhost/${BLOB_PORT}; do sleep 0.5; done" - -buildkitd -debugaddr 0.0.0.0:8060 & -while true; do - curl -s -f http://127.0.0.1:8060/debug/pprof/ >/dev/null && break - sleep 1 -done - -export default_options="type=azblob,container=cachecontainer,account_url=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT},secret_access_key=${AZURE_ACCOUNT_KEY}" - -rm -rf /tmp/destdir1 /tmp/destdir2 - -# First build of test1: no cache -buildctl build \ - --progress plain \ - --frontend dockerfile.v0 \ - --local context=/test/test1 \ - --local dockerfile=/test/test1 \ - --import-cache "$default_options,name=foo" \ - --export-cache "$default_options,mode=max,name=bar;foo" \ - --output type=local,dest=/tmp/destdir1 - -# Check the 4 blob files and 2 manifest files in the azure blob container -blobCount=$(az storage blob list --output tsv --prefix blobs --container-name cachecontainer --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" | wc -l) -if (("$blobCount" != 4)); then - echo "unexpected number of blobs found: $blobCount" - exit 1 -fi - -manifestCount=$(az storage blob list --output tsv --prefix manifests --container-name cachecontainer --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" | wc -l) -if (("$manifestCount" != 2)); then - echo "unexpected number of manifests found: $manifestCount" - exit 1 -fi - -mkdir /tmp/content1 -az storage blob download-batch -d /tmp/content1 --pattern blobs/* -s cachecontainer --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" - -# Second build of test1: Test that cache was used -buildctl build \ - --progress plain \ - --frontend dockerfile.v0 \ - --local context=/test/test1 \ - --local dockerfile=/test/test1 \ - --import-cache "$default_options,name=foo" \ - --export-cache "$default_options,mode=max,name=bar;foo" \ - 2>&1 | tee /tmp/log1 - -# Check that the existing steps were read from the cache -cat /tmp/log1 | grep 'cat /dev/urandom | head -c 100 | sha256sum > unique_first' -A1 | grep CACHED -cat /tmp/log1 | grep 'cat /dev/urandom | head -c 100 | sha256sum > unique_second' -A1 | grep CACHED - -# No change expected in the blobs -mkdir /tmp/content2 -az storage blob download-batch -d /tmp/content2 --pattern blobs/* -s cachecontainer --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" -diff -r /tmp/content1 /tmp/content2 - -# First build of test2: Test that we can reuse the cache for a different docker image -buildctl prune -buildctl build \ - --progress plain \ - --frontend dockerfile.v0 \ - --local context=/test/test2 \ - --local dockerfile=/test/test2 \ - --import-cache "$default_options,name=foo" \ - --export-cache "$default_options,mode=max,name=bar;foo" \ - --output type=local,dest=/tmp/destdir2 \ - 2>&1 | tee /tmp/log2 - -mkdir /tmp/content3 -az storage blob download-batch -d /tmp/content3 --pattern blobs/* -s cachecontainer --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" - -# There should ONLY be 1 difference between the contents of /tmp/content1 and /tmp/content3 -# This difference is that in /tmp/content3 there should 1 extra blob corresponding to the layer: RUN cat /dev/urandom | head -c 100 | sha256sum > unique_third -contentDiff=$(diff -r /tmp/content1 /tmp/content3 || :) -if [[ ! "$contentDiff" =~ ^"Only in /tmp/content3/blobs: sha256:"[a-z0-9]{64}$ ]]; then - echo "unexpected diff found $contentDiff" - exit 1 -fi - -# Check the existing steps were not executed, but read from cache -cat /tmp/log2 | grep 'cat /dev/urandom | head -c 100 | sha256sum > unique_first' -A1 | grep CACHED - -# Ensure cache is reused -rm /tmp/destdir2/unique_third -diff -r /tmp/destdir1 /tmp/destdir2 - -# Second build of test2: Test the behavior when a blob is missing -az storage blob delete-batch -s cachecontainer --pattern blobs/* --connection-string "DefaultEndpointsProtocol=http;AccountName=${AZURE_ACCOUNT_NAME};AccountKey=${AZURE_ACCOUNT_KEY};BlobEndpoint=http://${AZURE_ACCOUNT_URL}:${BLOB_PORT};" - -buildctl prune -buildctl build \ - --progress plain \ - --frontend dockerfile.v0 \ - --local context=/test/test2 \ - --local dockerfile=/test/test2 \ - --import-cache "$default_options,name=foo" \ - 2>&1 | tee /tmp/log3 - -cat /tmp/log3 | grep -E 'blob.+not found' >/dev/null - -pids="" - -for i in $(seq 0 9); do - buildctl build \ - --progress plain \ - --frontend dockerfile.v0 \ - --local context=/test/test1 \ - --local dockerfile=/test/test1 \ - --import-cache "$default_options,name=foo" \ - --export-cache "$default_options,mode=max,name=bar;foo" \ - &>/tmp/concurrencytestlog$i & - pids="$pids $!" -done - -wait $pids - -for i in $(seq 0 9); do - cat /tmp/concurrencytestlog$i | grep -q -v 'failed to upload blob ' -done - -echo Azure blob checks ok diff --git a/hack/azblob_test/test1/Dockerfile b/hack/azblob_test/test1/Dockerfile deleted file mode 100644 index d56dd9d1fd92..000000000000 --- a/hack/azblob_test/test1/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM busybox:1.35 AS build -RUN cat /dev/urandom | head -c 100 | sha256sum > unique_first -RUN cat /dev/urandom | head -c 100 | sha256sum > unique_second - -FROM scratch -COPY --link --from=build /unique_first / -COPY --link --from=build /unique_second / diff --git a/hack/azblob_test/test2/Dockerfile b/hack/azblob_test/test2/Dockerfile deleted file mode 100644 index c0efe23b40c6..000000000000 --- a/hack/azblob_test/test2/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM busybox:1.35 AS build -RUN cat /dev/urandom | head -c 100 | sha256sum > unique_first -RUN cat /dev/urandom | head -c 100 | sha256sum > unique_second -RUN cat /dev/urandom | head -c 100 | sha256sum > unique_third - -FROM scratch -COPY --link --from=build /unique_first / -COPY --link --from=build /unique_second / -COPY --link --from=build /unique_third /