Skip to content

Commit 164c492

Browse files
committedNov 26, 2023
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.
1 parent afe4bf6 commit 164c492

File tree

3 files changed

+85
-48
lines changed

3 files changed

+85
-48
lines changed
 

‎.github/workflows/docker.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Publish Docker image to DockerHub
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
branches: [ master ]
7+
8+
# https://docs.docker.com/build/ci/github-actions/multi-platform/
9+
jobs:
10+
docker:
11+
name: Build Docker Image and Publish (only on push)
12+
runs-on: ubuntu-latest
13+
steps:
14+
15+
- name: Check out the repo
16+
uses: actions/checkout@v4
17+
- name: Set up QEMU
18+
uses: docker/setup-qemu-action@v3
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
- name: Login to Docker Hub
22+
uses: docker/#-action@v3
23+
if: github.event_name == 'push'
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
27+
- name: Build and push
28+
uses: docker/build-push-action@v5
29+
with:
30+
context: .
31+
platforms: linux/amd64,linux/arm64
32+
push: ${{ github.event_name == 'push' }}
33+
tags: sysprog21/rv32emu:latest

‎Dockerfile

+2-48
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,9 @@
1-
FROM ubuntu:22.04
2-
LABEL maintainer="henrybear327@gmail.com"
3-
4-
# Install packages required for the emulator to compile and execute correctly
5-
RUN apt-get update && \
6-
DEBIAN_FRONTEND=noninteractive apt-get install -y \
7-
libsdl2-dev libsdl2-mixer-dev python3-pip git
8-
9-
RUN python3 -m pip install git+https://github.com/riscv/riscof
10-
11-
# set up the timezone
12-
ENV TZ=Asia/Taipei
13-
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
14-
15-
# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation
16-
# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh
17-
# for x86, we can optimize this part and take the nightly build directly, but not for aarch64
18-
ENV RISCV=/opt/riscv
19-
ENV PATH=$RISCV/bin:$PATH
20-
WORKDIR $RISCV
21-
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
22-
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
23-
RUN cd riscv-gnu-toolchain && \
24-
git checkout tags/2023.10.06 && \
25-
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \
26-
make -j$(nproc) && \
27-
make clean
28-
29-
# the default reference emulator is x86-based
30-
# we need to build it ourselves if we are using it on aarch64
31-
# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models
32-
# 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
33-
WORKDIR /home/root/
34-
RUN apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler
35-
RUN opam init --disable-sandboxing -y
36-
RUN opam install -y sail
37-
RUN git clone https://github.com/riscv/sail-riscv.git
38-
# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f
39-
# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7
40-
RUN cd sail-riscv && \
41-
git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \
42-
eval $(opam env) && \
43-
make && \
44-
ARCH=RV32 make
1+
FROM sysprog21/rv32emu-base:latest
452

463
# copy in the source code
474
WORKDIR /home/root/rv32emu
485
COPY . .
496

507
# replace the emulator (riscv_sim_RV32) with the arch that the container can execute
518
RUN rm /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32
52-
RUN cp /home/root/sail-riscv/c_emulator/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32
53-
54-
# clean up apt cache
55-
RUN rm -rf /var/lib/apt/lists/*
9+
RUN cp /home/root/sail-riscv/c_emulator/riscv_sim_RV32 /home/root/rv32emu/tests/arch-test-target/sail_cSim/riscv_sim_RV32

‎Dockerfile-base

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# builds the base image of rv32emu (the toolchains)
2+
FROM ubuntu:22.04
3+
4+
# Install packages required for the emulator to compile and execute correctly
5+
RUN apt-get update && \
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
7+
libsdl2-dev libsdl2-mixer-dev python3-pip git
8+
9+
RUN python3 -m pip install git+https://github.com/riscv/riscof
10+
11+
# set up the timezone
12+
ENV TZ=Asia/Taipei
13+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
14+
15+
# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation
16+
# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh
17+
# for x86, we can optimize this part and take the nightly build directly, but not for aarch64
18+
ENV RISCV=/opt/riscv
19+
ENV PATH=$RISCV/bin:$PATH
20+
WORKDIR $RISCV
21+
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
22+
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
23+
RUN cd riscv-gnu-toolchain && \
24+
git checkout tags/2023.10.06 && \
25+
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \
26+
make -j$(nproc) && \
27+
make clean
28+
29+
# the default reference emulator is x86-based
30+
# we need to build it ourselves if we are using it on aarch64
31+
# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models
32+
# 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
33+
WORKDIR /home/root/
34+
RUN apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler
35+
RUN opam init --disable-sandboxing -y
36+
RUN opam switch create ocaml-base-compiler.4.13.1 # opam switch list-available
37+
RUN opam search sail
38+
# https://opam.ocaml.org/packages/sail/sail.0.16/
39+
RUN opam install -y sail.0.16 # latest version 0.17.x will cause complication issues for sail-riscv on commit 9547a3
40+
RUN git clone https://github.com/riscv/sail-riscv.git
41+
# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f
42+
# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7
43+
RUN cd sail-riscv && \
44+
git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \
45+
eval $(opam env) && \
46+
make && \
47+
ARCH=RV32 make
48+
49+
# clean up apt cache
50+
RUN rm -rf /var/lib/apt/lists/*

0 commit comments

Comments
 (0)