adding in bazel build

Trying to get Bazel to build containers.
This commit is contained in:
Kyle Isom 2023-04-10 22:34:38 +00:00
parent 9f492fb42b
commit 660be935ef
9 changed files with 172 additions and 6 deletions

37
WORKSPACE Normal file
View File

@ -0,0 +1,37 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
## C++ dependencies
http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
build_file = "@//:gtest.BUILD",
)
## OCI
# see https://github.com/bazel-contrib/rules_oci/releases/tag/v0.3.9
http_archive(
name = "rules_oci",
sha256 = "f6125c9a123a2ac58fb6b13b4b8d4631827db9cfac025f434bbbefbd97953f7c",
strip_prefix = "rules_oci-0.3.9",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v0.3.9/rules_oci-v0.3.9.tar.gz",
)
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
rules_oci_dependencies()
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oci_register_toolchains")
oci_register_toolchains(
name = "oci",
crane_version = LATEST_CRANE_VERSION,
# Uncommenting the zot toolchain will cause it to be used instead of crane for some tasks.
# Note that it does not support docker-format images.
# zot_version = LATEST_ZOT_VERSION,
)
# Optional, for oci_tarball rule
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

2
packer/BUILD Normal file
View File

@ -0,0 +1,2 @@
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")

View File

@ -2,11 +2,12 @@
FROM ubuntu:22.04
LABEL org.opencontainers.image.authors=kyle@imap.cc
ONBUILD RUN apt-get update && apt-get install git bash
RUN apt-get update && apt-get -y install git curl sudo
RUN git clone https://git.wntrmute.dev/kyle/bladerunner
RUN bladerunner/tools/install-go.sh
ADD . packer
WORKDIR packer
RUN ./install-packer.sh
ENTRYPOINT ["/usr/bin/env", "bash"]

View File

@ -10,6 +10,7 @@ UPSTREAM="https://github.com/mkaczanowski/packer-builder-arm"
UPGRADE="false"
prep () {
sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools 'bsdtar|libarchive-tools'
mkdir -p build
pushd build
}
@ -40,7 +41,7 @@ install_packer_builder_arm () {
popd
}
cleanup {
cleanup () {
popd
}

33
tools/BUILD Normal file
View File

@ -0,0 +1,33 @@
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
# load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")
container_image(
name = "bladerunner/tools",
base = "@alpine_linux_amd64//image",
cmd = ["World"],
entrypoint = [
"echo",
"Hello",
],
env = {
"envVar": "My environment variable",
"xyz": "321",
},
files = [
"//extended/image_data:Data_file.txt",
"//extended/image_data:More_data.txt",
"//extended/image_data:file_to_copy.txt",
],
labels = {
"desc": "Description for version 7.7",
"version": "7.7",
},
symlinks = {
"/usr/More_data.txt": "/More_data.txt",
},
tars = ["//extended/image_data:tarfile.tar"],
volumes = [
"/myVol1",
"/usr/myVol2",
],
)

View File

@ -1,10 +1,10 @@
# Set up a packer image in Docker.
# Set up a container with the tooling installed.
FROM ubuntu:22.04
LABEL org.opencontainers.image.authors=kyle@imap.cc
RUN apt-get update && apt-get -y install git bash curl sudo
ADD . tools
RUN tools/install-dependencies.sh
RUN tools/install-go.sh
RUN tools/install-bazel.sh
ENTRYPOINT ["/usr/bin/env", "bash"]

64
tools/install-bazel.sh Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euxo pipefail
INSTALL_DIR="/usr/local/bin"
SUDO=sudo
preflight () {
if [ "$(whoami)" = "root" ]
then
SUDO=""
fi
}
bazel_setup () {
local BAZEL_BIN="$(command -v bazel)"
local BUILDIFIER_BIN="$(command -v buildifier)"
local BAZELISK_VERSION="1.16.0"
if [ "$(uname -s)" != "Linux" ]
then
echo '[!] godeb is only supported on Linux.' > /dev/stderr
exit 1
fi
case "$(uname -m)" in
amd64) ARCH="amd64" ;;
arm64) ARCH="arm64" ;;
x86_64) ARCH="amd64" ;;
*)
echo "[!] $(uname -m) is an unsupported architecture." > /dev/stderr
echo '[!] supported architectures: amd64, arm64' > /dev/stderr
exit 1
;;
esac
local BAZELISK_URL="https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VERSION}/bazelisk-linux-${ARCH}"
local BAZELISK_DBIN="${BAZELISK_URL##*/}"
if [ ! -x "${INSTALL_DIR}/bazelisk" ]
then
pushd /tmp
curl -LO "${BAZELISK_URL}"
chmod +x "${BAZELISK_DBIN}"
$SUDO mv "${BAZELISK_DBIN}" "${INSTALL_DIR}/bazelisk"
popd
fi
local BUILDTOOLS_REPO="https://github.com/bazelbuild/buildtools"
if [ ! -x "${INSTALL_DIR}/buildifier" ]
then
pushd /tmp
git clone "${BUILDTOOLS_REPO}"
pushd "${BUILDTOOLS_REPO##*/}"
bazelisk build //buildifier
sudo mv bazel-bin/buildifier/buildifier_/buildifier "${INSTALL_DIR}/buildifier"
popd
popd
fi
}
preflight
bazel_setup

21
tools/install-dependencies.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euxo pipefail
INSTALL_DIR="/usr/local/bin"
SUDO=sudo
preflight () {
if [ "$(whoami)" = "root" ]
then
SUDO=""
fi
}
apt_packages () {
$SUDO apt-get update
$SUDO apt-get -y install git bash curl sudo build-essential
}
preflight
apt_packages

7
tools/install.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euxo pipefail
./install-dependencies.sh
./install-go.sh
./install-bazel.sh