Skip to content

Commit b9bc15c

Browse files
levshamarko-k0
authored andcommitted
IDX-2857: wait for the artifact to be published.
1 parent 57ace6c commit b9bc15c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

bazel/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,9 @@ version_file_path(
136136
name = "version_file_path",
137137
visibility = ["//rs/tests:__subpackages__"],
138138
)
139+
140+
sh_binary(
141+
name = "sha256sum2url_sh",
142+
srcs = ["sha256sum2url.sh"],
143+
visibility = ["//visibility:public"],
144+
)

bazel/defs.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,25 @@ def _sha256sum2url_impl(ctx):
6161
"""
6262
Returns cas url pointing to the artifact with checksum specified.
6363
64-
The rule does not check existance of the artifact!
65-
Ensure that the corresponding rule that creates the artifact is remote cacheable!
64+
Waits for the artifact to be published before returning url.
6665
"""
6766
out = ctx.actions.declare_file(ctx.label.name)
6867
ctx.actions.run(
69-
executable = "awk",
70-
arguments = ["-v", "out=" + out.path, "-v", "base_url=" + ctx.attr.base_url, '{ printf "%s/cas/%s", base_url, $1 > out }', ctx.file.src.path],
68+
executable = ctx.executable._sha256sum2url_sh,
7169
inputs = [ctx.file.src],
7270
outputs = [out],
71+
env = {
72+
"SHASUMFILE": ctx.file.src.path,
73+
"OUT": out.path,
74+
},
7375
)
7476
return [DefaultInfo(files = depset([out]), runfiles = ctx.runfiles(files = [out]))]
7577

7678
sha256sum2url = rule(
7779
implementation = _sha256sum2url_impl,
7880
attrs = {
7981
"src": attr.label(allow_single_file = True),
80-
"base_url": attr.string(default = "http://artifacts.idx.proxy-global.dfinity.network:8080"),
82+
"_sha256sum2url_sh": attr.label(executable = True, cfg = "exec", default = "//bazel:sha256sum2url_sh"),
8183
},
8284
)
8385

bazel/sha256sum2url.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -eEuo pipefail
4+
5+
# TODO(IDX-2857): add timeout.
6+
7+
BASE_URL_DIRECT='https://artifacts.idx.dfinity.network'
8+
BASE_URL_PROXY='http://artifacts.idx.proxy-global.dfinity.network:8080'
9+
10+
SHASUM="$(cat "${SHASUMFILE}")"
11+
12+
DIRECT_URL="${BASE_URL_DIRECT}/cas/${SHASUM}"
13+
14+
while ! curl --head --fail "${DIRECT_URL}"; do
15+
sleep 5
16+
done
17+
18+
echo -n "${BASE_URL_PROXY}/cas/${SHASUM}" >"${OUT}"

0 commit comments

Comments
 (0)