Skip to content

Introduction of Dockerfile for building and running CBMC in a Docker container. #5715

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

Merged
merged 3 commits into from
Jan 12, 2021
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/pull-request-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,24 @@ jobs:
- uses: actions/checkout@v2
- name: Check for unused irep ids
run: ./scripts/string_table_check.sh

Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Might be worth stating in the commit title that this is PR check. Otherwise it might be confused with the release actions when looking through the commit history later. Something like - "Add github action on PRs to check the Dockerfile"
⛏️ The commit title should not end with a full stop. See point "4. Do not end the subject line with a period", here - How to Write a Git Commit Message

check-docker-image:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Download test dependencies
run: sudo apt install openjdk-11-jdk-headless
- name: Build docker image
run: docker build -t cbmc .
- name: Smoke test goto-cc
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-cc -o /mnt/smoke/test.goto /mnt/smoke/test.c
- name: Smoke test cbmc
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc cbmc /mnt/smoke/test.goto
- name: Smoke test jbmc
run: |
javac .github/workflows/smoke_test_assets/Test.java
docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc jbmc --classpath /mnt/smoke Test
- name: Smoke test goto-analyzer
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-analyzer /mnt/smoke/test.goto --unreachable-functions
6 changes: 6 additions & 0 deletions .github/workflows/smoke_test_assets/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Test {
public static void main(String[] args) {
System.out.println("Hi");
assert(1 == 1);
}
}
9 changes: 9 additions & 0 deletions .github/workflows/smoke_test_assets/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <assert.h>

#define return_val 0;

int main(void)
{
assert(1 == 1);
return return_val;
}
15 changes: 15 additions & 0 deletions COMPILING.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ the need to integrate JBMC as a separate project. Be aware that you need to
change the build location (Select project in Eclipse -> Properties -> C/C++
Build) to one of the src directories.

# WORKING WITH DOCKER

To compile and run the tools in a Docker container, do the following:

1. From the root folder of the project, run `$ docker build -t cbmc .`
2. After the building phase has finished, there should be a new
image with the CProver binaries installed under `/usr/local/bin/`.

To start a container using that image as a base, run `$ docker run -i -t cbmc`
This will result in dropping you to a new terminal inside the container. To
load files for analysis into the container, one way is by mounting the folder
that contains the tests to the container. A possible invocation that does that
is: `$ docker run --mount type=bind,source=local/path/with/files,target=/mnt/analysis -i t cbmc`. In the
resulting container, the files present in the local file system under
`local/path/with/files` will be present under `/mnt/analysis`.

# OPTIONS AND VARIABLES

Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:20.04 as builder
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
# Timezone data is needed during the installation of dependencies,
# since cmake depends on the tzdata package. In an interactive terminal,
# the user selects the timezone at installation time. Since this needs
# to be a non-interactive terminal, we need to setup some sort of default.
# The UTC one seemed the most suitable one.
RUN echo 'tzdata tzdata/Areas select Etc' | debconf-set-selections; \
echo 'tzdata tzdata/Zones/Etc select UTC' | debconf-set-selections; \
apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y \
cmake \
ninja-build \
gcc \
g++ \
maven \
flex \
bison \
libxml2-utils \
patch
COPY . /tmp/cbmc
WORKDIR /tmp/cbmc
RUN cmake -S . -Bbuild -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ && cd build; ninja -j2
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the -DCMAKE_*_COMPILER settings as those will be no different from the system defaults. And ninja -C build -j2 would spare you the cd build.

Choose a reason for hiding this comment

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

Or cmake --build build

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, when it comes to the WORKDIR I think it might be better to actually keep it. From the docker documentation it seems there's no longer any massive need to avoid extraneous instructions, as only a few introduce new layers, and I think it's cleaner this way.

What do you think about this?


FROM ubuntu:20.04 as runner
COPY --from=builder /tmp/cbmc/build/bin/* /usr/local/bin/
RUN apt-get update && apt-get install -y gcc