Bazel: Bazel on Alpine Linux

Created on 8 Jul 2016  Â·  22Comments  Â·  Source: bazelbuild/bazel

I've been thinking about developing with Bazel inside of docker containers so that way I can have sandboxing on Mac. Is it possible to use Bazel with Alpine Linux or is Ubuntu required?

P4 other

Most helpful comment

Moreover, I'm looking in creating native bazel package for Alpine Linux, so that something like that:

Native Bazel package for Alpine Linux is here.

All 22 comments

I don't think anyone's tried it, but we'd love to hear how it goes.

So I tried running it with this Dockerfile and get the below error. My best guess is that unzip does not work with the self extracting archive.

FROM alpine:3.4
RUN apk add --no-cache \
  bash=4.3.42-r3 \
  bash-completion=2.1-r2 \
  ca-certificates=20160104-r4 \
  g++=5.3.0-r0 \
  openjdk8=8.92.14-r1 \
  pkgconf=0.9.12-r0 \
  unzip=6.0-r1 \
  wget=1.17.1-r1 \
  zip=3.0-r4 \
  zlib-dev=1.2.8-r2
ENV JAVA_HOME /usr/lib/jvm/default-jvm
RUN wget -O bazel-installer.sh -q \
  https://github.com/bazelbuild/bazel/releases/download/0.3.0/bazel-0.3.0-installer-linux-x86_64.sh \
  && bash bazel-installer.sh \
  && rm bazel-installer.sh
bash-4.3$ bazel
/usr/local/bin/bazel: line 86: /usr/local/lib/bazel/bin/bazel-real: No such file or directory

I did some digging into this today, specifically to see why bazel can't build under alpine, and I believe it's failing in the protoc step, because the grpc protoc plugin isn't statically compiled, so it's failing to find a shared object it needs.

However I can't be sure, because it just dies instantly after printing "Building bazel from scratch."

You can add set -x to compile.sh and it'll print each line as it executes.

Yup, added that to compile.sh and can confirm it'e dying in the protoc step. Full log can be uploaded if wanted.

Is there a way to ensure the shared object is in the Alpine container?

I have no experience with Alpine Linux or Docker, but I thought this looked interesting and got it working.

I think using the installer built for a different libc is pretty hopeless, but I did get building from scratch working with just a few tweaks.

I assume you tried to compile an older Bazel version before 168031d21624741411ac238373cbd8544b8948df, because I didn't see any issues with protoc shared libraries.

third_party/grpc/protoc-gen-grpc-java-0.15.0-linux-x86_64.exe is dynamically linked (but not to libstdc++), so I followed the directions in the README.md of sgerrand/alpine-pkg-glibc to install glibc.

I've sent out a few fixes, and there's something else going on that I think is busybox env handling a -- in the arguments list differently. For now, removing the commandLineArgs.add("--"); line from src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxRunner.java makes it work on Alpine but breaks it on my Debian system.

I submitted grpc/grpc#7730 and I2bd5ec198522ea1ea19df0aaa1eb7c6977217eb3 to fix a few musl libc incompatibilities.

Noticing that https://bazel-review.googlesource.com/#/q/I2bd5ec198522ea1ea19df0aaa1eb7c6977217eb3 never got merged, would love to see that land, support musl/libc would be great.

@bsilver8192 How did you get ./compile.sh to use the glibc-compat from sgerrand/alpine-pkg-glibc? I added it to my docker image, but it didn't seem to solve anything for me. FYI, I added: /usr/glibc-compat/bin:/usr/glibc-compat/sbin to the front of my PATH as well as added /usr/glibc-compat/lib to LD_LIBRARY_PATH

I am trying to build bazel-4.3 on alpine-3.5. I am running into the following compile error I believe is connected to libc compatibility:

  /tmp/bazel_XXGIjcLb/out/execroot/bazel_build/_bin/process-wrapper -1 5 - - /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wl,-z,-relro,-z,now -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-canonical-system-headers -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fpermissive -fdata-sections '-std=c++0x' -MD -MF bazel-out/local-opt/bin/third_party/ijar/_objs/platform_utils/third_party/ijar/platform_utils.d '-frandom-seed=bazel-out/local-opt/bin/third_party/ijar/_objs/platform_utils/third_party/ijar/platform_utils.o' -iquote . -iquote bazel-out/local-opt/genfiles -iquote external/bazel_tools -iquote bazel-out/local-opt/genfiles/external/bazel_tools -isystem external/bazel_tools/tools/cpp/gcc3 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c third_party/ijar/platform_utils.cc -o bazel-out/local-opt/bin/third_party/ijar/_objs/platform_utils/third_party/ijar/platform_utils.o).
In file included from third_party/ijar/platform_utils.cc:15:0:
./third_party/ijar/platform_utils.h:31:3: error: 'mode_t' does not name a type
   mode_t file_mode;
   ^~~~~~
./third_party/ijar/platform_utils.h: In function 'devtools_ijar::u4 devtools_ijar::stat_to_zipattr(const devtools_ijar::Stat&)':
./third_party/ijar/platform_utils.h:38:26: error: 'const struct devtools_ijar::Stat' has no member named 'file_mode'
   return (((u4)file_stat.file_mode) << 16) |
                          ^~~~~~~~~
./third_party/ijar/platform_utils.h: At global scope:
./third_party/ijar/platform_utils.h:51:35: error: 'mode_t' has not been declared
 bool write_file(const char* path, mode_t perm, const void* data, size_t size);
                                   ^~~~~~
./third_party/ijar/platform_utils.h:68:34: error: 'mode_t' has not been declared
 bool make_dirs(const char* path, mode_t perm);
                                  ^~~~~~
