Skip to content

Commit

Permalink
add formatting tests for go, markdown and yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmyers committed Jan 2, 2025
1 parent c30ab35 commit 0527483
Show file tree
Hide file tree
Showing 14 changed files with 685 additions and 103 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 0 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bazelbuild/setup-bazelisk@v1

# Setup Credential Helper to authenticate to Github Container Registry
- run: echo '{"credHelpers":{"ghcr.io":"ghcr"}}' > ~/.docker/config.json
- run: echo "${HOME}/.local/bin" >> $GITHUB_PATH
- run: mkdir -p ~/.local/bin
- run: echo -e "#!/usr/bin/env bash\n echo '{\"ServerURL\":\"ghcr.io\",\"Username\":\"Bearer\",\"Secret\":\"${{ secrets.GITHUB_TOKEN }}\"}'" > ~/.local/bin/docker-credential-ghcr
- run: chmod +x ~/.local/bin/docker-credential-ghcr

# Setup local toolchain
- run: bazel build --config=ci //go/cmd/ocitool:ocitool && cp bazel-bin/go/cmd/ocitool/ocitool_/ocitool bin/ocitool-linux-amd64

# Run all tests
- run: bazel test --config=ci //...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ bazel-rules_oci
bazel-testlogs

bin/ocitool-*

node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
1 change: 1 addition & 0 deletions .yamlfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude: ["pnpm-lock.yaml"]
31 changes: 15 additions & 16 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//oci:toolchain.bzl", "oci_local_toolchain")

# gazelle:prefix github.com/DataDog/rules_oci
# gazelle:go_naming_convention go_default_library
# gazelle:lang go

oci_local_toolchain(
name = "oci_local_toolchain",
)

