-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: document starting from a docker tarfile base image (#345)
Co-authored-by: thesayyn <[email protected]>
- Loading branch information
Showing
12 changed files
with
177 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
image.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary") | ||
load("@container_structure_test//:defs.bzl", "container_structure_test") | ||
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") | ||
|
||
sh_binary( | ||
name = "convert", | ||
srcs = ["convert.bash"], | ||
data = [ | ||
"@oci_crane_registry_toolchains//:current_toolchain", | ||
"@oci_crane_toolchains//:current_toolchain", | ||
], | ||
) | ||
|
||
# Before building this example, you'll need to run ./create_base_image.bash to produce an | ||
# image.tar file. It's large so we .gitignore it. | ||
run_binary( | ||
name = "base", | ||
srcs = ["image.tar"], | ||
args = [ | ||
"$@", | ||
"$(location :image.tar)", | ||
"$(CRANE_BIN)", | ||
"$(LAUNCHER_WRAPPER)", | ||
], | ||
out_dirs = ["oci"], | ||
tool = ":convert", | ||
toolchains = [ | ||
"@oci_crane_toolchains//:current_toolchain", | ||
"@oci_crane_registry_toolchains//:current_toolchain", | ||
], | ||
) | ||
|
||
oci_image( | ||
name = "image", | ||
base = ":base", | ||
) | ||
|
||
oci_tarball( | ||
name = "tar", | ||
image = ":image", | ||
repo_tags = [], | ||
) | ||
|
||
container_structure_test( | ||
name = "test", | ||
configs = ["test.yaml"], | ||
image = ":image", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ubuntu:18.04 | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
ENV LC_ALL=C.UTF-8 \ | ||
LANG=C.UTF-8 \ | ||
LANGUAGE=C.UTF-8 | ||
|
||
RUN apt-get -y update \ | ||
&& apt-get -y install jq \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Convert a docker tarball as a base image | ||
|
||
In some cases, your legacy setup doesn't fetch a base image from a remote registry, instead you've produced your base image in a script and check or fetch the tarball. | ||
|
||
To generate the `image.tar` file, first run `create_base_image.bash`. Then build the example normally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
workspace(name = "custom_registry_example") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
local_repository( | ||
name = "rules_oci", | ||
path = "../../", | ||
) | ||
|
||
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies") | ||
|
||
rules_oci_dependencies() | ||
|
||
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains") | ||
|
||
oci_register_toolchains( | ||
name = "oci", | ||
crane_version = LATEST_CRANE_VERSION, | ||
) | ||
|
||
http_archive( | ||
name = "container_structure_test", | ||
sha256 = "2da13da4c4fec9d4627d4084b122be0f4d118bd02dfa52857ff118fde88e4faa", | ||
strip_prefix = "container-structure-test-1.16.0", | ||
urls = ["https://github.com/GoogleContainerTools/container-structure-test/archive/v1.16.0.zip"], | ||
) | ||
|
||
load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain") | ||
|
||
container_structure_test_register_toolchain(name = "st") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# Most rules_oci users will use oci_pull to fetch base layers from a remote registry. | ||
# However, you might build docker-format tarballs and uploaded them to Artifactory for example. | ||
# rules_oci expects an OCI format base image, so these need to be converted. | ||
# | ||
# This just requires push'ing the tarball into a locally-running registry which | ||
# understands both formats, then pull'ing back out in the oci format. | ||
# | ||
# Note, this is suboptimal because Bazel will still have to execute an action that has the entire | ||
# base image as an input. Large inputs cause network delays with remote execution. | ||
|
||
set -o pipefail -o errexit -o nounset | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
RUNFILES="$SCRIPT_DIR/$(basename $0).runfiles" | ||
|
||
TMP=$(mktemp -d) | ||
export HOME="$TMP" | ||
|
||
readonly OUTPUT="${1}" | ||
readonly TARBALL="${2}" | ||
readonly CRANE="${RUNFILES}/${3#"external/"}" | ||
readonly REGISTRY_LAUNCHER=${RUNFILES}/${4#"external/"} | ||
|
||
|
||
# Launch a registry instance at a random port | ||
source "${REGISTRY_LAUNCHER}" | ||
REGISTRY=$(start_registry $TMP $TMP/output.log) | ||
|
||
readonly REPOSITORY="${REGISTRY}/local" | ||
|
||
|
||
REF=$(mktemp) | ||
"${CRANE}" push "${TARBALL}" "${REPOSITORY}" --image-refs="${REF}" | ||
|
||
"${CRANE}" pull "$(cat $REF)" "${OUTPUT}" --format=oci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit -o nounset | ||
|
||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
|
||
# Export image | ||
docker build . -t temp --no-cache | ||
docker save temp -o image.tar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
schemaVersion: "2.0.0" | ||
|
||
metadataTest: | ||
envVars: | ||
- key: "LC_ALL" | ||
value: "C.UTF-8" | ||
- key: "LANG" | ||
value: "C.UTF-8" | ||
- key: "LANGUAGE" | ||
value: "C.UTF-8" | ||
entrypoint: [] | ||
cmd: ["/bin/bash"] | ||
|
||
commandTests: | ||
- name: "jq should be installed" | ||
command: "jq" | ||
expectedError: ["jq - commandline JSON processor"] | ||
exitCode: 2 | ||
|
||
fileExistenceTests: | ||
- name: "should not remove /var/lib/apt/lists" | ||
path: /var/lib/apt/lists | ||
shouldExist: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters