-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push docker image to DockerHub on merge into master
The base image will be built only if necessary, offline. for all PRs, a new image will be built.
- Loading branch information
1 parent
afe4bf6
commit ef678bb
Showing
7 changed files
with
123 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Publish Docker image to DockerHub | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
# https://docs.docker.com/build/ci/github-actions/multi-platform/ | ||
jobs: | ||
docker: | ||
name: Build Docker Image and Publish (only on push) | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
if: github.event_name == 'push' | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | ||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64/v8 | ||
push: ${{ github.event_name == 'push' }} | ||
tags: sysprog21/rv32emu:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,29 @@ | ||
FROM ubuntu:22.04 | ||
LABEL maintainer="henrybear327@gmail.com" | ||
FROM sysprog21/rv32emu-gcc as base_gcc | ||
FROM sysprog21/rv32emu-sail as base_sail | ||
|
||
# Install packages required for the emulator to compile and execute correctly | ||
FROM ubuntu:22.04 as final | ||
|
||
# Install extra packages for the emulator to compile and execute with full capabilities correctly | ||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
libsdl2-dev libsdl2-mixer-dev python3-pip git | ||
libsdl2-dev libsdl2-mixer-dev python3-pip git && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN python3 -m pip install git+https://github.com/riscv/riscof | ||
|
||
# set up the timezone | ||
ENV TZ=Asia/Taipei | ||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | ||
|
||
# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation | ||
# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh | ||
# for x86, we can optimize this part and take the nightly build directly, but not for aarch64 | ||
ENV RISCV=/opt/riscv | ||
ENV PATH=$RISCV/bin:$PATH | ||
WORKDIR $RISCV | ||
RUN apt install -y autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev | ||
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain | ||
RUN cd riscv-gnu-toolchain && \ | ||
git checkout tags/2023.10.06 && \ | ||
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \ | ||
make -j$(nproc) && \ | ||
make clean | ||
|
||
# the default reference emulator is x86-based | ||
# we need to build it ourselves if we are using it on aarch64 | ||
# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models | ||
# the above commands are modified to match the current build flow as indicated in the Github CI -> https://github.com/riscv/sail-riscv/blob/master/.github/workflows/compile.yml | ||
WORKDIR /home/root/ | ||
RUN apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler | ||
RUN opam init --disable-sandboxing -y | ||
RUN opam install -y sail | ||
RUN git clone https://github.com/riscv/sail-riscv.git | ||
# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f | ||
# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7 | ||
RUN cd sail-riscv && \ | ||
git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \ | ||
eval $(opam env) && \ | ||
make && \ | ||
ARCH=RV32 make | ||
|
||
# copy in the source code | ||
WORKDIR /home/root/rv32emu | ||
COPY . . | ||
|
||
# Copy the GCC binaries | ||
ENV RISCV=/opt/riscv | ||
ENV PATH=$RISCV/bin:$PATH | ||
COPY --from=base_gcc /opt/riscv/ /opt/riscv/ | ||
|
||
# replace the emulator (riscv_sim_RV32) with the arch that the container can execute | ||
RUN rm /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 | ||
RUN cp /home/root/sail-riscv/c_emulator/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 | ||
|
||
# clean up apt cache | ||
RUN rm -rf /var/lib/apt/lists/* | ||
COPY --from=base_sail /home/root/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM ubuntu:22.04 as base | ||
|
||
# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation | ||
# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh | ||
# for x86, we can optimize this part and take the nightly build directly, but not for aarch64 | ||
RUN apt-get update && \ | ||
apt install -y \ | ||
git autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain | ||
RUN cd riscv-gnu-toolchain && \ | ||
git checkout tags/2023.10.06 && \ | ||
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \ | ||
make -j$(nproc) && \ | ||
make clean | ||
|
||
FROM ubuntu:22.04 as final | ||
|
||
# Keep the GCC binaries only | ||
COPY --from=base /opt/riscv/ /opt/riscv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# builds the base image of rv32emu (the toolchains) | ||
# docker build --progress=plain -t sysprog21/rv32emu-base -f Dockerfile-base . 2>&1 | tee build.log | ||
FROM ubuntu:22.04 as base | ||
|
||
# the default reference emulator is x86-based | ||
# we need to build it ourselves if we are using it on aarch64 | ||
# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models | ||
# the above commands are modified to match the current build flow as indicated in the Github CI -> https://github.com/riscv/sail-riscv/blob/master/.github/workflows/compile.yml | ||
RUN apt-get update && \ | ||
apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler && \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN opam init --disable-sandboxing -y | ||
RUN opam switch create ocaml-base-compiler.4.13.1 # opam switch list-available | ||
RUN opam search sail | ||
# https://opam.ocaml.org/packages/sail/sail.0.16/ | ||
RUN opam install -y sail.0.16 # latest version 0.17.x will cause complication issues for sail-riscv on commit 9547a3 | ||
RUN git clone https://github.com/riscv/sail-riscv.git | ||
# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f | ||
# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7 | ||
RUN cd sail-riscv && \ | ||
git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \ | ||
eval $(opam env) && \ | ||
make && \ | ||
ARCH=RV32 make | ||
|
||
FROM ubuntu:22.04 as final | ||
|
||
# keep the emulator only | ||
COPY --from=base /sail-riscv/c_emulator/riscv_sim_RV32 /home/root/riscv_sim_RV32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Base images | ||
|
||
This directory contains the Dockerfiles of the base images, containing the `gcc` and `sail` toolchain. | ||
|
||
The build process should be rarely used, unless an update on the toolchain is required. When a new build is made by running `build.sh`, build and push to DockerHub are automated. | ||
|
||
## Details | ||
|
||
For `gcc`, we are using the compiler version `tags/2023.10.06`, as using the binaries from `apt install gcc-riscv64-unknown-elf` will cause `"unsupported ISA subset 'z'"` error during the compilation of the emulator on M1. | ||
|
||
For `sail`, we set up the toolchain to use `sail-0.16`, as the latest version `0.17.x` series will cause compilation errors. | ||
|
||
We are using the commit `9547a30bf84572c458476591b569a95f5232c1c7` from `sail-riscv` for the reference simulator, as this is the commit cloest to the time when the [x86 reference sail emulator](https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f) was added to the `rv32emu` Github repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
# note | ||
# Will take around 20 and 10 minutes when building a native image on the native arch for gcc and sail, respectively, if the internet connection is fast | ||
|
||
# To enable cross platform build | ||
# https://www.docker.com/blog/how-to-rapidly-build-multi-architecture-images-with-buildx/ | ||
-docker buildx create --name cross-platform-builder --use --bootstrap | ||
|
||
docker buildx build --progress=plain --push --platform linux/amd64,linux/arm64/v8 --tag sysprog21/rv32emu-gcc -f Dockerfile-gcc . 2>&1 | tee build-gcc.log | ||
rm build-gcc.log | ||
|
||
docker buildx build --progress=plain --push --platform linux/amd64,linux/arm64/v8 --tag sysprog21/rv32emu-sail -f Dockerfile-sail . 2>&1 | tee build-sail.log | ||
rm build-sail.log |