Skip to content

Commit

Permalink
Rename .resolve targets (deprecated) to .lock targets.
Browse files Browse the repository at this point in the history
This makes the naming uniform across apko and rules_apko.
The old rules still exist, but emit a warning.
  • Loading branch information
sfc-gh-ptabor committed Dec 22, 2023
1 parent 3caa83f commit 7ff68b2
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ docs/*.md linguist-generated=true
docs/initial-setup.md linguist-generated=false
docs/apko-cache.md linguist-generated=false
MODULE.bazel.lock linguist-generated=true
**/apko.resolved.json linguist-generated=true
**/apko.lock.json linguist-generated=true
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docs/*.md
**/*.resolved.json
**/*.resolved.json
**/*.lock.json
8 changes: 4 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ apk = use_extension(
)
apk.translate_lock(
name = "examples_lock",
lock = "//examples/lock:apko.resolved.json",
lock = "//examples/lock:apko.lock.json",
)
apk.translate_lock(
name = "examples_wolfi_base",
lock = "//examples/wolfi-base:apko.resolved.json",
lock = "//examples/wolfi-base:apko.lock.json",
)
apk.translate_lock(
name = "examples_oci",
lock = "//examples/oci:apko.resolved.json",
lock = "//examples/oci:apko.lock.json",
)
apk.translate_lock(
name = "examples_multi_arch_and_repo",
lock = "//examples/multi_arch_and_repo:apko.resolved.json",
lock = "//examples/multi_arch_and_repo:apko.lock.json",
)
use_repo(apk, "examples_multi_arch_and_repo")
use_repo(apk, "examples_lock")
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ using the GitHub-provided source archive like
## Usage

Apko usage begins with an `apko.yaml` configuration file. The `apko resolve` tool will create a corresponding
`apko.resolved.json` file, and this is where Bazel will read to fetch external content.
Apko usage begins with an `apko.yaml` configuration file. The `apko lock` tool will create a corresponding
`apko.lock.json` file, and this is where Bazel will read to fetch external content.
Assuming `apko_rules` are already loaded in your `MODULE.bazel` or `WORKSPACE` file one can call:
`bazel run @rules_apko//apko resolve ./apko.yaml` to lock the dependencies and generate `apko.resolved.json` file.
`bazel run @rules_apko//apko lock ./apko.yaml` to lock the dependencies and generate `apko.lock.json` file.

Than you import these base layers into Bazel:

Expand All @@ -32,10 +32,10 @@ Than you import these base layers into Bazel:

Now you can use the `apko_image` rule to build the image, producing an OCI format output.
As long as the apko `.yaml` file is in the same directory as the `apko_image` you can periodically refresh the
`apko.resolved.json` file by just calling: `bazel run path/to/image.resolve`.
Alternatively you can call `apko resolve path/to/apko.yaml` or `bazel run @rules_apko//apko resolve path/to/apko.yaml`
to regenerate the `apko.resolved.json` file manually.
To resolve all the files in the repository, such a [snippet](./examples/resolve.sh) can be useful.
`apko.lock.json` file by just calling: `bazel run path/to/image.lock`.
Alternatively you can call `apko lock path/to/apko.yaml` or `bazel run @rules_apko//apko lock path/to/apko.yaml`
to regenerate the `apko.lock.json` file manually.
To resolve all the files in the repository, such a [snippet](./examples/lock.sh) can be useful.

Finally, we recommend using <https://github.com/bazel-contrib/rules_oci> as the next step in your Bazel build
to add application code from your repo as the next layers of the image.
Expand All @@ -46,5 +46,5 @@ Also see the `e2e` folder in this repository, where we declare our end-to-end te

## Public API

- [translate_lock](./docs/translate_lock.md) Repository rules for translating `apko.resolved.json`
- [translate_lock](./docs/translate_lock.md) Repository rules for translating `apko.lock.json`
- [rules](./docs/rules.md) Build OCI images from APK packages directly without `Dockerfile`
4 changes: 2 additions & 2 deletions apko/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ bzl_library(
)

