-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: add dockerfile build (#570)
- Loading branch information
Showing
15 changed files
with
135 additions
and
130 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
load("@aspect_bazel_lib//lib:run_binary.bzl", "run_binary") | ||
load("@bazel_skylib//rules:native_binary.bzl", "native_binary") | ||
load("@container_structure_test//:defs.bzl", "container_structure_test") | ||
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") | ||
|
||
native_binary( | ||
name = "buildx", | ||
src = select({ | ||
"@bazel_tools//src/conditions:linux_x86_64": "@buildx_linux_amd64//file", | ||
"@bazel_tools//src/conditions:darwin_arm64": "@buildx_darwin_arm64//file", | ||
"@bazel_tools//src/conditions:darwin_x86_64": "@buildx_darwin_amd64//file", | ||
}), | ||
out = "buildx", | ||
) | ||
|
||
# docker buildx create --name container --driver=docker-container | ||
run_binary( | ||
name = "base", | ||
srcs = ["Dockerfile"] + glob(["src/*"]), | ||
args = [ | ||
"build", | ||
"./examples/dockerfile", | ||
"--builder", | ||
"container", | ||
"--output=type=oci,tar=false,dest=$@", | ||
], | ||
execution_requirements = {"local": "1"}, | ||
out_dirs = ["base"], | ||
target_compatible_with = [ | ||
"@platforms//os:linux", | ||
], | ||
tool = ":buildx", | ||
) | ||
|
||
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
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,17 @@ | ||
# Dockerfile + rules_oci | ||
|
||
STOP before committing this atrocity. Here's some good reasons why you should not do what we have done here. | ||
|
||
- Dockerfiles are fundamentally non-reproducible | ||
- Reproducible builds are important for Bazel, Dockerfiles will lead to poor cache hits. | ||
- `RUN` instruction is a perfect foot-gun for non-reprocubile builds, a simple command `RUN apt-get install curl` is non-hermetic by default. | ||
- Building the same Dockerfile one month apart will yield different results. | ||
- `FROM python:3.11.9-bullseye` is non-producible. | ||
|
||
# Resources | ||
|
||
https://reproducible-builds.org/ | ||
https://github.com/bazel-contrib/rules_oci/issues/35#issuecomment-1285954483 | ||
https://github.com/bazel-contrib/rules_oci/blob/main/docs/compare_dockerfile.md | ||
https://github.com/moby/moby/issues/43124 | ||
https://medium.com/nttlabs/bit-for-bit-reproducible-builds-with-dockerfile-7cc2b9faed9f |
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,31 @@ | ||
"repos for buildx" | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") | ||
|
||
def fetch_buildx(): | ||
http_file( | ||
name = "buildx_linux_amd64", | ||
urls = [ | ||
"https://github.com/docker/buildx/releases/download/v0.14.0/buildx-v0.14.0.linux-amd64", | ||
], | ||
integrity = "sha256-Mvjxfso1vy7+bA5H9A5Gkqh280UxtCHvyYR5mltBIm4=", | ||
executable = True, | ||
) | ||
|
||
http_file( | ||
name = "buildx_darwin_arm64", | ||
urls = [ | ||
"https://github.com/docker/buildx/releases/download/v0.14.0/buildx-v0.14.0.darwin-arm64", | ||
], | ||
integrity = "sha256-3BdvI2ZgnMITKubwi7IZOjL5/ZNUv9Agz3+juNt0hA0=", | ||
executable = True, | ||
) | ||
|
||
http_file( | ||
name = "buildx_darwin_amd64", | ||
urls = [ | ||
"https://github.com/docker/buildx/releases/download/v0.14.0/buildx-v0.14.0.darwin-amd64", | ||
], | ||
integrity = "sha256-J6rZfENSvCzFBHDgnA8Oqq2FDXR+M9CTejhhg9DruPU=", | ||
executable = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import cowsay | ||
|
||
cowsay.cow('moo!') |
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