Commit Graph

40 Commits

Author SHA1 Message Date
Tianon Gravi fb05da102f Add support for submodules in gitfs
For now, these emulate the support that `git archive` has for them (namely, that they present as empty directories, which are otherwise impossible to create/represent in Git).
2025-08-12 13:57:33 -07:00
Tianon Gravi 4485636e95 Apply `gofmt` 2025-03-06 15:32:23 -08:00
Tianon Gravi 6505490e65 Rename "Example" tests to satisfy Go 1.24's new vet rule
In Go 1.24, there's a new `go vet` rule that complains about `Example*` test functions that don't follow the documented naming convention.  Combine that with `go test` running `go vet` by default, and you've got a perfect storm.

This renames our "example" tests to satisfy Go's naming convention.
2025-03-05 11:30:57 -08:00
Tianon Gravi 60ee93caf8 Simplify `pkg/dockerfile` interface by ditching pointer
This means slightly more typing in "zero-value" cases (`nil` vs `dockerfile.Metadata{}`), but the tradeoff is that it's simpler to use and reason about (and all the struct members are pointer-type map/slice values anyhow, so copying the struct is still pretty cheap).

This also swaps the scanner error handling to return the partially parsed Metadata object alongside the scanner error -- the error already tells us the object isn't fully complete data, so it's fair/fine to return and will likely just be ignored by the caller instead.  This also allows us to get to 100% code coverage. 👀

This also updates our "treat `oci-import` just like `FROM scratch`" code to *actually* parse `FROM scratch` so we can't accidentally cause "missing data" bugs there in the future, and I implemented that using `sync.OnceValues` which requires upgrading to Go 1.21, but IMO that's a worthwhile tradeoff (because `sync.OnceValues` makes that code so clean/simple).
2025-01-09 16:20:49 -08:00
Tianon Gravi 7ddf2bef73 Fix very minor continuation bugs for better coverage
There were some very minor/subtle bugs in how I implemented continuation that wouldn't affect any real-world parsing we did, but still bothered me because I'm me.  This fixes them (and further increases test coverage as a result).
2025-01-09 15:40:00 -08:00
Tianon Gravi 0e00438cf2 Implement parsing for `RUN --mount=type=bind,from=...` 2025-01-09 13:06:16 -08:00
Tianon Gravi 0c6df94b46 Move `Dockerfile` parsing to a dedicated package
Also, add a bunch of test cases / code coverage
2025-01-09 13:06:11 -08:00
Tianon Gravi 722f7d6464 Fix gitfs symlink handling
In my refactoring to use `go-git`'s `Tree` objects, I missed this edge case (that symlinks get resolved to be relative to the Git root, but our `Tree` object is a subdirectory).
2024-02-22 15:47:41 -08:00
Tianon Gravi b9a5bd8a9c Add test for sha256sum function 2024-01-22 09:46:30 -08:00
Tianon Gravi 1a4c6e83ab Add `sha256sum` template function
This is intentionally named and implemented to match the one in Sprig: https://masterminds.github.io/sprig/crypto.html
2024-01-19 16:42:52 -08:00
Tianon Gravi 795ff4ba45 Add better `ModTime` in `gitfs` and `ArchGitTime` helper (for `SOURCE_DATE_EPOCH`) 2024-01-12 13:13:45 -08:00
Tianon Gravi 2d67127dd1 Add `ArchGitChecksum` template command in `bashbrew cat`
This also finally adds `bashbrew context` as an explicit subcommand so that issues with this code are easier to test/debug (so we can generate the actual tarball and compare it to previous versions of it, versions generated by `git archive`, etc).

As-is, this currently generates verbatim identical checksums to 0cde8de57d/sources.sh (L90-L96) (by design).  We'll wait to do any cache bust there until we implement `Dockerfile`/context filtering:

