Skip to content

Commit f94d5ca

Browse files
Add more retries
1 parent 1d0a94a commit f94d5ca

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

.github/workflows/dump.yml

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ jobs:
3232
try {
3333
var token = "";
3434
var refresh = async () => {
35+
console.log("Authenticate against registry");
3536
var resp = await fetch("https://ghcr.io/token?service=registry.docker.io&scope=repository:${{ github.repository_owner }}/runner-images:pull,push", { method: "GET", redirect: "manual", credentials: "include", headers: {
3637
"Authorization": "Basic " + btoa("${{ github.actor }}:${{ github.token }}")
3738
} });
3839
console.log(JSON.stringify(resp.status));
3940
token = (await resp.json()).token;
4041
}
4142
if(process.env.UPLOAD_LAYER) {
43+
console.log("Uploading Layer");
4244
await refresh();
4345
var resp = await fetch("https://ghcr.io/v2/${{ github.repository_owner }}/runner-images/blobs/uploads/", { method: "POST", redirect: "manual", body: "", credentials: "include", headers: {
4446
"Authorization": "Bearer " + token
@@ -53,17 +55,34 @@ jobs:
5355
console.log(JSON.stringify(resp.status));
5456
location = resp.headers.get("Location");
5557
console.log("NEXT_URL:" + location);
56-
await refresh();
57-
var url = "https://ghcr.io" + location + "?digest=sha256:" + (await fs.promises.readFile("sha2.txt", { encoding: "utf-8" })).trim();
58-
console.log("url:" + url);
59-
resp = await fetch(url, { method: "PUT", redirect: "manual", duplex: "half", credentials: "include", headers: {
60-
"Content-Type": "application/octet-stream",
61-
"Content-Length": "0",
62-
"Authorization": "Bearer " + token
63-
} });
64-
console.log(JSON.stringify(resp.status));
65-
location = resp.headers.get("Location");
66-
console.log("NEXT_URL:" + location);
58+
console.log("Committing Layer");
59+
var commitLayer = async () => {
60+
await refresh();
61+
var url = "https://ghcr.io" + location + "?digest=sha256:" + (await fs.promises.readFile("sha2.txt", { encoding: "utf-8" })).trim();
62+
console.log("url:" + url);
63+
resp = await fetch(url, { method: "PUT", redirect: "manual", duplex: "half", credentials: "include", headers: {
64+
"Content-Type": "application/octet-stream",
65+
"Content-Length": "0",
66+
"Authorization": "Bearer " + token
67+
} });
68+
console.log(JSON.stringify(resp.status));
69+
location = resp.headers.get("Location");
70+
console.log("NEXT_URL:" + location);
71+
};
72+
var finish = false;
73+
var lastException = null;
74+
for(var i = 0; i < 10 && !finish; i++) {
75+
try {
76+
await commitLayer();
77+
finish = true;
78+
} catch(ex) {
79+
lastException = ex;
80+
console.log("Failed to commit to registry, attempt: " + i + " Cause: " + ex.toString());
81+
}
82+
}
83+
if(!finish) {
84+
throw lastException;
85+
}
6786
}
6887
clearInterval(token);
6988
@@ -410,8 +429,9 @@ jobs:
410429
- name: Dump gcc
411430
id: gcc
412431
run: |
413-
sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/gcc ${{ env.UP }}
432+
${{ env.CMD }} || ${{ env.CMD }}
414433
env:
434+
CMD: sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/gcc ${{ env.UP }}
415435
UPLOAD_LAYER: 1
416436
TAG: runner-gcc
417437
DIFF_IDS: |
@@ -426,8 +446,9 @@ jobs:
426446
- name: Dump llvm
427447
id: llvm
428448
run: |
429-
sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/llvm-* ${{ env.UP }}
449+
${{ env.CMD }} || ${{ env.CMD }}
430450
env:
451+
CMD: sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/llvm-* ${{ env.UP }}
431452
UPLOAD_LAYER: 1
432453
TAG: runner-llvm
433454
DIFF_IDS: |
@@ -444,8 +465,9 @@ jobs:
444465
- name: Dump firefox
445466
id: firefox
446467
run: |
447-
sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/firefox ${{ env.UP }}
468+
${{ env.CMD }} || ${{ env.CMD }}
448469
env:
470+
CMD: sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/firefox ${{ env.UP }}
449471
UPLOAD_LAYER: 1
450472
TAG: runner-firefox
451473
DIFF_IDS: |
@@ -460,8 +482,9 @@ jobs:
460482
- name: Dump python3
461483
id: python3
462484
run: |
463-
sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/python3 ${{ env.UP }}
485+
${{ env.CMD }} || ${{ env.CMD }}
464486
env:
487+
CMD: sudo tar -C / -c --no-recursion /usr /usr/lib --recursion /usr/lib/python3 ${{ env.UP }}
465488
UPLOAD_LAYER: 1
466489
TAG: runner-python3
467490
DIFF_IDS: |
@@ -476,8 +499,9 @@ jobs:
476499
- name: Dump android
477500
id: android
478501
run: |
479-
sudo tar -C / -c --no-recursion /usr /usr/local /usr/local/lib --recursion /usr/local/lib/android ${{ env.UP }}
502+
${{ env.CMD }} || ${{ env.CMD }}
480503
env:
504+
CMD: sudo tar -C / -c --no-recursion /usr /usr/local /usr/local/lib --recursion /usr/local/lib/android ${{ env.UP }}
481505
UPLOAD_LAYER: 1
482506
TAG: runner-usr-android
483507
DIFF_IDS: |
@@ -494,8 +518,9 @@ jobs:
494518
- name: Dump haskell
495519
id: haskell
496520
run: |
497-
sudo tar -C / -c --no-recursion /usr /usr/local --recursion /usr/local/.ghcup ${{ env.UP }}
521+
${{ env.CMD }} || ${{ env.CMD }}
498522
env:
523+
CMD: sudo tar -C / -c --no-recursion /usr /usr/local --recursion /usr/local/.ghcup ${{ env.UP }}
499524
UPLOAD_LAYER: 1
500525
TAG: runner-usr-haskell
501526
DIFF_IDS: |
@@ -512,8 +537,9 @@ jobs:
512537
- name: Dump powershell
513538
id: powershell
514539
run: |
515-
sudo tar -C / -c --no-recursion /usr /usr/local /usr/local/share --recursion /usr/local/share/powershell ${{ env.UP }}
540+
${{ env.CMD }} || ${{ env.CMD }}
516541
env:
542+
CMD: sudo tar -C / -c --no-recursion /usr /usr/local /usr/local/share --recursion /usr/local/share/powershell ${{ env.UP }}
517543
UPLOAD_LAYER: 1
518544
TAG: runner-usr-powershell
519545
DIFF_IDS: |
@@ -532,8 +558,9 @@ jobs:
532558
- name: Dump /snap
533559
id: snap
534560
run: |
535-
sudo tar -C / -c /snap ${{ env.UP }}
561+
${{ env.CMD }} || ${{ env.CMD }}
536562
env:
563+
CMD: sudo tar -C / -c /snap ${{ env.UP }}
537564
UPLOAD_LAYER: 1
538565
TAG: runner-snap
539566
DIFF_IDS: |

0 commit comments

Comments
 (0)