From ab80e72047dd0ce7fc18e874a2712074908c2d7b Mon Sep 17 00:00:00 2001 From: Ivan Subotic <400790+subotic@users.noreply.github.com> Date: Mon, 31 Jan 2022 08:36:34 +0100 Subject: [PATCH] build: add support for building native API and Fuseki Docker images on Apple M1 (DEV-435) (#1987) --- WORKSPACE | 102 ++++++++++++++------------- docker/knora-api/BUILD.bazel | 5 +- docker/knora-jena-fuseki/BUILD.bazel | 6 +- third_party/versions.bzl | 3 +- 4 files changed, 64 insertions(+), 52 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index f948654159..7d0066630a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,6 +16,42 @@ http_archive( url = "https://github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib-{}.tar.gz".format(skylib_version, skylib_version), ) +##################################### +# Buildifier # +##################################### +# buildifier is written in Go and hence needs rules_go to be built. +# See https://github.com/bazelbuild/rules_go for the up to date setup instructions. +http_archive( + name = "io_bazel_rules_go", + sha256 = "d6b2513456fe2229811da7eb67a444be7785f5323c6708b38d851d2b51e54d83", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip", + ], +) + +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +go_rules_dependencies() + +go_register_toolchains(version = "1.17.6") + +http_archive( + name = "bazel_gazelle", + sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", + ], +) + +# bazel buildtools providing buildifier +http_archive( + name = "com_github_bazelbuild_buildtools", + strip_prefix = "buildtools-master", + url = "https://github.com/bazelbuild/buildtools/archive/master.zip", +) + ##################################### # Docker # ##################################### @@ -48,26 +84,25 @@ load( "container_pull", ) -# get distroless java +# get openjdk container_pull( - name = "java_base", - # 'tag' is also supported, but digest is encouraged for reproducibility. - digest = "sha256:deadbeef", - registry = "gcr.io", - repository = "distroless/java", + name = "openjdk11_amd64", + digest = "sha256:967349ef166d630bceda0370507b096edd6e7220e62e4539db70f04c04c2295f", # 7.01.2022 + registry = "docker.io", + repository = "eclipse-temurin", + # tag = "11-jre-focal", # Ubuntu 20.04 ) -# get openjdk container_pull( - name = "openjdk11", - digest = "sha256:14605eb0f24ce726e13c4a85862325083dee3ab13da847b7af20d0df5966c176", # 29.11.2021 + name = "openjdk11_arm64", + digest = "sha256:e46fac3005d08732931de9671864683f6adf3a3eb0f8a7e8ac27d1bff1955a5c", # 7.01.2022 registry = "docker.io", repository = "eclipse-temurin", # tag = "11-jre-focal", # Ubuntu 20.04 ) # get sipi -load("//third_party:versions.bzl", "FUSEKI_IMAGE_DIGEST", "FUSEKI_REPOSITORY", "SIPI_IMAGE_DIGEST", "SIPI_REPOSITORY") +load("//third_party:versions.bzl", "FUSEKI_IMAGE_DIGEST_AMD64", "FUSEKI_IMAGE_DIGEST_ARM64", "FUSEKI_REPOSITORY", "SIPI_IMAGE_DIGEST", "SIPI_REPOSITORY") container_pull( name = "sipi", @@ -77,8 +112,15 @@ container_pull( ) container_pull( - name = "jenafuseki", - digest = FUSEKI_IMAGE_DIGEST, + name = "jenafuseki_amd64", + digest = FUSEKI_IMAGE_DIGEST_AMD64, + registry = "docker.io", + repository = FUSEKI_REPOSITORY, +) + +container_pull( + name = "jenafuseki_arm64", + digest = FUSEKI_IMAGE_DIGEST_ARM64, registry = "docker.io", repository = FUSEKI_REPOSITORY, ) @@ -196,42 +238,6 @@ load("@twirl//:defs.bzl", twirl_pinned_maven_install = "pinned_maven_install") twirl_pinned_maven_install() -##################################### -# Buildifier # -##################################### -# buildifier is written in Go and hence needs rules_go to be built. -# See https://github.com/bazelbuild/rules_go for the up to date setup instructions. -http_archive( - name = "io_bazel_rules_go", - sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz", - ], -) - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains() - -http_archive( - name = "bazel_gazelle", - sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", - ], -) - -# bazel buildtools providing buildifier -http_archive( - name = "com_github_bazelbuild_buildtools", - strip_prefix = "buildtools-master", - url = "https://github.com/bazelbuild/buildtools/archive/master.zip", -) - ##################################### # rules_pkg - basic packaging rules # ##################################### diff --git a/docker/knora-api/BUILD.bazel b/docker/knora-api/BUILD.bazel index 20fa15a54b..88b9c00c93 100644 --- a/docker/knora-api/BUILD.bazel +++ b/docker/knora-api/BUILD.bazel @@ -5,7 +5,10 @@ load("@io_bazel_rules_docker//container:container.bzl", "container_image", "cont # builds the docker image container_image( name = "image", - base = "@openjdk11//image", + base = select({ + "@platforms//cpu:arm64": "@openjdk11_arm64//image", + "//conditions:default": "@openjdk11_amd64//image", + }), cmd = [ "java", "-jar", diff --git a/docker/knora-jena-fuseki/BUILD.bazel b/docker/knora-jena-fuseki/BUILD.bazel index fc733a7766..857499dcfa 100644 --- a/docker/knora-jena-fuseki/BUILD.bazel +++ b/docker/knora-jena-fuseki/BUILD.bazel @@ -5,8 +5,10 @@ load("@io_bazel_rules_docker//container:container.bzl", "container_image", "cont # builds the docker image container_image( name = "image", - base = "@jenafuseki//image", - # env = {}, + base = select({ + "@platforms//cpu:arm64": "@jenafuseki_arm64//image", + "//conditions:default": "@jenafuseki_amd64//image", + }), labels = { "MAINTAINER": "400790+subotic@users.noreply.github.com", }, diff --git a/third_party/versions.bzl b/third_party/versions.bzl index c4fac29efb..60c742fe2c 100644 --- a/third_party/versions.bzl +++ b/third_party/versions.bzl @@ -16,4 +16,5 @@ SIPI_IMAGE_DIGEST = "sha256:67a0e8c16a67914f2765a1c7906e781383b835cfe72cd19c763b FUSEKI_REPOSITORY = "daschswiss/apache-jena-fuseki" FUSEKI_VERSION = "2.0.7" # contains Fuseki 4.3.2 (with log4j 2.16.0) FUSEKI_IMAGE = FUSEKI_REPOSITORY -FUSEKI_IMAGE_DIGEST = "sha256:fea8c556fca76c6beab2589018babd778d55dbdffef725fd2de784646cca0638" +FUSEKI_IMAGE_DIGEST_AMD64 = "sha256:fea8c556fca76c6beab2589018babd778d55dbdffef725fd2de784646cca0638" +FUSEKI_IMAGE_DIGEST_ARM64 = "sha256:137dc481978e13ff56a7212976b2ef0d8696e08c0abf4f97a4973a2af0b77b5a"