Skip to content

Commit

Permalink
don't respect entrypoint after all
Browse files Browse the repository at this point in the history
Feels pretty confusing and weird. Dockerfiles don't respect them either.

I could see Bass respecting them if/when it supports directly running an
image like (run (linux/redis)).
  • Loading branch information
vito committed Apr 7, 2023
1 parent 8811fbe commit d40215e
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 84 deletions.
8 changes: 4 additions & 4 deletions bass/bass.bass
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
trim))

(defn remote [src]
(git-out src ($ remote get-url origin)))
(git-out src ($ git remote get-url origin)))

(defn latest-commit [src paths]
(git-out src ($ log -n1 "--pretty=format:%H" -- & $paths)))
(git-out src ($ git log -n1 "--pretty=format:%H" -- & $paths)))

(defn git-submodules [src]
(map (fn [[_ path]] (string->dir path))
(-> ($ config --file src/.gitmodules --get-regexp path)
(-> ($ git config --file src/.gitmodules --get-regexp path)
(with-image (linux/alpine/git))
(read :unix-table)
take-all))))
Expand Down Expand Up @@ -140,7 +140,7 @@
smoke-tests))

(def test-depot
(-> ($ init --cn bass --passphrase "")
(-> ($ certstrap init --cn bass --passphrase "")
(with-image (linux/squareup/certstrap))
(subpath ./out/)))

Expand Down
2 changes: 1 addition & 1 deletion demos/booklit/test-last-10.bass
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
booklit (load (latest/bass/booklit.bass))
commits (from (linux/alpine/git)
(cd latest
($ rev-list "HEAD~10..HEAD")))]
($ git rev-list "HEAD~10..HEAD")))]
(for [sha (read commits :lines)]
(let [src (git:github/vito/booklit/sha/ (string->dir sha))
ok? (succeeds? (booklit:tests src testflags))]
Expand Down
2 changes: 1 addition & 1 deletion demos/readme-prep.bass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; prefetch images used by readme demo so it's not too long

(run (from (linux/alpine/git)
($ --version)))
($ git --version)))

(run (from (linux/golang)
($ go version)))
2 changes: 1 addition & 1 deletion docs/lit/guide.lit
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ for common tasks. If you'd like to learn the language, see \reference{bassics}.

(def cloned
(from (linux/alpine/git)
($ clone "https://github.com/vito/bass" ./repo/)))
($ git clone "https://github.com/vito/bass" ./repo/)))

