-
Notifications
You must be signed in to change notification settings - Fork 16
chore(ci): add docker image cache #274
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,41 @@ jobs: | |
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| - name: Cache Docker images | ||
| uses: actions/cache@v4 | ||
| id: docker-cache | ||
| with: | ||
| path: /tmp/.docker | ||
| key: ${{ runner.os }}-docker-images-${{ hashFiles('test/docker-compose.yml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-docker-images- | ||
| - name: Load Docker images from cache | ||
| if: steps.docker-cache.outputs.cache-hit == 'true' | ||
| run: | | ||
| if [ -f /tmp/.docker/images.tar ]; then | ||
| docker load -i /tmp/.docker/images.tar | ||
| fi | ||
| - name: Pull Docker images | ||
| run: | | ||
| docker compose -f test/docker-compose.yml pull | ||
| - name: Save Docker images to cache | ||
| if: steps.docker-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| mkdir -p /tmp/.docker | ||
| # Get all images from docker-compose.yml and save them | ||
| # Use a temporary file to store images list to avoid subshell issues | ||
| docker compose -f test/docker-compose.yml config --images > /tmp/.docker/images_list.txt 2>/dev/null || true | ||
| if [ -s /tmp/.docker/images_list.txt ]; then | ||
| while IFS= read -r img || [ -n "$img" ]; do | ||
| [ -z "$img" ] && continue | ||
| filename=$(echo "$img" | tr '/:' '_' | tr -d ' ') | ||
| docker save "$img" -o "/tmp/.docker/${filename}.tar" 2>/dev/null || true | ||
| done < /tmp/.docker/images_list.txt | ||
| # Combine all image tars into one compressed archive | ||
| if ls /tmp/.docker/*.tar 1> /dev/null 2>&1; then | ||
| cd /tmp/.docker && tar -czf images.tar.gz *.tar && rm -f *.tar images_list.txt && mv images.tar.gz images.tar | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Cached images cannot be loaded correctlyThe save step creates individual tar files per image, then combines them into a compressed archive using Additional Locations (1) |
||
| fi | ||
| fi | ||
| - name: starts dependencies | ||
| run: | | ||
| mkdir -p test/output/otel | ||
|
|
@@ -70,6 +105,41 @@ jobs: | |
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| - name: Cache Docker images | ||
| uses: actions/cache@v4 | ||
| id: docker-cache | ||
| with: | ||
| path: /tmp/.docker | ||
| key: ${{ runner.os }}-docker-images-${{ hashFiles('test/docker-compose.yml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-docker-images- | ||
| - name: Load Docker images from cache | ||
| if: steps.docker-cache.outputs.cache-hit == 'true' | ||
| run: | | ||
| if [ -f /tmp/.docker/images.tar ]; then | ||
| docker load -i /tmp/.docker/images.tar | ||
| fi | ||
| - name: Pull Docker images | ||
| run: | | ||
| docker compose -f test/docker-compose.yml pull | ||
| - name: Save Docker images to cache | ||
| if: steps.docker-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| mkdir -p /tmp/.docker | ||
| # Get all images from docker-compose.yml and save them | ||
| # Use a temporary file to store images list to avoid subshell issues | ||
| docker compose -f test/docker-compose.yml config --images > /tmp/.docker/images_list.txt 2>/dev/null || true | ||
| if [ -s /tmp/.docker/images_list.txt ]; then | ||
| while IFS= read -r img || [ -n "$img" ]; do | ||
| [ -z "$img" ] && continue | ||
| filename=$(echo "$img" | tr '/:' '_' | tr -d ' ') | ||
| docker save "$img" -o "/tmp/.docker/${filename}.tar" 2>/dev/null || true | ||
| done < /tmp/.docker/images_list.txt | ||
| # Combine all image tars into one compressed archive | ||
| if ls /tmp/.docker/*.tar 1> /dev/null 2>&1; then | ||
| cd /tmp/.docker && tar -czf images.tar.gz *.tar && rm -f *.tar images_list.txt && mv images.tar.gz images.tar | ||
| fi | ||
| fi | ||
| - name: starts dependencies | ||
| run: | | ||
| mkdir -p test/output/otel | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Docker images pulled despite cache hit
The
docker compose pullcommand runs unconditionally, even when cached images are successfully loaded. This defeats the caching mechanism's purpose by always pulling images from the registry regardless of cache hits, negating any performance benefits from the cache.Additional Locations (1)
.github/workflows/test.yml#L121-L124