Skip to content

Commit

Permalink
feat: implement apko rule
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Sep 14, 2023
2 parents f3ed1c7 + bb22c85 commit 7053776
Show file tree
Hide file tree
Showing 60 changed files with 2,513 additions and 305 deletions.
6 changes: 6 additions & 0 deletions .apko/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by apko_bazelrc. DO NOT EDIT
# Required for range requests for fetching the apk packages.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
# Use https://www.base64decode.org/ to see what this base64 encoded command does.

common --credential_helper="%workspace%/.apko/range.sh"
4 changes: 4 additions & 0 deletions .apko/range.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo -n '{"headers":{"Range":['
cat | sed -n 's/.*#_apk_range_bytes_\([[:digit:]]*-[[:digit:]]*\).*/"bytes=\1"/p' | tr -d '\n'
echo ']}}'
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Required until this is the default; expected in Bazel 7
common --enable_bzlmod

# Required for rules_apko to make range requests
try-import %workspace%/.apko/.bazelrc

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
6.2.1
6.3.0
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
Expand Down
4 changes: 2 additions & 2 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "https://github.com/myorg/rules_mylang",
"homepage": "https://github.com/chainguard-dev/rules_apko",
"maintainers": [],
"repository": ["github:myorg/rules_mylang"],
"repository": ["github:chainguard-dev/rules_apko"],
"versions": [],
"yanked_versions": {}
}
2 changes: 1 addition & 1 deletion .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_mylang-{TAG}.tar.gz"
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_apko-{TAG}.tar.gz"
}
5 changes: 1 addition & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@ jobs:
]
exclude: |
[
{"folder": ".", "bzlmodEnabled": false},
{"bazelversion": "5.4.0", "bzlmodEnabled": true},
{"bazelversion": "5.4.0", "os": "macos-latest"},
{"bazelversion": "5.4.0", "os": "windows-latest"},
{"bazelversion": "5.4.0"}
]
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
release:
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v2
with:
release_files: rules_mylang-*.tar.gz
release_files: rules_apko-*.tar.gz
21 changes: 16 additions & 5 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set -o errexit -o nounset -o pipefail
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives
PREFIX="rules_mylang-${TAG:1}"
ARCHIVE="rules_mylang-$TAG.tar.gz"
PREFIX="rules_apko-${TAG:1}"
ARCHIVE="rules_apko-$TAG.tar.gz"
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

Expand All @@ -18,7 +18,7 @@ cat << EOF
2. Add to your \`MODULE.bazel\` file:
\`\`\`starlark
bazel_dep(name = "com_myorg_rules_mylang", version = "${TAG:1}")
bazel_dep(name = "rules_apko", version = "${TAG:1}")
\`\`\`
## Using WORKSPACE
Expand All @@ -28,12 +28,23 @@ Paste this snippet into your `WORKSPACE.bazel` file:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_myorg_rules_mylang",
name = "rules_apko",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/myorg/rules_mylang/releases/download/${TAG}/${ARCHIVE}",
url = "https://github.com/chainguard-dev/rules_apko/releases/download/${TAG}/${ARCHIVE}",
)
EOF

awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel
echo "\`\`\`"


cat << EOF
## Initial setup
rules_apko requires a one-time setup to configure bazel to be able to make partial fetches.
Follow https://github.com/chainguard-dev/rules_apko/blob/main/docs/initial-setup.md for the setup.
EOF
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@rules_apko//apko:defs.bzl", "apko_bazelrc")

apko_bazelrc()

gazelle_binary(
name = "gazelle_bin",
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ Run `bazel run //:gazelle` to keep them up-to-date.
## Using this as a development dependency of other rules

You'll commonly find that you develop in another WORKSPACE, such as
some other ruleset that depends on rules_mylang, or in a nested
some other ruleset that depends on rules_apko, or in a nested
WORKSPACE in the integration_tests folder.

To always tell Bazel to use this directory rather than some release
artifact or a version fetched from the internet, run this from this
directory:

```sh
OVERRIDE="--override_repository=rules_mylang=$(pwd)/rules_mylang"
OVERRIDE="--override_repository=rules_apko=$(pwd)/rules_apko"
echo "common $OVERRIDE" >> ~/.bazelrc
```

This means that any usage of `@rules_mylang` on your system will point to this folder.
This means that any usage of `@rules_apko` on your system will point to this folder.

## Releasing

Expand Down
29 changes: 23 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
"Bazel dependencies"

module(
name = "com_myorg_rules_mylang",
name = "rules_apko",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "aspect_bazel_lib", version = "1.34.5")

bazel_dep(name = "gazelle", version = "0.29.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.1.0", dev_dependency = True)

mylang = use_extension("//mylang:extensions.bzl", "mylang")
mylang.toolchain(mylang_version = "1.14.2")
use_repo(mylang, "mylang_toolchains")
toolchain = use_extension("//apko:extensions.bzl", "apko")
toolchain.toolchain(apko_version = "v0.0.0")
use_repo(toolchain, "apko_toolchains")

register_toolchains("@mylang_toolchains//:all")
register_toolchains("@apko_toolchains//:all")

# locks
lock = use_extension(
"//apko:extensions.bzl",
"apko",
dev_dependency = True,
)
lock.translate_lock(
name = "examples_lock",
lock = "//examples/lock:apko.lock.json",
)
lock.translate_lock(
name = "examples_wolfi_base",
lock = "//examples/wolfi-base:apko.lock.json",
)
use_repo(lock, "examples_lock")
use_repo(lock, "examples_wolfi_base")
Loading

0 comments on commit 7053776

Please sign in to comment.