diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..37d4609 --- /dev/null +++ b/WORKSPACE @@ -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() \ No newline at end of file diff --git a/packer/BUILD b/packer/BUILD new file mode 100644 index 0000000..3b79952 --- /dev/null +++ b/packer/BUILD @@ -0,0 +1,2 @@ +load("@io_bazel_rules_docker//container:container.bzl", "container_image") +load("@io_bazel_rules_docker//contrib:test.bzl", "container_test") \ No newline at end of file diff --git a/packer/Dockerfile b/packer/Dockerfile index 7187f4d..bc80bd8 100644 --- a/packer/Dockerfile +++ b/packer/Dockerfile @@ -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"] diff --git a/packer/install-packer.sh b/packer/install-packer.sh index bcee371..9492f8c 100755 --- a/packer/install-packer.sh +++ b/packer/install-packer.sh @@ -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 } diff --git a/tools/BUILD b/tools/BUILD new file mode 100644 index 0000000..8321b40 --- /dev/null +++ b/tools/BUILD @@ -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", + ], +) \ No newline at end of file diff --git a/tools/Dockerfile b/tools/Dockerfile index 040fd0d..4bc2dce 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -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"] diff --git a/tools/install-bazel.sh b/tools/install-bazel.sh new file mode 100755 index 0000000..1d05bfa --- /dev/null +++ b/tools/install-bazel.sh @@ -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 \ No newline at end of file diff --git a/tools/install-dependencies.sh b/tools/install-dependencies.sh new file mode 100755 index 0000000..45685d8 --- /dev/null +++ b/tools/install-dependencies.sh @@ -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 \ No newline at end of file diff --git a/tools/install.sh b/tools/install.sh new file mode 100755 index 0000000..d454b1f --- /dev/null +++ b/tools/install.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +./install-dependencies.sh +./install-go.sh +./install-bazel.sh \ No newline at end of file