```console
$ bashbrew cat varnish:stable --format '{{ .TagEntry.GitCommit }} {{ .TagEntry.Directory }}'
0c295b528f28a98650fb2580eab6d34b30b165c4 stable/debian
$ git -C "$BASHBREW_CACHE/git" archive 0c295b528f28a98650fb2580eab6d34b30b165c4:stable/debian/ | ./tar-scrubber | sha256sum
3aef5ac859b23d65dfe5e9f2a47750e9a32852222829cfba762a870c1473fad6
$ bashbrew cat --format '{{ .ArchGitChecksum arch .TagEntry }}' varnish:stable
3aef5ac859b23d65dfe5e9f2a47750e9a32852222829cfba762a870c1473fad6
```

(Choosing `varnish:stable` there because it currently has [some 100% valid dangling symlinks](6b1c6ffedc/stable/debian/scripts) that tripped up my code beautifully 💕)

From a performance perspective (which was the original reason for looking into / implementing this), running the `meta-scripts/sources.sh` script against `--all` vs this, my local system gets ~18.5m vs ~4.5m (faster being this new pure-Go implementation).
2024-01-12 13:13:42 -08:00
Tianon Gravi eeaf85b4d2 Add support for BASHBREW_BUILDKIT_SBOM_GENERATOR and provenance
Since Docker's image store can't represent these, we round trip them through our self-managed (or external) containerd image store, which also makes pushing more efficient.
2023-03-02 14:40:46 -08:00
Tianon Gravi 449eb48090 Add "path.Clean" and more comments in gitfs's "resolveSymlink" function 2022-12-16 09:09:58 -08:00
Tianon Gravi 99c15f44c2 Fix "gitfs"'s "Mode()" function and transparently follow symlinks 2022-12-15 11:42:13 -08:00
Tianon Gravi 0b7ae64b2f Add "Builder: oci-import" support
In the case of base images (`debian`, `alpine`, `ubuntu`, etc), using a `Dockerfile` as our method of ingestion doesn't really buy us very much.  It made sense at the time it was implemented ("all `Dockerfile`, all the time"), but at this point they're all some variation on `FROM scratch \n ADD foo.tar.xz / \n CMD ["/bin/some-shell"]`, and cannot reasonably be "rebuilt" when their base image changes (which is one of the key functions of the official images) since they _are_ the base images in question.

Functionally, consuming a tarball in this way isn't _that_ much different from consuming a raw tarball that's part of, say, an OCI image layout (https://github.com/opencontainers/image-spec/blob/v1.0.2/image-layout.md) -- it's some tarball plus some metadata about what to do with it.

For less trivial images, there's a significant difference (and I'm not proposing to use this for anything beyond simple one-layer base images), but for a single layer this would be basically identical.

