Skip to content

Commit 8309c9a

Browse files
committed
Add "version-redirect.rkt" script for pruning global redirects
It's convenient for a release to just redirect all `releases/<vers>/installers` requests at `download.racket-lang.org` to `mirror.racket-lang.org`, but we can only link up to 50 versions that way through a bucket redirect rule. For old versions, make an indivudual bucket object for each redirection that should work (and there are a small number, because it's roughlyone per installer). For now, versions before v7.0 have been changed in this way, which buys us another 4 years or so before we run out of redirections again. Assuming no problems are desovered in the next year or so, we can turn it up to before v9.0, which will put off the problem for a decae or so. And we can keep turning up the version this way indefinitely in the future.
1 parent 1829622 commit 8309c9a

File tree

3 files changed

+1887
-1
lines changed

3 files changed

+1887
-1
lines changed

sync.rkt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#:jobs jobs
7777
#:log displayln))
7878

79+
#;
7980
(unless render-locally?
8081
(upload "www" "racket-lang.org")
8182
(upload "www" "www.racket-lang.org")
@@ -113,7 +114,10 @@
113114
#:redirect-code "302"
114115
#:new-protocol 'https)
115116
(for/list ([r (in-list all-releases)]
116-
#:when (version<=? "5.92" (release-version r)))
117+
;; when we run out of redirects (max is 50), this version number
118+
;; will need to be increased by running the "version-redirect.rkt"
119+
;; script
120+
#:when (version<=? "7.0" (release-version r)))
117121
(redirect-prefix-routing-rule #:old-prefix (format "releases/~a/installers" (release-version r))
118122
#:new-prefix (format "~ainstallers/~a"
119123
download-mirror-path

version-redirect.rkt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#lang racket/base
2+
3+
;; How to use this script:
4+
;;
5+
;; * Add new versions to "version-redirect.txt".
6+
;; The original context of that file was created by
7+
;; looking at a mirror of "mirror.racket-lang.org",
8+
;; which was made with
9+
;;
10+
;; wget --no-check-certificate -nv -m -X "/docs" --reject-regex ".*[?].*" \
11+
;; https://mirror.racket-lang.org/installers/
12+
;;
13+
;; and running `find .` to get the list, and then pruning
14+
;; some garbage.
15+
;;
16+
;; * Adjust the `redirect-before-version` definition below.
17+
;;
18+
;; The script will create new redirection objects, but it does not
19+
;; remove bucket-wide redirection rules that are meant to be covered
20+
;; by the added objects, so remove those manually via the S3 console.
21+
22+
(define redirect-before-version "7.0")
23+
24+
(define bucket "download.racket-lang.org")
25+
(define target "mirror.racket-lang.org")
26+
27+
(define bucket-pattern "releases/~a/installers")
28+
(define target-pattern "installers/~a")
29+
30+
(require version/utils
31+
racket/runtime-path
32+
aws/keys
33+
aws/s3)
34+
35+
(define-runtime-path version-redirect.txt "version-redirect.txt")
36+
37+
(define version+paths
38+
(call-with-input-file*
39+
version-redirect.txt
40+
(lambda (i)
41+
(for/list ([line (in-lines i)]
42+
#:do [(unless (regexp-match? #rx"^[.]/" line)
43+
(error 'redirect "bad line in \"version-redirect.txt\": ~s" line))
44+
(define elems (explode-path line))
45+
(define vers (path->string (cadr elems)))]
46+
#:when (version<? vers redirect-before-version)
47+
#:unless (equal? line (string-append "./" vers)))
48+
(list vers (substring line (+ 3 (string-length vers))))))))
49+
50+
version+paths
51+
52+
(with-handlers ([exn:fail? (lambda _ (ensure-have-keys))])
53+
(credentials-from-environment!))
54+
55+
(s3-host "s3.amazonaws.com")
56+
57+
(s3-region (bucket-location bucket))
58+
59+
(for ([version+path (in-list version+paths)])
60+
(define vers (car version+path))
61+
(define path (cadr version+path))
62+
(define redirect-to (format "https://~a/~a/~a" target (format target-pattern vers) path))
63+
(define bucket+path (format "~a/~a/~a" bucket (format bucket-pattern vers) path))
64+
(define data #"")
65+
(define mime-type "application/octet-stream")
66+
(define heads (hash 'x-amz-website-redirect-location redirect-to
67+
'x-amz-storage-class "REDUCED_REDUNDANCY"
68+
'x-amz-acl "public-read"))
69+
(printf "linking ~a to ~a\n" bucket+path redirect-to)
70+
(put/bytes bucket+path data mime-type heads))

0 commit comments

Comments
 (0)