Skip to content

Commit

Permalink
Add riscv Dockerfile builder
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbiesek committed Aug 5, 2023
1 parent 021aee9 commit f1f5c38
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ else
$(error error: invalid ARCH; "$(ARCH)")
endif

ifeq ("riscv64", "$(ARCH)")
DIST=ubunturiscv
else
DIST=ubuntu
endif

# include the CLI targets with "cli" prefix plus "scope" shortcut
cli%:
@$(MAKE) -C cli $(@:cli%=%)
Expand All @@ -129,7 +135,6 @@ docker-run-alpine:
@$(MAKE) -s build CMD="$(CMD)" DIST="alpine"

# build in our builder container for the given ARCH
build: DIST ?= ubuntu
build: CMD ?= make all test
build: require-docker require-qemu-binfmt
@[ -n "$(NOBUILD)" ] || $(MAKE) -s builder DIST="$(DIST)" ARCH="$(ARCH)"
Expand All @@ -143,14 +148,12 @@ build: require-docker require-qemu-binfmt
$(CMD)

# run a shell our builder container without starting a build
run: DIST ?= ubuntu
run: CMD ?= /bin/bash --login
run:
@echo Running the AppScope $(DIST)/$(ARCH) Builder Container
@$(MAKE) -s build DIST="$(DIST)" ARCH="$(ARCH)" CMD="$(CMD)"

# get another shell in an existing builder container
exec: DIST ?= ubuntu
exec: CMD ?= /bin/bash
exec:
@[ -n "$(shell docker ps -q -f "name=appscope-builder-$(DIST)-$(ARCH)")" ] || \
Expand All @@ -159,7 +162,6 @@ exec:
@docker exec -it $(shell docker ps -q -f "name=appscope-builder-$(DIST)-$(ARCH)") $(CMD)

# build the builder image for the given ARCH
builder: DIST ?= ubuntu
builder: TAG := $(BUILD_IMAGE):$(DIST)-$(ARCH)
builder: require-docker-buildx-builder
@[ -z "$(CI)" ] || echo "Update $(DIST)/$(ARCH) Builder Image"
Expand Down
70 changes: 70 additions & 0 deletions docker/builder/Dockerfile.ubunturiscv
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

ARG IMAGE=riscv64/ubuntu:23.04
FROM $IMAGE

# These are needed to bypass the prompts when tzdata is installed.
ENV DEBIAN_FRONTEND="noninteractive"
ENV TZ="America/New_York"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# ---
# Install packages. Note extra PPA for Go.
#
# Also note that this logic duplicates the top-level `install_build_tools.sh`
# script. Trying to use that script here causes issues because of its use of
# `sudu` when running the package installer. It clears the environment so the
# additions above don't apply and we end up with interaction when some of the
# dependencies (i.e. tzdata) are installed.
#
RUN apt-get update && \
apt-get install -y software-properties-common gpg apt-utils libelf-dev && \
add-apt-repository ppa:longsleep/golang-backports && \
apt-get update && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 52B59B1571A79DBC054901C0F6BC817356A3D45E && \
apt-get install -y \
autoconf \
automake \
build-essential \
cmake \
curl \
emacs \
gdb \
git \
golang-go \
lcov \
libtool \
lsof \
make \
strace \
sudo \
tzdata \
&& \
dpkg-reconfigure --frontend noninteractive tzdata && \
apt-get clean

RUN useradd -d /home/builder -m builder && \
useradd -d /home/builder -m builder1 && \
\
echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/builder && \
echo "builder1 ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/builder && \
\
echo "alias ll='ls -alF'" >> /home/builder/.bashrc && \
echo "alias la='ls -A'" >> /home/builder/.bashrc && \
echo "alias l='ls -CF'" >> /home/builder/.bashrc && \
echo "alias h='history'" >> /home/builder/.bashrc && \
\
echo "#set environment LD_PRELOAD=/home/builder/appscope/lib/linux/libscope.so" >> /home/builder/.gdbinit && \
echo "set follow-fork-mode child" >> /home/builder/.gdbinit && \
echo "set breakpoint pending on" >> /home/builder/.gdbinit && \
echo "set directories /home/builder/appscope" >> /home/builder/.gdbinit && \
\
mkdir /home/builder/appscope

# ---
# The local git clone of the project is mounted as /home/builder/appscope. See Makefile.
#
# docker run -v $(pwd):/home/builder/appscope ...
#
WORKDIR /home/builder/appscope

# fini
4 changes: 2 additions & 2 deletions docs/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ You can override the command setting `CMD` like below.
make build CMD="make coreall"
```

By default, this will build for the local CPU architecture; `uname -m`. We support building for other architectures via [QEMU] and [`binfmt`] by setting `ARCH` like below. Note we only support `x86_64` and `aarch64` currently
By default, this will build for the local CPU architecture; `uname -m`. We support building for other architectures via [QEMU] and [`binfmt`] by setting `ARCH` like below. Note we only support `x86_64`, `aarch64` and `riscv64` currently

```text
make build ARCH=aarch64
```

The resulting binaries are listed below. `$ARCH` will be `x86_64` or `aarch64`.
The resulting binaries are listed below. `$ARCH` will be `x86_64`, `aarch64` or `riscv64`.

* `lib/linux/$ARCH/libscope.so`
* `bin/linux/$ARCH/scope`
Expand Down

0 comments on commit f1f5c38

Please sign in to comment.