As a more specific use case, the Debian `rootfs.tar.xz` files are currently [100% reproducible](https://github.com/debuerreotype/debuerreotype).  Unfortunately, some of that gets lost when it gets imported into Docker, and thus it takes some additional effort to get from the Docker-generated rootfs back to the original debuerreotype-generated file.

This adds the ability to consume an OCI image directly, to go even further and have a 100% fully reproducible image digest as well, which makes it easier to trace a given published image back to the reproducible source generated by the upstream tooling (especially if a given image is also pushed by the maintainer elsewhere).

Here's an example `oci-debian` file I was using for testing this:

    Maintainers: Foo (@bar)
    GitRepo: https://github.com/tianon/docker-debian-artifacts.git
    GitFetch: refs/heads/oci-arm32v5
    Architectures: arm32v5
    GitCommit: d6ac440e7760b6b16e3d3da6f2b56736b9c10065
    Builder: oci-import
    File: index.json

    Tags: bullseye, bullseye-20221114, 11.5, 11, latest
    Directory: bullseye/oci

    Tags: bullseye-slim, bullseye-20221114-slim, 11.5-slim, 11-slim
    Directory: bullseye/slim/oci
2022-12-15 11:42:10 -08:00
Tianon Gravi 143301cc9e Merge github.com/docker-library/go-dockerlibrary into bashbrew
This adjusts import paths, go.mod, and adds a new "Dockerfile.test" to run the unit tests.
2020-08-19 16:21:07 -07:00
Tianon Gravi 8e25067487 Update Go versions to 1.12 and 1.13
See https://golang.org/doc/go1.12#text/template, especially:

> If a user-defined function called by a template panics, the panic is now caught and returned as an error by the `Execute` or `ExecuteTemplate` method.
2019-12-10 16:36:34 -08:00
Tianon Gravi 57f0420223 Add new "getenv" templatelib function
Three usages:

- getenv "FOO"
- getenv "FOO" "default"
- getenv "FOO" "set" "unset"
2017-07-12 16:06:44 -07:00
Tianon Gravi 818247f8b4 Add examples/tests for "pkg/execpipe" (100% coverage!) 2017-04-03 15:02:26 -07:00
Tianon Gravi b7dd34a9b2 Update coverage in "pkg/templatelib" to 100% 2017-04-03 12:57:27 -07:00
Tianon Gravi 3da366f1ac Rename example functions so they actually show up 2017-04-03 12:29:03 -07:00
Tianon Gravi fa89a44b4d Rename example functions so they show up in godoc properly 2017-04-03 12:25:50 -07:00
Tianon Gravi 8177bb8839 Add some examples/tests for "pkg/templatelib" (94.9% coverage) 2017-04-03 12:20:49 -07:00
Tianon Gravi 273a3770eb Update "pkg/stripper" coverage to 100% with a smaller buffer size 2017-04-03 11:19:48 -07:00
Tianon Gravi 8e09786a2f Add an example of our CommentStripper that doubles as a test 2017-04-01 08:10:49 -07:00
Tianon Gravi 2406f9a744 Add some godocs for templatelib (mostly so I don't forget again how to use it, but also for others) 2017-02-20 11:07:45 -08:00
Tianon Gravi 945a488370 Rename "execpipe.New" to "execpipe.Run" so it's more clear that it invokes "Start" too 2016-06-24 17:31:43 -07:00
Tianon Gravi 449c8e950c Add new "execpipe" package for easily streaming the output of commands in a sane, simple "io.Reader" way 2016-06-24 17:09:19 -07:00
Tianon Gravi c98d0c2b3d Stop being a dummy reinventing the wheel and use template.IsTrue 2016-06-03 09:15:36 -07:00
Tianon Gravi 3db02d3b23 Add "empty string is false" to "ternary" 2016-06-02 20:41:21 -07:00
Tianon Gravi 5e6bbb37cb Make ternary more forgiving of "interesting" boolean-like values 2016-06-02 17:30:32 -07:00
Tianon Gravi 29dc82bbab More reflection tweaking 2016-06-02 17:23:48 -07:00
Tianon Gravi 032bdbe949 Use proper reflection instead of simple type switching 2016-06-02 17:21:11 -07:00
Tianon Gravi 5c8be71405 Generify some of the "action factory" logic in templatelib, thus allowing "first" and "last" to work on arbitrary types instead of just strings 2016-06-02 17:14:33 -07:00
Tianon Gravi e4fd05106a Screw it, let functions take only one argument instead of requiring two 2016-06-02 17:05:15 -07:00
Tianon Gravi e55c34e8a6 Add new "ternary" templatelib function 2016-06-02 17:01:09 -07:00
Tianon Gravi 939e8fc63d Fix minor typo 2016-06-02 16:49:58 -07:00
Tianon Gravi 369f346d90 Add a new "pkg/templatelib" package with the start of a simple text/template "stdlib" 2016-06-02 16:46:29 -07:00
Tianon Gravi c09c7f0323 Rename misc -> pkg (https://twitter.com/davecheney/status/733156157192175616) 2016-05-25 15:49:51 -07:00