Skip to content

Commit b9bdb8a

Browse files
committed
use docker for reproducible build
The reproducible build of MigTD binary requires same user and code path, so we provide a `Dockerfile` for reproducibility. Signed-off-by: Jiaqi Gao <[email protected]>
1 parent 0983324 commit b9bdb8a

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

container/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM ubuntu:22.04
2+
3+
# Adding rust binaries to PATH.
4+
ENV PATH="$PATH:/root/.cargo/bin"
5+
WORKDIR /root
6+
7+
# Install all required packages in one go to optimize the image
8+
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
9+
# DEBIAN_FRONTEND is set for tzdata.
10+
RUN apt-get update && \
11+
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
12+
build-essential unzip ca-certificates curl gcc git libssl-dev pkg-config ssh \
13+
clang llvm nasm \
14+
ocaml ocamlbuild wget pkg-config libtool autoconf autotools-dev automake \
15+
screen expect \
16+
# cleanup
17+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
18+
19+
# Install rustup and a fixed version of Rust.
20+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2023-08-28
21+
RUN rustup component add rust-src
22+
RUN cargo install cargo-xbuild
23+
24+
RUN git clone --recursive https://github.com/intel/MigTD.git

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,16 @@ echo "qom-set /objects/tdx0/ vsockport 0" | nc -U /tmp/qmp-sock-dst
263263
Ask migtd-src to start pre-migration:
264264
```
265265
echo "qom-set /objects/tdx0/ vsockport 0" | nc -U /tmp/qmp-sock-src
266+
267+
## Reproducible Build
268+
269+
Reproducible build of MigTD binary requires same system user and
270+
source code path (see https://github.com/intel/MigTD/issues/51).
271+
272+
The [Dockerfile](./Dockerfile) is provided to build the docker image with
273+
the MigTD compilation environment for reproducible build. You can use the
274+
[docker.sh](./sh_script/docker.sh) to build and run the docker container:
275+
276+
```
277+
./sh_script/docker.sh -f container
266278
```

sh_script/docker.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -e
3+
4+
FOLDER=""
5+
6+
usage() {
7+
cat << EOM
8+
Usage: $(basename "$0") [OPTION]...
9+
-d <docker file> Path of Dockerfile.
10+
EOM
11+
}
12+
13+
error() {
14+
echo -e "\e[1;31mERROR: $*\e[0;0m"
15+
exit 1
16+
}
17+
18+
process_args() {
19+
while getopts ":f:h" option; do
20+
case "$option" in
21+
f) FOLDER=$OPTARG;;
22+
h) usage
23+
exit 0
24+
;;
25+
*)
26+
echo "Invalid option '-$OPTARG'"
27+
usage
28+
exit 1
29+
;;
30+
esac
31+
done
32+
33+
if [[ -z ${FOLDER} ]]; then
34+
error "Please specify the folder of where the Dockerfile is located through -f."
35+
fi
36+
37+
if [[ ! -f "${FOLDER}/Dockerfile" ]]; then
38+
error "Dockerfile does not exist."
39+
fi
40+
}
41+
42+
process_args $@
43+
44+
pushd ${FOLDER}
45+
46+
# If the docker image does not exist, build the docker image
47+
set +e && docker image inspect migtd.build.env:latest > /dev/null 2>&1 && set -e
48+
if [ $? != 0 ]; then
49+
docker build -t migtd.build.env \
50+
--build-arg https_proxy=$https_proxy \
51+
--build-arg http_proxy=$http_proxy \
52+
.
53+
fi
54+
55+
popd
56+
57+
# Run the docker image
58+
docker run -it --rm migtd.build.env

0 commit comments

Comments
 (0)