1
1
ARG BASE_IMAGE="ubuntu:20.04"
2
2
ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,aarch64-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu,mips64-softmmu,mips64el-softmmu"
3
- ARG LIBOSI_VERSION= "v0.1.7 "
3
+ ARG INSTALL_PREFIX= "/usr/local/ "
4
4
5
5
# ## BASE IMAGE
6
- FROM $BASE_IMAGE as base
6
+ FROM $BASE_IMAGE AS base
7
7
ARG BASE_IMAGE
8
+ ARG INSTALL_PREFIX
8
9
9
10
# Copy dependencies lists into container. We copy them all and then do a mv because
10
11
# we need to transform base_image into a windows compatible filename which we can't
@@ -16,22 +17,19 @@ RUN mv /tmp/$(echo "$BASE_IMAGE" | sed 's/:/_/g')_build.txt /tmp/build_dep.txt &
16
17
# Base image just needs runtime dependencies
17
18
RUN [ -e /tmp/base_dep.txt ] && \
18
19
apt-get -qq update && \
19
- DEBIAN_FRONTEND=noninteractive apt-get -qq install -y --no-install-recommends curl $(cat /tmp/base_dep.txt | grep -o '^[^#]*' ) && \
20
+ DEBIAN_FRONTEND=noninteractive apt-get -qq install -y --no-install-recommends curl jq $(cat /tmp/base_dep.txt | grep -o '^[^#]*' ) && \
20
21
apt-get clean
21
22
22
23
# ## BUILD IMAGE - STAGE 2
23
24
FROM base AS builder
24
25
ARG BASE_IMAGE
25
26
ARG TARGET_LIST
26
- ARG LIBOSI_VERSION
27
+ ARG INSTALL_PREFIX
27
28
28
29
RUN [ -e /tmp/build_dep.txt ] && \
29
30
apt-get -qq update && \
30
31
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $(cat /tmp/build_dep.txt | grep -o '^[^#]*' ) && \
31
32
apt-get clean && \
32
- python3 -m pip install --upgrade --no-cache-dir pip && \
33
- python3 -m pip install --upgrade --no-cache-dir "cffi>1.14.3" && \
34
- python3 -m pip install --upgrade --no-cache-dir "capstone" && \
35
33
curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal
36
34
37
35
# Then install capstone from source
@@ -43,24 +41,31 @@ RUN cd /tmp && \
43
41
ENV PATH="/root/.cargo/bin:${PATH}"
44
42
45
43
# install libosi
46
- RUN cd /tmp && curl -LJO https://github.com/panda-re/libosi/releases/download/${LIBOSI_VERSION}/libosi_$(echo "$BASE_IMAGE" | awk -F':' '{print $2}' ).deb && dpkg -i /tmp/libosi_$(echo "$BASE_IMAGE" | awk -F':' '{print $2}' ).deb
44
+ RUN cd /tmp && \
45
+ BASE_IMAGE_VERSION=$(echo "$BASE_IMAGE" | awk -F':' '{print $2}' ) && \
46
+ LIBOSI_VERSION=$(curl -s https://api.github.com/repos/panda-re/libosi/releases/latest | jq -r .tag_name) && \
47
+ curl -LJO https://github.com/panda-re/libosi/releases/download/${LIBOSI_VERSION}/libosi_${BASE_IMAGE_VERSION}.deb && \
48
+ dpkg -i /tmp/libosi_${BASE_IMAGE_VERSION}.deb && \
49
+ rm -rf /tmp/libosi_${BASE_IMAGE_VERSION}.deb
47
50
48
51
# Build and install panda
49
52
# Copy repo root directory to /panda, note we explicitly copy in .git directory
50
53
# Note .dockerignore file keeps us from copying things we don't need
54
+ # PyPANDA needs CFFI from pip (the version in apt is too old)
51
55
COPY . /panda/
52
56
COPY .git /panda/
57
+ RUN pip install -r /panda/panda/python/core/requirements.txt
53
58
54
59
# Note we diable NUMA for docker builds because it causes make check to fail in docker
55
60
RUN git -C /panda submodule update --init dtc && \
56
- git -C /panda rev-parse HEAD > /usr/local/ panda_commit_hash && \
61
+ git -C /panda rev-parse HEAD > ${INSTALL_PREFIX} panda_commit_hash && \
57
62
mkdir /panda/build && cd /panda/build && \
58
63
python3 -m pip install setuptools_scm && \
59
64
python3 -m pip install build && \
60
65
python3 -m setuptools_scm -r .. --strip-dev 2>/dev/null >/tmp/savedversion && \
61
66
/panda/configure \
62
67
--target-list="${TARGET_LIST}" \
63
- --prefix=/usr/local \
68
+ --prefix=${INSTALL_PREFIX} \
64
69
--disable-numa \
65
70
--enable-llvm && \
66
71
rm -rf /panda/.git
@@ -69,7 +74,8 @@ RUN git -C /panda submodule update --init dtc && \
69
74
RUN PRETEND_VERSION=$(cat /tmp/savedversion) make -C /panda/build -j "$(nproc)"
70
75
71
76
# ### Develop setup: panda built + pypanda installed (in develop mode) - Stage 3
72
- FROM builder as developer
77
+ FROM builder AS developer
78
+ ARG INSTALL_PREFIX
73
79
RUN cd /panda/panda/python/core && \
74
80
python3 create_panda_datatypes.py && \
75
81
PRETEND_VERSION=$(cat /tmp/savedversion) pip install -e . && \
@@ -82,22 +88,19 @@ RUN cd /panda/panda/python/core && \
82
88
WORKDIR /panda/
83
89
84
90
# ### Install PANDA + pypanda from builder - Stage 4
85
- FROM builder as installer
91
+ FROM builder AS installer
92
+ ARG INSTALL_PREFIX
86
93
RUN make -C /panda/build install && \
87
- rm -r /usr/local/ lib/panda/*/cosi \
88
- /usr/local/ lib/panda/*/cosi_strace \
89
- /usr/local/ lib/panda/*/gdb \
90
- /usr/local/ lib/panda/*/snake_hook \
91
- /usr/local/ lib/panda/*/rust_skeleton
94
+ rm -r ${INSTALL_PREFIX} lib/panda/*/cosi \
95
+ ${INSTALL_PREFIX} lib/panda/*/cosi_strace \
96
+ ${INSTALL_PREFIX} lib/panda/*/gdb \
97
+ ${INSTALL_PREFIX} lib/panda/*/snake_hook \
98
+ ${INSTALL_PREFIX} lib/panda/*/rust_skeleton
92
99
93
- # Install pypanda
94
- RUN cd /panda/panda/python/core && \
95
- python3 create_panda_datatypes.py --install && \
96
- PRETEND_VERSION=$(cat /tmp/savedversion) pip install .
97
- RUN python3 -m pip install --ignore-install pycparser && python3 -m pip install --force-reinstall --no-binary :all: cffi
98
- # Build a whl too
100
+ # Install pypanda and build wheel
99
101
RUN cd /panda/panda/python/core && \
100
102
python3 create_panda_datatypes.py --install && \
103
+ PRETEND_VERSION=$(cat /tmp/savedversion) pip install . && \
101
104
PRETEND_VERSION=$(cat /tmp/savedversion) python3 -m build --wheel .
102
105
103
106
# BUG: PANDA sometimes fails to generate all the necessary files for PyPANDA. This is a temporary fix to detect and fail when this occurs
@@ -106,41 +109,53 @@ RUN bash -c "ls $(pip show pandare | grep Location: | awk '{print $2}')/pandare/
106
109
107
110
# this layer is used to strip shared objects and change python data to be
108
111
# symlinks to the installed panda data directory
109
- FROM installer as cleanup
110
- RUN find /usr/local/lib/panda -name "*.so" -exec strip {} \;
112
+ FROM installer AS cleanup
113
+ ARG INSTALL_PREFIX
114
+ RUN find ${INSTALL_PREFIX}lib/panda -name "*.so" -exec strip {} \;
111
115
RUN PKG=`pip show pandare | grep Location: | awk '{print $2}' `/pandare/data; \
112
- rm -rf $PKG/pc-bios && ln -s /usr/local/ share/panda $PKG/pc-bios; \
116
+ rm -rf $PKG/pc-bios && ln -s ${INSTALL_PREFIX} share/panda $PKG/pc-bios; \
113
117
for arch in `find $PKG -name "*-softmmu" -type d -exec basename {} \; ` ; do \
114
118
ARCHP=$PKG/$arch; \
115
119
SARCH=`echo $arch | cut -d'-' -f 1`; \
116
120
rm $ARCHP/libpanda-$SARCH.so $ARCHP/llvm-helpers-$SARCH.bc; \
117
- ln -s /usr/local/ share/panda/llvm-helpers-$SARCH.bc $ARCHP/llvm-helpers-$SARCH.bc1; \
118
- ln -s /usr/local/ bin/libpanda-$SARCH.so $ARCHP/libpanda-$SARCH.so; \
121
+ ln -s ${INSTALL_PREFIX} share/panda/llvm-helpers-$SARCH.bc $ARCHP/llvm-helpers-$SARCH.bc1; \
122
+ ln -s ${INSTALL_PREFIX} bin/libpanda-$SARCH.so $ARCHP/libpanda-$SARCH.so; \
119
123
rm -rf $ARCHP/panda/plugins; \
120
- ln -s /usr/local/ lib/panda/$SARCH/ $ARCHP/panda/plugins; \
124
+ ln -s ${INSTALL_PREFIX} lib/panda/$SARCH/ $ARCHP/panda/plugins; \
121
125
done
122
126
123
127
# ## Copy files for panda+pypanda from installer - Stage 5
124
- FROM base as panda
128
+ FROM base AS panda
129
+ ARG INSTALL_PREFIX
130
+ ARG TARGET_LIST
125
131
126
132
# Include dependency lists for packager
127
133
COPY --from=base /tmp/base_dep.txt /tmp
128
134
COPY --from=base /tmp/build_dep.txt /tmp
129
135
130
136
# Copy panda + libcapstone.so* + libosi libraries
131
- COPY --from=cleanup /usr/local /usr/local
137
+ COPY --from=cleanup ${INSTALL_PREFIX} ${INSTALL_PREFIX}
132
138
COPY --from=cleanup /usr/lib/libcapstone* /usr/lib/
133
- COPY --from=cleanup /lib/libosi.so /lib/libiohal.so /lib/liboffset.so /lib/
139
+ # TODO: Once PR, https://github.com/panda-re/libosi/pull/17 is in, libosi installs to /usr/lib/x86_64-linux-gnu instead of /usr/lib
140
+ COPY --from=cleanup /usr/lib/libosi.so /usr/lib/libiohal.so /usr/lib/liboffset.so /usr/lib/x86_64-linux-gnu/
134
141
135
142
# Workaround issue #901 - ensure LD_LIBRARY_PATH contains the panda plugins directories
136
- # ARG TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu"
137
- ENV LD_LIBRARY_PATH /usr/local/lib/python3.8/dist-packages/pandare/data/x86_64-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/i386-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/arm-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/ppc-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/mips-softmmu/panda/plugins/:/usr/local/lib/python3.8/dist-packages/pandare/data/mipsel-softmmu/panda/plugins/
138
- # PANDA_PATH is used by rust plugins
139
- ENV PANDA_PATH /usr/local/lib/python3.8/dist-packages/pandare/data
140
-
143
+ RUN LD_LIBRARY_PATH="" && \
144
+ for arch in $(echo $TARGET_LIST | tr ',' ' ' ); do \
145
+ if [ -z "$LD_LIBRARY_PATH" ]; then \
146
+ LD_LIBRARY_PATH="${INSTALL_PREFIX}lib/python3.8/dist-packages/pandare/data/${arch}/panda/plugins/" ; \
147
+ else \
148
+ LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${INSTALL_PREFIX}lib/python3.8/dist-packages/pandare/data/${arch}/panda/plugins/" ; \
149
+ fi \
150
+ done && \
151
+ echo "${LD_LIBRARY_PATH}" > /tmp/ld_library_path
152
+ ENV LD_LIBRARY_PATH $(cat /tmp/ld_library_path)
153
+
154
+ # PANDA_PATH is used by rust plugins
155
+ ENV PANDA_PATH ${INSTALL_PREFIX}lib/python3.8/dist-packages/pandare/data
141
156
142
157
# Ensure runtime dependencies are installed for our libpanda objects and panda plugins
143
158
RUN ldconfig && \
144
159
update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \
145
- if (ldd /usr/local/ lib/python*/dist-packages/pandare/data/*-softmmu/libpanda-*.so | grep 'not found' ); then exit 1; fi && \
146
- if (ldd /usr/local/ lib/python*/dist-packages/pandare/data/*-softmmu/panda/plugins/*.so | grep 'not found' ); then exit 1; fi
160
+ if (ldd ${INSTALL_PREFIX} lib/python*/dist-packages/pandare/data/*-softmmu/libpanda-*.so | grep 'not found' ); then exit 1; fi && \
161
+ if (ldd ${INSTALL_PREFIX} lib/python*/dist-packages/pandare/data/*-softmmu/panda/plugins/*.so | grep 'not found' ); then exit 1; fi
0 commit comments