Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding docker developer build with bazel #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bazel-bin
bazel-genfiles
bazel-out
bazel-old
bazel-code
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the linked executables that appeared during the build from bazel - it's on my host because I tested binding the PWD to /code (and it generated). Here is the (now dead) symlink in root's home (in the container):

 ls -l bazel-code 
lrwxrwxrwx 1 root root 81 Jul  5 12:04 bazel-code -> /root/.cache/bazel/_bazel_root/933c2f549343e099e3a6911b282cb71c/execroot/__main__

here are the whole set:

lrwxrwxrwx 1 root root 108 Jul  5 12:04 bazel-bin -> /root/.cache/bazel/_bazel_root/933c2f549343e099e3a6911b282cb71c/execroot/__main__/bazel-out/k8-fastbuild/bin
lrwxrwxrwx 1 root root  81 Jul  5 12:04 bazel-code -> /root/.cache/bazel/_bazel_root/933c2f549343e099e3a6911b282cb71c/execroot/__main__
lrwxrwxrwx 1 root root  91 Jul  5 12:04 bazel-out -> /root/.cache/bazel/_bazel_root/933c2f549343e099e3a6911b282cb71c/execroot/__main__/bazel-out
lrwxrwxrwx 1 root root 113 Jul  5 12:04 bazel-testlogs -> /root/.cache/bazel/_bazel_root/933c2f549343e099e3a6911b282cb71c/execroot/__main__/bazel-out/k8-fastbuild/testlogs

Was this possibly added in a newer release? If you build the container and bind to /code and then build you should see the same pop up!

bazel-testlogs
bazel-vagrant
bazel-bazel-example
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:22.04
# docker build -t old .
RUN apt-get update && apt-get install -y curl gnupg
RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add - && \
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
RUN apt-get update && apt-get install -y bazel
WORKDIR /code
COPY . /code
RUN bazel build src/main:libold.so
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# old

![main brabcg](https://github.com/fzakaria/old/actions/workflows/actions.yml/badge.svg)
![main branch](https://github.com/fzakaria/old/actions/workflows/actions.yml/badge.svg)

> The Other Dynamic Linker

Expand Down Expand Up @@ -120,6 +120,7 @@ The tool generously provides the required TOML file necessary for the configurat
This repository uses [bazel](https://docs.bazel.build/) as the build system; some familiarity is required.

Once you have bazel installed, building the shared object is done as follows.

```console
$ bazel build src/main:libold.so
```
Expand All @@ -128,4 +129,34 @@ You can then run the built binary with the example TOML file provided by setting

```console
$ OLDAUDIT_CONFIG=./example.toml LD_AUDIT=./bazel-bin/src/main/libold.so ruby --help | head
```
```

### Docker

If you want to develop using a Docker container, we provide a [Dockerfile](Dockerfile)
with bazel ready to go! First, build the container:

```bash
$ docker build -t old .
```

You can then shell inside to use old:

```bash
$ docker run -it old
```
```bash
$ apt-get install -y ruby
$ LD_AUDIT=./bazel-bin/src/main/libold.so ruby -e "puts 'hi'"
$ OLDAUDIT_CONFIG=./example.toml LD_AUDIT=./bazel-bin/src/main/libold.so ruby --help | head
```

or bind the present working directory (with the source code) to `/code`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be bazel-code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indeed not - the code is bound to /code in the container (a terrible convention I've had for as long as containers have been around!)

to work locally and build in the container:

```bash
$ docker run -it -v $PWD:/code old
$ bazel build src/main:libold.so
```

Have fun!