(go-build cloned/repo/ "./cmd/...")
}}}{
Expand Down
2 changes: 1 addition & 1 deletion docs/lit/index.lit
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ release}{https://github.com/vito/bass/releases/latest} and skim the
}{{{
; BAD
(from (linux/alpine/git)
($ clone "https://github.com/vito/bass" ./))
($ git clone "https://github.com/vito/bass" ./))
}}}{
If you run this thunk somewhere else it might return something different.
It'll also be cached forever, so you'll never get new commits.
Expand Down
12 changes: 8 additions & 4 deletions pkg/bass/thunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ type Thunk struct {
TLS *ThunkTLS `json:"tls,omitempty"`

// Entrypoint configures a static command and arguments that will be
// prepended to child commands.
// prepended to any command the published container runs.
//
// A nil value inherits from the parent. An empty slice removes it.
// A null value inherits from the parent. An empty slice removes it.
//
// Note that Bass thunks don't actually use the entrypoint themselves.
Entrypoint []string `json:"entrypoint,omitempty"`

// DefaultArgs configures a command and arguments to use if a child execution
// does not specify a command.
// DefaultArgs configures a command and arguments to used when the published
// container runs.
//
// Note that Bass thunks don't actually use the default args themselves.
DefaultArgs []string `json:"default_args,omitempty"`
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/runtimes/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,6 @@ func (b *buildkitBuilder) llb(
return ib, err
}

entrypoint := ib.config.Entrypoint

// propagate thunk's entrypoint to the child
if thunk.Entrypoint != nil { // note: nil vs. [] distinction
ib.config.Entrypoint = thunk.Entrypoint
Expand Down Expand Up @@ -793,8 +791,6 @@ func (b *buildkitBuilder) llb(
return ib, nil
}

cmd.Args = append(entrypoint, cmd.Args...)

cmdPayload, err := bass.MarshalJSON(cmd)
if err != nil {
return ib, err
Expand Down
21 changes: 21 additions & 0 deletions pkg/runtimes/dagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,31 @@ func (runtime *Dagger) container(ctx context.Context, thunk bass.Thunk) (*dagger
}

if cmd.Args != nil {
ep, err := ctr.Entrypoint(ctx)
if err != nil {
return nil, err
}

// Don't respect the entrypoint; this is way too confusing:
//
// (from (linux/alpine/git)
// ($ clone "https://github.com/vito/bass"))
//
// Bass thunks feel are similar to Dockerfiles, which also don't respect
// entrypoints.
if len(ep) > 0 {
ctr = ctr.WithEntrypoint(nil)
}

ctr = ctr.WithExec(cmd.Args, dagger.ContainerWithExecOpts{
Stdin: string(cmd.Stdin),
InsecureRootCapabilities: thunk.Insecure,
})

// Restore the entrypoint so it's still around when publishing.
if len(ep) > 0 {
ctr = ctr.WithEntrypoint(ep)
}
}

if thunk.Entrypoint != nil {
Expand Down
19 changes: 2 additions & 17 deletions pkg/runtimes/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,8 @@ func Suite(t *testing.T, config bass.RuntimeConfig) {
),
},
{
File: "entrypoints.bass",
Result: bass.Bindings{
"from-image": bass.String("git version 2.36.3\n"),
"unset-image": bass.String("git version 2.36.3\n"),
"from-thunk": bass.String(
"setting entrypoint\n" +
"using entrypoint\n" +
"using entrypoint again\n" +
"removing entrypoint\n" +
"no more entrypoint\n",
),
"from-thunk-scratch": bass.String(
"using entrypoint\n" +
"using entrypoint again\n" +
"no more entrypoint\n",
),
}.Scope(),
File: "entrypoints.bass",
Result: bass.Null{},
},
} {
test := test
Expand Down
99 changes: 51 additions & 48 deletions pkg/runtimes/testdata/entrypoints.bass
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
{:from-image
(-> (from (linux/alpine/git :2.36.3)
($ --version))
(read :raw)
next)
:unset-image
(-> (from (linux/alpine/git :2.36.3)
(with-entrypoint ($) [])
($ git --version))
(read :raw)
next)
:from-thunk
(-> (from (linux/alpine)
; set an entrypoint
(-> ($ sh -c "echo setting entrypoint >> out")
(with-entrypoint ["sh"]))

; use entrypoint
($ -c "echo using entrypoint >> out")
($ -c "echo using entrypoint again >> out")

; erase entrypoint
(-> ($ -c "echo removing entrypoint >> out")
(with-entrypoint []))

; use no entryopint
($ sh -c "echo no more entrypoint >> out"))
(subpath ./out)
(read :raw)
next)
:from-thunk-scratch
(-> (from (linux/alpine)
; set an entrypoint
(with-entrypoint ($) ["sh"])

; use entrypoint
($ -c "echo using entrypoint >> out")
($ -c "echo using entrypoint again >> out")

; erase entrypoint
(with-entrypoint ($) [])

; use no entryopint
($ sh -c "echo no more entrypoint >> out"))
(subpath ./out)
(read :raw)
next)
}
(defn tar-file [tar path]
(defn find-file [stream]
(let [file (next stream)
info (meta file)
name (path-name file)]
(if (= name path)
file
(find-file stream))))

(find-file (read tar :tar)))

(defn entrypoint [thunk]
(let [config-path (-> (tar-file (export thunk) "manifest.json")
(read :json)
next
first ; contains array of manifests
:Config
string->fs-path)
config (-> (tar-file (export thunk) (path-name config-path))
(read :json)
next
:config)]
(:Entrypoint config null)))

(def from-image
(from (linux/alpine/git :2.36.3)
($ git --version)))

(assert = "git version 2.36.3" (-> from-image (read :lines) next))
(assert = ["git"] (entrypoint from-image))

(def unset-image
(from (linux/alpine/git :2.36.3)
(with-entrypoint ($) [])
($ git --version)))

(assert = "git version 2.36.3"
(-> unset-image (read :lines) next))
(assert null? (entrypoint unset-image))

(def set-thunk
(from (linux/alpine)
(with-entrypoint ($) ["sh"])))

(assert = ["sh"] (entrypoint set-thunk))

(def keeps-entrypoint
(from set-thunk
($ echo "Hello, world!")))

(assert = ["sh"] (entrypoint keeps-entrypoint))
4 changes: 1 addition & 3 deletions std/git.bass
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
(def *git-image*
(case (next *stdin* :none)
:none (error "git image must be provided")
image (from image
; ignore any entrypoint, we just run regular git commands
(with-entrypoint ($) []))))
image image))

; resolves a ref to a sha at the remote repo
;
Expand Down

0 comments on commit d40215e

Please sign in to comment.