From 406e1996224e6a5d4587e8b88540ef4567a50790 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 9 Dec 2024 14:09:54 -0800 Subject: [PATCH 1/3] Support multi tags for autosdk docker build --- internal/test/e2e/autosdk/build.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/test/e2e/autosdk/build.sh b/internal/test/e2e/autosdk/build.sh index c9cf03243..2bec0ff54 100755 --- a/internal/test/e2e/autosdk/build.sh +++ b/internal/test/e2e/autosdk/build.sh @@ -24,6 +24,7 @@ parse_opts() { local deliminator option local arg= + local tag=() # Translate --gnu-long-options to -g (short options) for arg @@ -50,7 +51,7 @@ parse_opts() { do case "$option" in t) - readonly TAG="$OPTARG" + tag+=("$OPTARG") ;; h) usage @@ -65,8 +66,11 @@ parse_opts() { done # Default values - [ -z "${TAG}" ] \ - && readonly TAG="sample-app" + if [ ${#tag[@]} -eq 0 ]; then + readonly TAG=("sample-app") + else + readonly TAG=("${tag[@]}") + fi return 0 } @@ -75,7 +79,7 @@ build() { local root_dir="$1" local local_dir="$2" local dockerfile="${local_dir}/Dockerfile" - local tag_arg + local tag_arg tag if [ ! -f "$dockerfile" ]; then echo "Dockerfile does not exist: $dockerfile" @@ -87,9 +91,9 @@ build() { return 1 fi - if [ -n "$TAG" ]; then - tag_arg=("-t" "$TAG") - fi + for tag in "${TAG[@]}"; do + tag_arg+=("-t" "$tag") + done (cd "$root_dir" && docker build "${tag_arg[@]}" -f "$dockerfile" .) return 0 From af40a1dd0f8a03657838d2fda37d178059ed60de Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 9 Dec 2024 14:10:11 -0800 Subject: [PATCH 2/3] Cache docker build in kind workflow --- .github/workflows/kind.yml | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/.github/workflows/kind.yml b/.github/workflows/kind.yml index df0b479a7..659ac34bd 100644 --- a/.github/workflows/kind.yml +++ b/.github/workflows/kind.yml @@ -36,13 +36,34 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - name: Setup BATS uses: mig4/setup-bats@af9a00deb21b5d795cabfeaa8d9060410377686d # v1 - - name: Build sample app from script - if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) != '' }} - run: ./internal/test/e2e/${{ matrix.library }}/build.sh -t sample-app:latest - - name: Build sample app + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-docker-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-docker- + - name: Build and push local if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) == '' }} - working-directory: ./internal/test/e2e/${{ matrix.library }} - run: docker build -t sample-app:latest . + uses: docker/build-push-action@v5 + with: + context: ./internal/test/e2e/${{ matrix.library }} + tags: "sample-app:latest,go.opentelemetry.io/auto-test-${{ matrix.library }}:latest" + load: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + - name: Build and push global + if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) != '' }} + uses: docker/build-push-action@v5 + with: + context: . + file: ./internal/test/e2e/${{ matrix.library }}/Dockerfile + tags: "sample-app:latest,go.opentelemetry.io/auto-test-${{ matrix.library }}:latest" + load: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max - name: Set up Helm uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4 with: @@ -106,6 +127,7 @@ jobs: if: always() && steps.job-status.outcome == 'success' - name: print auto-instrumentation logs run: | + kubectl logs -l app=sample -c sample-app kubectl logs -l app=sample -c auto-instrumentation --tail=300 exit 1 if: always() && steps.job-status.outcome == 'failure' From 7300ac755aa501d7be537d86cf43c26ec443c0bf Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 10 Dec 2024 08:39:19 -0800 Subject: [PATCH 3/3] Cache the auto-instrumentation image build --- .github/workflows/kind.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/kind.yml b/.github/workflows/kind.yml index 659ac34bd..a981b3cef 100644 --- a/.github/workflows/kind.yml +++ b/.github/workflows/kind.yml @@ -14,10 +14,24 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 - - name: Build auto-instrumentation - run: | - IMG=otel-go-instrumentation:latest make docker-build - docker save otel-go-instrumentation:latest -o otel-go-instrumentation.tar + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-docker-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-docker- + - name: Docker build + uses: docker/build-push-action@v5 + with: + context: . + tags: "otel-go-instrumentation:latest" + load: true + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + outputs: type=tar,dest=otel-go-instrumentation.tar - name: Upload Docker image artifact uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 with: @@ -42,9 +56,9 @@ jobs: uses: actions/cache@v3 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-docker-${{ github.sha }} + key: ${{ runner.os }}-docker-${{ matrix.library }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-docker- + ${{ runner.os }}-docker-${{ matrix.library }}- - name: Build and push local if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) == '' }} uses: docker/build-push-action@v5