Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache docker builds #1395

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -36,13 +50,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-${{ matrix.library }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-${{ matrix.library }}-
- 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:
Expand Down Expand Up @@ -106,6 +141,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'
Expand Down
18 changes: 11 additions & 7 deletions internal/test/e2e/autosdk/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parse_opts() {

local deliminator option
local arg=
local tag=()

# Translate --gnu-long-options to -g (short options)
for arg
Expand All @@ -50,7 +51,7 @@ parse_opts() {
do
case "$option" in
t)
readonly TAG="$OPTARG"
tag+=("$OPTARG")
;;
h)
usage
Expand All @@ -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
}
Expand All @@ -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"
Expand All @@ -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
Expand Down
Loading