Skip to content

Commit

Permalink
docs: stop using (with-label) for cache busting
Browse files Browse the repository at this point in the history
this was always a decision of convenience, doesn't make sense when
they're more useful as image metadata, which shouldn't bust caches
  • Loading branch information
vito committed Apr 17, 2023
1 parent 1d3056e commit 7b019b6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion demos/hello.bass
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(defn main [lines]
(-> ($ sh -c "for i in $(seq 1 $0); do echo line $i; sleep 0.5; done" $lines)
(with-label :start (now 0))
(with-env {:START (now 0)})
(with-image (linux/alpine))
run))
4 changes: 3 additions & 1 deletion demos/multi-fail.bass
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(defn echo-sleep-exit [msg seconds exit-code]
(subpath
(from (linux/alpine)
(with-label ($ sleep (str seconds)) :at (now 0))
(with-env
($ sleep (str seconds))
{:AT (now 0)})
($ sh -c (str "echo \"$0\"; exit " exit-code) $msg))
./))

Expand Down
2 changes: 1 addition & 1 deletion demos/speedtest.bass
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(defn speedtest []
(from (speedtest-cli)
(-> ($ speedtest --accept-license --format json-pretty)
(with-label :at (now 0)))))
(with-env {:NOW (now 0)}))))

(defn main []
(let [results (next (read (speedtest) :json))]
Expand Down
18 changes: 9 additions & 9 deletions docs/lit/guide.lit
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ for common tasks. If you'd like to learn the language, see \reference{bassics}.
Thunks are cached forever. They can be cleared with \code{bass --prune},
but this should only be necessary for regaining disk space.
}{
To influence caching, use \b{with-label} to stamp thunks with arbitrary
data. Two thunks that differ only in labels will be cached independently.
If you want to run a cache multiple times, just set a random value as an
environment variable:
}{{{
(run (with-label
(run (with-env
(from (linux/alpine)
($ echo "Hello, world!"))
:foo "bar"))
($ echo "Hi again!"))
{:NOW (now 0)}))
}}}{
Tip: to avoid deep nesting like above, consider the alternative \b{->}
form.
}{{{
(-> ($ echo "Hello, world!")
(-> ($ echo "Hi again!")
(with-image (linux/alpine))
(with-label :foo "bar")
(with-env {:NOW (now 0)})
run)
}}}
}
Expand Down Expand Up @@ -181,8 +181,8 @@ for common tasks. If you'd like to learn the language, see \reference{bassics}.

(defn counter [tag]
(from (linux/alpine)
(-> ($ sh -c "echo x >> /var/cache/file; cat /var/cache/file | wc -l")
(with-label :tag tag)
(-> ($ sh -c "echo $0 >> /var/cache/file; cat /var/cache/file | wc -l"
$tag)
(with-mount my-cache /var/cache/))))

(defn count [tag]
Expand Down
2 changes: 1 addition & 1 deletion docs/lit/index.lit
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ release}{https://github.com/vito/bass/releases/latest} and skim the
(defn ls-remote [repo ref & timestamp]
(-> ($ git ls-remote $repo $ref)
(with-image *git-image*)
(with-label :at (now 60)) ; rerun every minute
(with-env {:MINUTE (now 60)}) ; rerun every minute
(read :unix-table) ; line and space separated table output
next ; first row : <ref> <sha>
first)) ; first column: <ref>
Expand Down
3 changes: 2 additions & 1 deletion pkg/bass/ground.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ func init() {
Ground.Set("with-label",
Func("with-label", "[thunk name val]", (Thunk).WithLabel),
`returns thunk with the label set to val`,
`Labels are typically used to control caching. Two thunks that differ only in labels will evaluate separately and produce independent results.`,
`Labels are used to set metadata on a thunk, and are not used by the thunk itself.`,
`When the thunk is exported or published, labels will be included in the OCI image.`,
`=> (with-label ($ sleep 10) :at (now 10))`)

Ground.Set("with-port",
Expand Down
4 changes: 3 additions & 1 deletion pkg/runtimes/testdata/sleep.bass
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
(run (-> ($ sleep "999") (with-label :now (now 1)) (with-image (linux/alpine))))
(run (-> ($ sleep "999")
(with-env {:RANDOM (str *random*)})
(with-image (linux/alpine))))
2 changes: 1 addition & 1 deletion std/git.bass
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(defn ls-remote [repo ref & timestamp]
(-> ($ git ls-remote $repo $ref)
(with-image *git-image*)
(with-label :at (if (empty? timestamp) (now 0) (first timestamp)))
(with-env {:TIME (if (empty? timestamp) (now 0) (first timestamp))})
(read :unix-table)
next
first))
Expand Down

0 comments on commit 7b019b6

Please sign in to comment.