Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Aug 14, 2022
1 parent 8fd48e9 commit 1dd06ff
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 43 deletions.
69 changes: 52 additions & 17 deletions bass/bass.bass
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
(archive src (dist src version os arch) os arch))

(defn with-deps-and-shims [thunk src]
(let [only-shim (subgit src ./pkg/runtimes/ship/ ./Makefile ./go.mod ./go.sum)
(let [only-shim src ;(subgit src ./pkg/runtimes/shim/ ./Makefile ./go.mod ./go.sum)
built-shims (make-shims only-shim)]
(-> thunk
(with-mount src ./)
Expand Down Expand Up @@ -128,19 +128,52 @@
smoke-tests))

(def *buildkit-version* "v0.10.3")
(def *cni-version* "v1.1.1")

(def buildkitd
(from (linux/moby/buildkit (string->symbol *buildkit-version*))
(-> ($ buildkitd --addr "tcp://0.0.0.0:6107")
(with-mount (cache-dir "bass buildkitd") /var/lib/buildkit/)
(with-port :grpc 6107)
insecure!)))
(defn cni [os arch version]
(subpath
(from (linux/alpine)
($ apk add --no-cache curl)
($ curl -Ls
(str "https://github.com/containernetworking/plugins"
"/releases/download/" version
"/cni-plugins-" os "-" arch "-" version ".tgz")
-o ./cni.tgz))
./cni.tgz))

(defn cni-config [name subnet]
{:cniVersion "1.0.0"
:name name
:type "bridge"
:bridge (str name "0")
:isDefaultGateway true
:ipMasq true
:hairpinMode true
:ipam {:type "host-local",
:ranges [[{:subnet subnet}]]}})

(def prod-cni (cni-config "bass" "64.55.0.0/16"))
(def test-cni (cni-config "test" "73.57.0.0/16"))

(defn buildkitd [src]
(from (linux/moby/buildkit *buildkit-version*)
($ apk add --no-cache iptables)
($ mkdir -p /opt/cni/bin/ /etc/buildkit/)
($ tar -zxf (cni "linux" "amd64" *cni-version*) -C /opt/cni/bin/)
($ cp (mkfile ./cni.json (json prod-cni)) /etc/buildkit/cni.json)))

(defn test-buildkitd [src]
(-> (from (linux/moby/buildkit *buildkit-version*)
($ buildkitd --addr "tcp://0.0.0.0:6107"))
(with-mount (cache-dir "bass buildkitd") /var/lib/buildkit/)
(with-port :grpc 6107)
insecure!))

(defn with-bass-and-buildkitd [thunk src]
(let [built-bass (dist src "dev" "linux" "amd64")]
(let [buildkitd-host (addr (test-buildkitd src) :grpc "tcp://$host:$port")
built-bass (dist src "dev" "linux" "amd64")]
(-> thunk
; TODO: would be nice to set this one var rather than replace them all
(with-env {:BUILDKIT_HOST (addr buildkitd :grpc "tcp://$host:$port")})
(with-env {:BUILDKIT_HOST buildkitd-host})
(with-mount built-bass/bass /bin/bass)
(with-deps-and-shims src))))

Expand All @@ -152,17 +185,19 @@

; returns a thunk that runs the tests
(defn tests [src testflags]
(-> ($ gotestsum --format testname --no-color=false --jsonfile ./tests.log
--
-cover
-coverprofile ./cover.out
-covermode count
& $testflags)
(-> ($ go test & $testflags)
(with-bass-and-buildkitd src)))

; returns a thunk that will run the tests and return cover.html
(defn coverage [src testflags]
(from (tests src testflags)
(from (with-bass-and-buildkitd src)
($ gotestsum --format testname --no-color=false --jsonfile ./tests.log
--
-cover
-coverprofile ./cover.out
-covermode count
& $testflags)

; report slow tests
($ gotestsum tool slowest --jsonfile ./tests.log --threshold "500ms")

Expand Down
1 change: 1 addition & 0 deletions bass/buildkitd-image
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env bass
5 changes: 2 additions & 3 deletions bass/test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
; Emits code coverage to *stdout*.
(defn main testflags
(for [{:src src} *stdin*]
(let [tests (bass:coverage src ["./..." & testflags])]
(let [tests (bass:tests src testflags)]
(log "running tests")
(run tests)
(emit {:coverage tests/cover.html} *stdout*))))
(run tests))))
10 changes: 5 additions & 5 deletions demos/addrs.bass
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
; a simple server that returns a static index
(defn http-server [port index]
(defn http-server [index]
(from (linux/python)
(-> ($ python -m http.server (str port))
(-> ($ python -m http.server)
(with-mount (mkfile ./index.html index) ./index.html)
(with-port :http port))))
(with-port :http 8000))))

(defn main []
; construct a couple of server thunks (doesn't start them)
(let [hello (http-server 1111 "hello,")
world (http-server 2222 "world!")]
(let [hello (http-server "hello,")
world (http-server "world!")]
; curl both thunk addrs
;
; starts the two servers, waits for the ports to be ready, and resolves to
Expand Down
76 changes: 76 additions & 0 deletions demos/bass.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,79 @@ memos: {
}
}
}
memos: {
module: {
cmd: {
command: {
name: "git"
}
}
stdin: {
object: {
bindings: {
symbol: "repository"
value: {
string: {
value: "alpine/git"
}
}
}
bindings: {
symbol: "platform"
value: {
object: {
bindings: {
symbol: "os"
value: {
string: {
value: "linux"
}
}
}
}
}
}
bindings: {
symbol: "tag"
value: {
string: {
value: "latest"
}
}
}
bindings: {
symbol: "digest"
value: {
string: {
value: "sha256:760aaf0d59c93f87572ec40dee1efd10a7ea13a78dff1f59a904e908449329ae"
}
}
}
}
}
}
calls: {
binding: "ls-remote"
results: {
input: {
array: {
values: {
string: {
value: "https://github.com/vito/tabs"
}
}
values: {
string: {
value: "main"
}
}
}
}
output: {
string: {
value: "2f824aa1b2670bb9e11d6ca138e074b5d66e03a4"
}
}
}
}
}
Loading

0 comments on commit 1dd06ff

Please sign in to comment.