buildifier(
name = "buildifier",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "fix",
npm_link_all_packages(
name = "node_modules",
)

buildifier_test(
name = "buildifier_test",
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
no_sandbox = True,
workspace = "//:WORKSPACE",
oci_local_toolchain(
name = "oci_local_toolchain",
)

gazelle(
Expand Down Expand Up @@ -54,3 +43,13 @@ write_source_files(
"bin/ocitool-linux-arm64": "//go/cmd/ocitool",
},
)

alias(
name = "format",
actual = "//tools/format",
)

exports_files(
["WORKSPACE"],
visibility = ["//visibility:public"],
)
27 changes: 25 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ module(
repo_name = "com_github_datadog_rules_oci",
)

bazel_dep(name = "aspect_rules_js", version = "2.1.2")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "aspect_rules_lint", version = "1.0.8")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "rules_go", version = "0.47.1")
bazel_dep(name = "rules_nodejs", version = "6.3.2")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "stardoc", version = "0.6.2")

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.6.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.5")
go_sdk.host()
go_sdk.download(
name = "go_sdk",
version = "1.22.5",
)
use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
Expand Down Expand Up @@ -68,3 +74,20 @@ oci_pull(
register_toolchains(
"@com_github_datadog_rules_oci//:oci_local_toolchain",
)

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
node.toolchain(node_version = "16.14.2")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")

# Allows developers to use the matching pnpm version, for example:
# bazel run -- @pnpm --dir $PWD install
use_repo(pnpm, "pnpm")
626 changes: 563 additions & 63 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ DEPEND ON FOR PRODUCTION USE-CASES.
A Bazel rule-set for extending, creating and publishing OCI artifacts, including image
manifests, image indexes (multi-arch images) and custom artifacts
([ORAS](https://github.com/oras-project)), with a focus on:
* **Speed**, only pulling artifacts that are needed at build-time (no more long image pull times)
* **Extensibility**, creating custom artifacts to leverage standard OCI distribution

- **Speed**, only pulling artifacts that are needed at build-time (no more long image pull times)
- **Extensibility**, creating custom artifacts to leverage standard OCI distribution
APIs
* **Multi-arch images**, compiling and building multi-arch images with a single Bazel invocation
- **Multi-arch images**, compiling and building multi-arch images with a single Bazel invocation

In addition to Bazel rules, we offer many helpers for interacting with OCI
artifacts under the `go/pkg` directory and a CLI tool for creating new OCI
Expand Down Expand Up @@ -67,27 +68,29 @@ in the image, but this trade-off is worth the speed of not downloaded many GBs o
base images.

### Roadmap
* [ ] Flesh out code for non-shallow pulls and cases where the layers are coming

- [ ] Flesh out code for non-shallow pulls and cases where the layers are coming
from a different registry.
* [ ] Full Starlark DSL for creating custom artifacts, it's currently looks
a bit wonky
* [ ] Support for the ORAS Artifact Spec
* [ ] Support for custom artifact crawlers to pull artifacts that have children
not represented by the OCI Image Spec. Ex pulling a full CNAB bundle and all
dependencies.
* [ ] Benchmark against `rules_docker` and raw `docker build`.
- [ ] Full Starlark DSL for creating custom artifacts, it's currently looks
a bit wonky
- [ ] Support for the ORAS Artifact Spec
- [ ] Support for custom artifact crawlers to pull artifacts that have children
not represented by the OCI Image Spec. Ex pulling a full CNAB bundle and all
dependencies.
- [ ] Benchmark against `rules_docker` and raw `docker build`.

### FAQ

**Comparison to `rules_docker`**
* `rules_docker` is built on `go-containerregistry`, which is focused on Docker,

- `rules_docker` is built on `go-containerregistry`, which is focused on Docker,
`rules_oci` uses `containerd` whose implementation complies more to the OCI spec
and more easily supports custom artifacts
* `rules_oci` focused on supporting the OCI Image spec, rather than the Docker
- `rules_oci` focused on supporting the OCI Image spec, rather than the Docker
spec
* `rules_oci` doesn't have language specific rules, instead a higher-level
- `rules_oci` doesn't have language specific rules, instead a higher-level
package can build on `rules_oci` to create rules like `go_image`
* `rules_docker` doesn't have support for multi-arch images [#1599](https://github.com/bazelbuild/rules_docker/issues/1599)
- `rules_docker` doesn't have support for multi-arch images [#1599](https://github.com/bazelbuild/rules_docker/issues/1599)

### Developing

Expand Down
2 changes: 1 addition & 1 deletion go/cmd/ocitool/createlayer_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/DataDog/rules_oci/go/internal/flagutil"
"github.com/DataDog/rules_oci/go/internal/tarutil"
"github.com/DataDog/rules_oci/go/pkg/ociutil"
"github.com/DataDog/rules_oci/go/pkg/layer"
"github.com/DataDog/rules_oci/go/pkg/ociutil"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/deb2layer/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
// TestDebToLayer checks that the expected files are in the resulting layer
// based on a deb file created by Bazel's rules_pkg
func TestDebToLayer(t *testing.T) {
// XXX Fix generating deb package
// XXX Fix generating deb package
f, err := os.Open("testdeb.deb")
if err != nil {
t.Fatalf("%v", err)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"prettier": "^3.4.2"
}
}
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun", "format_test")
load("@npm//:prettier/package_json.bzl", prettier = "bin")

package(default_visibility = ["//:__subpackages__"])

prettier.prettier_binary(
name = "prettier",
env = {
# Allow the binary to be run outside bazel
"BAZEL_BINDIR": ".",
},
fixed_args = [
"--log-level=warn",
],
)

format_multirun(
name = "format",
go = "@go_sdk//:bin/gofmt",
markdown = ":prettier",
starlark = "@buildifier_prebuilt//:buildifier",
yaml = "@aspect_rules_lint//format:yamlfmt",
)

format_test(
name = "format_test",
size = "small",
go = "@go_sdk//:bin/gofmt",
markdown = ":prettier",
no_sandbox = True,
starlark = "@buildifier_prebuilt//:buildifier",
workspace = "//:WORKSPACE",
yaml = "@aspect_rules_lint//format:yamlfmt",
)

0 comments on commit 0527483

Please sign in to comment.