Skip to content

Commit

Permalink
Update readme + scripts
Browse files Browse the repository at this point in the history
Branch build-from-scratch in https://github.com/ochafik/bazel.git now compiles deps as needed
  • Loading branch information
ochafik committed Nov 30, 2017
1 parent a57c7c4 commit 27d93d9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 82 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# See README.md
FROM resin/rpi-raspbian:stretch
ADD build_from_scratch.sh /

RUN apt-get update

# Needed for apt-key on the debian:stretch image.
Expand All @@ -20,4 +18,7 @@ RUN apt-get install -y automake g++ libtool make curl git python unzip wget zip
apt-get autoremove && \
apt-get clean

RUN cd / && bash ./build_from_scratch.sh
RUN cd / && \
git clone https://github.com/ochafik/bazel.git -b build-from-scratch --depth=1 && \
cd bazel && \
VERBOSE=yes bash ./compile.sh
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Unfortunately, Raspbian doesn't have (yet) a package for Bazel. And Bazel
doesn't provide (yet) a binary for armhf. And their instructions to build from
source either implies you have a binary (which we don't) or that you battle with
compilation errors. Which I did in
[ochafik/bazel](https://github.com/ochafik/bazel/tree/from-scratch) (hopefully
to be merged back into the original repo), and here I'm using it to build...
[ochafik/bazel](https://github.com/ochafik/bazel/tree/build-from-scratch) (hopefully
to be pulled back into the original repo), and here I'm using it to build...

## A Docker image to run Raspbian w/ Bazel on your Desktop

Expand Down Expand Up @@ -51,38 +51,30 @@ docker run --rm -ti ochafik/rpi-raspbian-bazel /bin/bash

## From sources on a Raspberry Pi

Prerequisite: you'll need a large SD card, and the following packages (assumes
you already have an Oracle JDK8 installed, as is the case on NOOBS distros,
otherwise try `sudo apt-get install default-jdk`):
Prerequisite: you'll need a large SD card, and the following packages:

```bash
sudo apt-get update
sudo apt-get install -y automake g++ libtool make curl git python unzip wget zip
sudo apt-get install -y oracle-java8-installer oracle-java8-set-default

# Reclaim as much space as we can: we'll need it.
sudo apt-get autoremove
sudo apt-get clean
```

Now download my [script](./build_from_scratch.sh) and convince yourself it's safe:
- It clones [ochafik/bazel](https://github.com/ochafik/bazel)
(my fork of [bazelbuild/bazel](https://github.com/bazelbuild/bazel))
- Either your trust me, or you can fork my fork, check it doesn't contain dodgy
[diffs against the original repo](https://github.com/bazelbuild/bazel/compare/master...ochafik:from-scratch)
(assuming you trust the original, which I assume to be the case if you want to
use Bazel), edit the script to clone your fork instead (in case I sneakily
modified my fork after you scrutinized it), and proceed to the next command
Clone [ochafik/bazel](https://github.com/ochafik/bazel) (my fork of
[bazelbuild/bazel](https://github.com/bazelbuild/bazel)) and build it:

```bash
wget https://raw.githubusercontent.com/ochafik/rpi-raspbian-bazel/master/build_from_scratch.sh
# Do not trust scripts you download off the net!
less build_from_scratch.sh

bash build_from_scratch.sh
git clone https://github.com/ochafik/bazel -b build-from-scratch --depth=1
cd bazel
bash ./compile.sh
```

## Building the Raspberry Pi Docker image:

We aim to publish images every now and then, but you may rebuild the image at
I aim to publish images to docker hub soon, but you may rebuild the image at
any time with the following command (*takes a while*):

```bash
Expand All @@ -106,5 +98,6 @@ And if you want to test the `Dockerfile` itself faster on an image that does
not require QEMU:

```bash
docker build -t debian-bazel -f Dockerfile.debian .
cat Dockerfile | sed 's/resin\/rpi-raspbian:stretch/debian:stretch/' > Dockerfile.debian
docker build -t debian-bazel-build -f Dockerfile.debian .
```
75 changes: 48 additions & 27 deletions build_debian_and_raspbian_docker_images.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
#!/bin/bash
set -eux

if [[ ! -d dist-amd64 ]]; then
cat Dockerfile | sed 's/resin\/rpi-raspbian:stretch/debian:stretch/' > Dockerfile.debian
docker build -t debian-bazel-build -f Dockerfile.debian .

mkdir dist-amd64
id=$(docker create debian-bazel-build)
docker cp $id:bazel/output/bazel dist-amd64
docker rm -v $id
echo "
FROM debian-bazel-build
COPY ./dist-amd64/bazel /usr/bin
" > Dockerfile.debian-slim
docker build -t debian-bazel -f Dockerfile.debian-slim .
fi

if [[ ! -d dist-armhf ]]; then
docker build -t rpi-raspbian-bazel-build .
mkdir dist-armhf
id=$(docker create rpi-raspbian-bazel-build)
docker cp $id:bazel/output/bazel dist-armhf
docker rm -v $id
echo "
FROM rpi-raspbian-bazel-build
COPY ./dist-armhf/bazel /usr/bin
" > Dockerfile.raspbian-slim
docker build -t rpi-raspbian-bazel -f Dockerfile.raspbian-slim .
fi
readonly BAZEL_OUTPUT=/bazel/output/bazel

function build_bazel_docker() {
local build_image_base="$1"
local build_image_name="$2"
local normal_image_base="$3"
local normal_image_name="$4"
local slim_image_base="$5"
local slim_image_name="$6"
local dist_dir="$7"

if [[ ! -d "$dist_dir" ]]; then
cat Dockerfile | \
sed "s/resin\/rpi-raspbian:stretch/$(echo "$build_image_base" | sed 's/\//\\\//g')/" |
docker build -t "$build_image_name" -

mkdir -p "$dist_dir"
id=$(docker create "$build_image_name")
docker cp "$id:$BAZEL_OUTPUT" "$dist_dir"
docker rm -v $id

echo "
FROM $normal_image_base
COPY ./$dist_dir/bazel /usr/bin
" | \
docker build -t "$normal_image_name" -

echo "
FROM $slim_image_base
COPY ./$dist_dir/bazel /usr/bin
" | \
docker build -t "$slim_image_name" -
fi
}

# Use native Debian as a canary of sorts: this will fail way faster than the
# QEMU rasbian build.
build_bazel_docker \
debian:stretch debian-bazel-build \
debian:stretch debian-bazel \
debian:stretch-slim debian-bazel-slim \
dist-amd64

build_bazel_docker \
resin/rpi-raspbian:stretch rpi-raspbian-bazel-build \
resin/rpi-raspbian:stretch rpi-raspbian-bazel \
resin/rpi-raspbian:stretch-slim rpi-raspbian-bazel-slim \
dist-armhf
32 changes: 0 additions & 32 deletions build_from_scratch.sh

This file was deleted.

0 comments on commit 27d93d9

Please sign in to comment.