-
Notifications
You must be signed in to change notification settings - Fork 3
235 lines (193 loc) · 7.73 KB
/
test-load-docker-image.yml
File metadata and controls
235 lines (193 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Test Load Docker Image Action
on:
push:
paths:
- 'load-docker-image/**'
pull_request:
paths:
- 'load-docker-image/**'
workflow_dispatch:
jobs:
test-load-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Pull and save a test Docker image
run: |
docker pull nginx:alpine
docker save nginx:alpine -o nginx-alpine.tar
- name: Upload test image as artifact
uses: actions/upload-artifact@v4
with:
name: nginx-alpine.tar
path: nginx-alpine.tar
retention-days: 1
- name: Remove local image to test loading
run: docker rmi nginx:alpine
- name: Test basic usage
id: test-basic
uses: ./load-docker-image
with:
artifact-name: 'nginx-alpine.tar'
image-name: 'nginx'
tag: 'alpine'
- name: Verify basic test output
run: |
echo "Loaded image: ${{ steps.test-basic.outputs.loaded-image }}"
echo "Image ID: ${{ steps.test-basic.outputs.image-id }}"
echo "File size: ${{ steps.test-basic.outputs.file-size }}"
# Verify image is loaded
if ! docker images | grep -q "nginx.*alpine"; then
echo "❌ Error: Image not loaded correctly"
exit 1
fi
# Verify outputs are not empty
if [ -z "${{ steps.test-basic.outputs.loaded-image }}" ]; then
echo "❌ Error: loaded-image output is empty"
exit 1
fi
if [ -z "${{ steps.test-basic.outputs.image-id }}" ]; then
echo "❌ Error: image-id output is empty"
exit 1
fi
if [ -z "${{ steps.test-basic.outputs.file-size }}" ]; then
echo "❌ Error: file-size output is empty"
exit 1
fi
echo "✅ Basic test passed"
- name: Test custom image file location
run: |
# Create custom directory and save another image
mkdir -p custom-path
docker pull busybox:latest
docker save busybox:latest -o custom-path/busybox.tar
- name: Upload custom file test image
uses: actions/upload-artifact@v4
with:
name: busybox.tar
path: custom-path/busybox.tar
retention-days: 1
- name: Remove busybox image to test loading
run: docker rmi busybox:latest
- name: Test custom image-file usage
id: test-custom
uses: ./load-docker-image
with:
artifact-name: 'busybox.tar'
image-file: './custom-download/busybox-custom.tar'
image-name: 'busybox'
tag: 'latest'
- name: Verify custom image-file test
run: |
echo "Custom loaded image: ${{ steps.test-custom.outputs.loaded-image }}"
# Verify busybox image is loaded
if ! docker images | grep -q "busybox.*latest"; then
echo "❌ Error: Custom image-file image not loaded correctly"
exit 1
fi
# Verify the file was created at the specified location
if [ ! -f "./custom-download/busybox-custom.tar" ]; then
echo "❌ Error: Image file not found at specified location"
exit 1
fi
echo "✅ Custom image-file test passed"
- name: Test image verification
run: |
# Test that the loaded image works
docker run --rm nginx:alpine nginx -v
docker run --rm busybox:latest echo "BusyBox test successful"
echo "✅ Image verification test passed"
- name: Test summary
run: |
echo "## Test Results 🧪" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Basic usage test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Custom image-file test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Image verification test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Loaded Images" >> $GITHUB_STEP_SUMMARY
echo "- Basic test: \`${{ steps.test-basic.outputs.loaded-image }}\` (ID: ${{ steps.test-basic.outputs.image-id }})" >> $GITHUB_STEP_SUMMARY
echo "- Custom image-file test: \`${{ steps.test-custom.outputs.loaded-image }}\` (ID: ${{ steps.test-custom.outputs.image-id }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### File Details" >> $GITHUB_STEP_SUMMARY
echo "- Basic test file size: ${{ steps.test-basic.outputs.file-size }} bytes" >> $GITHUB_STEP_SUMMARY
echo "- Custom test file size: ${{ steps.test-custom.outputs.file-size }} bytes" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Additional Tests" >> $GITHUB_STEP_SUMMARY
echo "- Error handling test: See separate job" >> $GITHUB_STEP_SUMMARY
echo "- Skip download test: See separate job" >> $GITHUB_STEP_SUMMARY
test-error-handling:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Test with non-existent artifact (should fail)
id: test-error
continue-on-error: true
uses: ./load-docker-image
with:
artifact-name: 'non-existent-artifact'
- name: Verify error handling
run: |
if [ "${{ steps.test-error.outcome }}" = "success" ]; then
echo "❌ Error: Action should have failed with non-existent artifact"
exit 1
fi
echo "✅ Error handling test passed - action correctly failed with non-existent artifact"
test-skip-download:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create pre-existing image file
run: |
# Pull and save an image to simulate a pre-existing file
docker pull alpine:latest
mkdir -p ./pre-existing
docker save alpine:latest -o ./pre-existing/alpine.tar
docker rmi alpine:latest
- name: Test skip download functionality
id: test-skip-download
uses: ./load-docker-image
with:
download: 'false'
image-file: './pre-existing/alpine.tar'
image-name: 'alpine'
tag: 'latest'
- name: Verify skip download test
run: |
echo "Skip download loaded image: ${{ steps.test-skip-download.outputs.loaded-image }}"
# Verify alpine image is loaded
if ! docker images | grep -q "alpine.*latest"; then
echo "❌ Error: Skip download image not loaded correctly"
exit 1
fi
# Verify outputs are not empty
if [ -z "${{ steps.test-skip-download.outputs.loaded-image }}" ]; then
echo "❌ Error: loaded-image output is empty"
exit 1
fi
if [ -z "${{ steps.test-skip-download.outputs.image-id }}" ]; then
echo "❌ Error: image-id output is empty"
exit 1
fi
if [ -z "${{ steps.test-skip-download.outputs.file-size }}" ]; then
echo "❌ Error: file-size output is empty"
exit 1
fi
echo "✅ Skip download test passed"
- name: Test skip download with missing file (should fail)
id: test-skip-download-error
continue-on-error: true
uses: ./load-docker-image
with:
download: 'false'
image-file: './non-existent/missing.tar'
- name: Verify skip download error handling
run: |
if [ "${{ steps.test-skip-download-error.outcome }}" = "success" ]; then
echo "❌ Error: Action should have failed with missing file when download=false"
exit 1
fi
echo "✅ Skip download error handling test passed - action correctly failed with missing file"