Skip to content

Commit 03c2e8d

Browse files
committed
fix failing build by pushing temp image for next step
1 parent e3759b6 commit 03c2e8d

1 file changed

Lines changed: 54 additions & 16 deletions

File tree

.github/workflows/build.yml

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,81 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
1215

1316
steps:
1417
- name: Checkout
1518
uses: actions/checkout@v4
1619

1720
- name: Set up Docker Buildx
1821
uses: docker/setup-buildx-action@v3
22+
23+
- name: Login to GHCR
24+
uses: docker/login-action@v3
1925
with:
20-
driver: docker
21-
# Use the plain 'docker' driver (instead of the default 'docker-container' driver
22-
# that is selected when 'platforms:' is specified). The docker driver makes local
23-
# image tags (canis-base:pr) from the previous step immediately visible to
24-
# subsequent FROM instructions in the same job. The container driver keeps
25-
# the image only in its internal cache, causing the next build to try to
26-
# pull "canis-base:pr" from Docker Hub (library/canis-base:pr) and fail with
27-
# "pull access denied".
28-
29-
# Build slim base (verification only — no push)
30-
- name: Build slim base
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Compute temporary tag (for PR verification only)
31+
id: temp
32+
run: |
33+
if [ "${{ github.event_name }}" = "pull_request" ]; then
34+
TEMP_TAG="pr-${{ github.event.pull_request.number }}-${{ github.sha }}"
35+
else
36+
TEMP_TAG="main-${{ github.sha }}"
37+
fi
38+
echo "temp_tag=$TEMP_TAG" >> $GITHUB_OUTPUT
39+
40+
# Build and push the slim base with a temporary tag.
41+
# This makes the base image available in GHCR so the tools step can pull it
42+
# via the build-arg (avoids local driver / local-tag visibility problems
43+
# and the cache-export limitation of the docker driver).
44+
- name: Build and push slim base (temporary tag)
3145
uses: docker/build-push-action@v6
3246
with:
3347
context: .
3448
file: Dockerfile
35-
push: false
36-
load: true
37-
tags: canis-base:pr
49+
platforms: linux/amd64
50+
push: true
51+
tags: |
52+
ghcr.io/datacite/canis-base:${{ steps.temp.outputs.temp_tag }}
53+
ghcr.io/datacite/canis-base:${{ github.sha }}
3854
cache-from: type=gha
3955
cache-to: type=gha,mode=max
4056

41-
# Build tools variant on top of the local base tag (verification only — no push)
57+
# Build the tools variant. It will resolve BASE_IMAGE from GHCR using the temp tag.
58+
# We do not push the tools image here (verification only).
4259
- name: Build tools variant
4360
uses: docker/build-push-action@v6
4461
with:
4562
context: .
4663
file: Dockerfile.tools
64+
platforms: linux/amd64
4765
push: false
4866
build-args: |
49-
BASE_IMAGE=canis-base:pr
67+
BASE_IMAGE=ghcr.io/datacite/canis-base:${{ steps.temp.outputs.temp_tag }}
5068
cache-from: type=gha
5169
cache-to: type=gha,mode=max
70+
71+
# Always attempt to delete the temporary base image after the build/checks
72+
# (whether the job passed or failed).
73+
- name: Cleanup temporary base image
74+
if: always()
75+
run: |
76+
TEMP_TAG="${{ steps.temp.outputs.temp_tag }}"
77+
echo "Attempting to delete temporary tag: $TEMP_TAG"
78+
# Find the version ID for this exact tag
79+
VERSION_ID=$(gh api \
80+
"/users/${{ github.repository_owner }}/packages/container/canis-base/versions" \
81+
--jq ".[] | select(.metadata.container.tags | index(\"$TEMP_TAG\")) | .id" 2>/dev/null || echo "")
82+
if [ -n "$VERSION_ID" ]; then
83+
echo "Deleting version ID $VERSION_ID"
84+
gh api -X DELETE \
85+
"/users/${{ github.repository_owner }}/packages/container/canis-base/versions/$VERSION_ID" \
86+
|| echo "Warning: delete may have failed or insufficient permissions (manual cleanup may be needed in the GitHub UI)"
87+
else
88+
echo "No matching version found for tag $TEMP_TAG"
89+
fi

0 commit comments

Comments
 (0)