third_party/ijar/platform_utils.cc: In function 'bool devtools_ijar::stat_file(const char*, devtools_ijar::Stat*)':
third_party/ijar/platform_utils.cc:47:11: error: 'struct devtools_ijar::Stat' has no member named 'file_mode'
   result->file_mode = statst.st_mode;
           ^~~~~~~~~
third_party/ijar/platform_utils.cc: In function 'bool devtools_ijar::write_file(const char*, mode_t, const void*, size_t)':
third_party/ijar/platform_utils.cc:67:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (write(fd, data, size) != size) {
       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
Target //src:bazel failed to build

Any ideas?

It looks like mode_t is defined in a different header than on other systems. Maybe try grepping to find where mode_t is defined in /usr/include. third_party/ijar/platform_utils.cc is already including all of the places I'd expect to find it. Maybe sys/file.h?

@r351574nc3 , you can see a workaround in this Dockerfile which builds Bazel and TF with musl instead of glibc:
https://github.com/tatsushid/docker-alpine-py3-tensorflow-jupyter/blob/master/Dockerfile#L46

It seems, that those workarounds are not needed any more. Here is the working Dockerfile that is building Bazel on Alpine Linux.

Moreover, I'm looking in creating native bazel package for Alpine Linux, so that something like that:

apk add bazel

just work.

Thanks! This should mean lighter docker containers for all

Moreover, I'm looking in creating native bazel package for Alpine Linux, so that something like that:

Native Bazel package for Alpine Linux is here.

NICE!!

On Wed, Nov 8, 2017 at 2:08 PM David Ostrovsky notifications@github.com
wrote:

Moreover, I'm looking in creating native bazel package for Alpine Linux,
so that something like that:

Native Bazel package for Alpine Linux is here
https://github.com/davido/bazel-alpine-package/blob/master/APKBUILD.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/bazelbuild/bazel/issues/1492#issuecomment-342977203,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABQdpi9JEVlBlXxjreV7659ebqSI4d5ks5s0iZfgaJpZM4JITQG
.

Hello all,
I think that as it is explained here, the issue is actually not from Bazel but from Buzybox. So imho the best and simplest solution is to add the coreutils dependency in your Dockerfiles.
As an example I did this Docker image and it works perfectly: https://hub.docker.com/r/alexiskofman/bazel-alpine/

So imho the best and simplest solution is to add the coreutils dependency in your Dockerfiles.

Sure, but why are you worried about this diff line:
https://github.com/davido/bazel-alpine-package/blob/master/APKBUILD#L22

In the end users should be able to just say:

apk add bazel

BTW, the Bazel 0.8.0 native package for Alpine Linux is here: https://github.com/davido/bazel-alpine-package/releases/tag/0.8.0.

Closing since this is not really an issue anymore?

@davido @mhlopko abovementioned builds are not up to date (0.15.2 is latest there, yet we have 0.18.0). Is there any alternative way to get those binaries on alpine?

[F.Y.I.] For those who're looking for the latest Bazel Alpine package (apk file like I do), check:

https://github.com/davido/bazel-alpine-package/releases

  • Currently (2019/09/04) available Bazel versions:

    • PreRelease: Bazel v0.26.1

    • Latest: Bazel v0.22.0

[LOG] Alpine:latest(3.10.2) @ macOS

$ # Host Env Infos
$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.13.6
BuildVersion:   17G7024
$ 
$ docker version
Client: Docker Engine - Community
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:33:12 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:41:49 2019
  OS/Arch:          linux/amd64
  Experimental:     false
$
$ docker run --rm -it alpine:latest /bin/sh
/ # 
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.10.2
PRETTY_NAME="Alpine Linux v3.10"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/ #
/ # # Install Bazel
/ # #   See: https://github.com/davido/bazel-alpine-package
/ # apk --no-cache add ca-certificates wget
...
/ # wget -q -O /etc/apk/keys/[email protected] \
>  https://raw.githubusercontent.com/davido/bazel-alpine-package/master/[email protected]
/ #
/ # wget https://github.com/davido/bazel-alpine-package/releases/download/0.26.1/bazel-0.26.1-r0.apk
...
/ #
/ # apk add bazel-0.26.1-r0.apk && rm bazel-0.26.1-r0.apk
...
/ #
/ # bazel version
Extracting Bazel installation...
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Build label: 0.26.1- (@non-git)
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Sat Jun 8 20:32:26 2019 (1560025946)
Build timestamp: 1560025946
Build timestamp as int: 1560025946
/ #
/ # # Build C++ sample
/ # #   See: https://docs.bazel.build/versions/master/tutorial/cpp.html
/ # 
/ # apk --no-cache add git g++
/ # git clone https://github.com/bazelbuild/examples/
...
/ # cd examples/cpp-tutorial/stage1
/ # bazel build //main:hello-world
INFO: Analyzed target //main:hello-world (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //main:hello-world up-to-date:
  bazel-bin/main/hello-world
INFO: Elapsed time: 0.450s, Critical Path: 0.32s
INFO: 1 process: 1 processwrapper-sandbox.
INFO: Build completed successfully, 2 total actions
/ # 
/ # ./bazel-bin/main/hello-world
Hello world
Wed Sep  4 02:40:06 2019
/ # 
/ # ldd ./bazel-bin/main/hello-world
    /lib/ld-musl-x86_64.so.1 (0x7fc58ae7d000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fc58ad23000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc58ad0f000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fc58ae7d000)

apk add bazel

Just to anyone landing here from Google Search, you can't add bazel like that anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

buchgr picture buchgr  Â·  3Comments

ensonic picture ensonic  Â·  3Comments

xinxiao picture xinxiao  Â·  3Comments

ttsugriy picture ttsugriy  Â·  3Comments

GaofengCheng picture GaofengCheng  Â·  3Comments