# Enables calling apko tool directly by bazel.
# To resolve given `./apko.yaml` file into `./apko.resolved.json`, once can call:
# e.g. (cd ./examples/oci; bazel run @rules_apko//apko resolve ./apko.yaml)
# To resolve given `./apko.yaml` file into `./apko.lock.json`, once can call:
# e.g. (cd ./examples/oci; bazel run @rules_apko//apko lock ./apko.yaml)
apko_run(
name = "apko",
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion apko/private/apk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _apk_filegroup_impl(ctx):
apk_filegroup = rule(
implementation = _apk_filegroup_impl,
attrs = {
"lockfile": attr.label(doc = "Label to the `apko.resolved.json` file.", allow_single_file = True, mandatory = True),
"lockfile": attr.label(doc = "Label to the `apko.lock.json` file.", allow_single_file = True, mandatory = True),
"keyrings": attr.label_list(doc = "Labels of the keyring (public key) files.", allow_files = True, mandatory = True),
"apks": attr.label_list(doc = "Labels of the package (apk) files.", allow_files = True, mandatory = True),
"indexes": attr.label_list(doc = "Labels of the APKINDEX files.", allow_files = True, mandatory = True),
Expand Down
15 changes: 13 additions & 2 deletions apko/private/apko_image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def apko_image(name, contents, config, tag, output = "oci", architecture = None,
)
```
The label `@example_lock//:contents` is generated by the `translate_lock` extension, which consumes an 'apko.resolved.json' file.
The label `@example_lock//:contents` is generated by the `translate_lock` extension, which consumes an 'apko.lock.json' file.
For more details, refer to the [documentation](./docs/apko-cache.md).
An example demonstrating usage with [rules_oci](https://github.com/bazel-contrib/rules_oci)
Expand Down Expand Up @@ -145,8 +145,18 @@ def apko_image(name, contents, config, tag, output = "oci", architecture = None,
)
config_label = native.package_relative_label(config)

# We generate the `.resolve` target only if the config (apko.yaml file) is in the same package as the apko_image rule.
# We generate the `.lock` (or `.resolve`)s target only if the config (apko.yaml file) is in the same package as the apko_image rule.
if config_label.workspace_name == "" and config_label.package == native.package_name() and config_label.name.endswith(".yaml"):
lock_json_name = config_label.name.removesuffix(".yaml") + ".lock.json"

# We generate the .lock target only if the `.apko.lock.json` file exists in the same package.
for _ in native.glob([lock_json_name]):
apko_run(
name = name + ".lock",
args = ["lock", config_label.package + "/" + config_label.name],
workdir = "workspace",
)

resolved_json_name = config_label.name.removesuffix(".yaml") + ".resolved.json"

# We generate the .resolve target only if the `.apko.resolved.json` file exists in the same package.
Expand All @@ -155,4 +165,5 @@ def apko_image(name, contents, config, tag, output = "oci", architecture = None,
name = name + ".resolve",
args = ["resolve", config_label.package + "/" + config_label.name],
workdir = "workspace",
deprecated = "Please use .lock target instead. Rename your .resolve.json file to .lock.json file.",
)
6 changes: 3 additions & 3 deletions apko/translate_lock.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Repository rules for translating apko.resolved.json"""
"""Repository rules for translating apko.lock.json"""

load("//apko/private:util.bzl", "util")

_DOC = """Repository rule to generate starlark code from an `apko.resolved.json` file.
_DOC = """Repository rule to generate starlark code from an `apko.lock.json` file.
See [apko-cache.md](./apko-cache.md) documentation.
"""
Expand Down Expand Up @@ -64,7 +64,7 @@ APK_KEYRING_TMPL = """\
def _translate_apko_lock_impl(rctx):
lock_file = util.parse_lock(rctx.read(rctx.attr.lock))

# We copy the lockfile (.resolved.json) to avoid visibility problems when we reference it from another module.
# We copy the lockfile (.lock.json) to avoid visibility problems when we reference it from another module.
lock_file_local = "lockfile_copy"
rctx.symlink(rctx.attr.lock, lock_file_local)

Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md

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

4 changes: 2 additions & 2 deletions docs/translate_lock.md

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

2 changes: 1 addition & 1 deletion e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ apko = use_extension(
)
apko.translate_lock(
name = "example_lock",
lock = "//:apko.resolved.json",
lock = "//:apko.lock.json",
)
use_repo(apko, "example_lock")
2 changes: 1 addition & 1 deletion e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load("@rules_apko//apko:translate_lock.bzl", "translate_apko_lock")

translate_apko_lock(
name = "example_lock",
lock = "@//:apko.resolved.json",
lock = "@//:apko.lock.json",
)

load("@example_lock//:repositories.bzl", "apko_repositories")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/resolve.sh → examples/lock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set -e -x

TARGETS=$(bazel query 'filter(".resolve$", kind("apko_run", ...))')
TARGETS=$(bazel query 'filter(".lock", kind("apko_run", ...))')
for target in ${TARGETS}; do
bazel run "${target}"
done
Expand Down
2 changes: 1 addition & 1 deletion examples/lock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@rules_apko//apko:defs.bzl", "apko_image")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

# An example demonstrating how to use alpine packages with a lock file.
# See MODULE.bazel for how apko.resolved.json is translated to @examples_lock//:contents
# See MODULE.bazel for how apko.lock.json is translated to @examples_lock//:contents
apko_image(
name = "lock",
config = "apko.yaml",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/multi_arch_and_repo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@rules_apko//apko:defs.bzl", "apko_image")
load("@container_structure_test//:defs.bzl", "container_structure_test")

# An example demonstrating how to use multi architecture alpine packages with a lock file.
# See MODULE.bazel for how apko.resolved.json is translated to @examples_multi_arch_and_repo//:contents
# See MODULE.bazel for how apko.lock.json is translated to @examples_multi_arch_and_repo//:contents
apko_image(
name = "image",
architecture = select({
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/oci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@container_structure_test//:defs.bzl", "container_structure_test")

# An example demonstrating how to use apko_image with rules_oci
# See MODULE.bazel for how apko.resolved.json is translated to @examples_oci//:contents
# See MODULE.bazel for how apko.lock.json is translated to @examples_oci//:contents
apko_image(
name = "wolfi-base",
architecture = select({
Expand Down
36 changes: 18 additions & 18 deletions examples/oci/apko.resolved.json → examples/oci/apko.lock.json

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

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

2 changes: 1 addition & 1 deletion scripts/update_locks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ apko="$output_base/$external_apko"


for yaml in "./examples/"*"/apko.yaml" "./e2e/"*"/apko.yaml"; do
$apko resolve $yaml
$apko lock $yaml
done

0 comments on commit 7ff68b2

Please sign in to comment.