57
57
org.opencontainers.image.vendor=TryGhost
58
58
maintainer=TryGhost
59
59
60
+ - name : Determine build strategy
61
+ id : strategy
62
+ run : |
63
+ IS_FORK_PR="false"
64
+ if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then
65
+ IS_FORK_PR="true"
66
+ fi
67
+ echo "is-fork-pr=$IS_FORK_PR" >> $GITHUB_OUTPUT
68
+ echo "should-push=${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}" >> $GITHUB_OUTPUT
69
+ echo "should-load=$IS_FORK_PR" >> $GITHUB_OUTPUT
70
+
71
+ echo "Build strategy determined:"
72
+ echo "- Is fork PR: $IS_FORK_PR"
73
+ echo "- Should push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}"
74
+ echo "- Should load: $IS_FORK_PR"
75
+
60
76
- name : Display Docker metadata
61
77
run : |
62
78
echo "Generated tags:"
72
88
context : .
73
89
file : .docker/Dockerfile
74
90
# Only push on main branch or PRs from the main repo (not forks)
75
- push : ${{ github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
91
+ push : ${{ steps.strategy.outputs.should-push }}
76
92
# Only load image on PRs from forks (to allow testing without pushing)
77
- load : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
93
+ load : ${{ steps.strategy.outputs.should-load }}
78
94
tags : ${{ steps.meta.outputs.tags }}
79
95
labels : ${{ steps.meta.outputs.labels }}
80
96
# On PRs: use both main cache and PR-specific cache
@@ -83,12 +99,29 @@ jobs:
83
99
type=registry,ref=${{ steps.cache.outputs.image }}:cache-main
84
100
${{ github.event_name == 'pull_request' && format('type=registry,ref={0}:cache-pr-{1}', steps.cache.outputs.image, github.event.pull_request.number) || '' }}
85
101
# Only export cache if we can push (not on fork PRs)
86
- cache-to : ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && format('type=registry,ref={0}:cache-{1},mode=max', steps.cache.outputs.image, github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'main') || '' }}
102
+ cache-to : ${{ steps.strategy.outputs.should-push == 'true' && format('type=registry,ref={0}:cache-{1},mode=max', steps.cache.outputs.image, github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || 'main') || '' }}
103
+
104
+ - name : Save image as artifact (fork PR)
105
+ if : steps.strategy.outputs.is-fork-pr == 'true'
106
+ run : |
107
+ IMAGE_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1)
108
+ echo "Saving image: $IMAGE_TAG"
109
+ docker save "$IMAGE_TAG" | gzip > docker-image.tar.gz
110
+ echo "Image saved as docker-image.tar.gz"
111
+ ls -lh docker-image.tar.gz
112
+
113
+ - name : Upload image artifact (fork PR)
114
+ if : steps.strategy.outputs.is-fork-pr == 'true'
115
+ uses : actions/upload-artifact@v4
116
+ with :
117
+ name : docker-image
118
+ path : docker-image.tar.gz
119
+ retention-days : 1
87
120
88
121
outputs :
89
122
image-tags : ${{ steps.meta.outputs.tags }}
90
123
image-digest : ${{ steps.build.outputs.digest }}
91
- is-fork : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
124
+ is-fork : ${{ steps.strategy.outputs.is-fork-pr }}
92
125
test :
93
126
needs : build
94
127
runs-on : ubuntu-latest-16-cores
@@ -97,6 +130,20 @@ jobs:
97
130
- name : Set up Docker Buildx
98
131
uses : docker/setup-buildx-action@v3
99
132
133
+ - name : Download image artifact (fork PR)
134
+ if : needs.build.outputs.is-fork == 'true'
135
+ uses : actions/download-artifact@v4
136
+ with :
137
+ name : docker-image
138
+
139
+ - name : Load image from artifact (fork PR)
140
+ if : needs.build.outputs.is-fork == 'true'
141
+ run : |
142
+ echo "Loading Docker image from artifact..."
143
+ gunzip -c docker-image.tar.gz | docker load
144
+ echo "Available images after load:"
145
+ docker images
146
+
100
147
- name : Log in to GitHub Container Registry
101
148
if : needs.build.outputs.is-fork == 'false'
102
149
uses : docker/login-action@v3
@@ -119,21 +166,26 @@ jobs:
119
166
echo "Pulling image from registry..."
120
167
docker pull ${{ steps.image.outputs.tag }}
121
168
122
- - name : List available images (fork PR)
123
- if : needs.build.outputs.is-fork == 'true'
124
- run : |
125
- echo "Images loaded locally:"
126
- docker images
127
- echo "Looking for image: ${{ steps.image.outputs.tag }}"
128
-
129
169
- name : Verify image is available
130
170
run : |
131
- if docker inspect ${{ steps.image.outputs.tag }} > /dev/null 2>&1; then
132
- echo "✅ Image ${{ steps.image.outputs.tag }} is available"
171
+ IMAGE_TAG="${{ steps.image.outputs.tag }}"
172
+ echo "Checking for image: $IMAGE_TAG"
173
+
174
+ if docker inspect "$IMAGE_TAG" > /dev/null 2>&1; then
175
+ echo "✅ Image $IMAGE_TAG is available"
176
+ echo "Image details:"
177
+ docker inspect "$IMAGE_TAG" --format='{{.Id}} {{.Created}}'
133
178
else
134
- echo "❌ Image ${{ steps.image.outputs.tag }} is not available"
179
+ echo "❌ Image $IMAGE_TAG is not available"
135
180
echo "Available images:"
136
181
docker images
182
+
183
+ # For fork PRs, the image might have been loaded with a different tag
184
+ if [ "${{ needs.build.outputs.is-fork }}" = "true" ]; then
185
+ echo ""
186
+ echo "Searching for any loaded Ghost images..."
187
+ docker images --format "table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}" | grep -E "(ghost|Ghost)" || echo "No Ghost images found"
188
+ fi
137
189
exit 1
138
190
fi
139
191
0 commit comments