Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit c54f84a

Browse files
authored
Remove Python2 from pushed Docker images (#731)
Had to rename the directory where the Python 3 module is installed so that we could hard-code the PYTHONPATH to it, e.g. `lib/python3.6` -> `lib/python3` on Ubuntu 18.04 with default Python version installed by `apt install python3` or `lib/python3.8` -> `lib/python3` for Ubuntu 20.04.
1 parent aa49fcc commit c54f84a

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Test final Docker image
3737
run: |
3838
docker run --rm docker.pkg.github.com/lifting-bits/mcsema/mcsema-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --version
39-
docker run --rm --entrypoint=mcsema-disass-2 docker.pkg.github.com/lifting-bits/mcsema/mcsema-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --help
39+
docker run --rm --entrypoint=mcsema-disass docker.pkg.github.com/lifting-bits/mcsema/mcsema-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --help
4040
- name: Push Image for LLVM ${{ matrix.llvm }} on ${{ matrix.ubuntu }}
4141
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
4242
run: |

Dockerfile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ FROM ${BUILD_BASE} as base
1818
ARG UBUNTU_VERSION
1919
ARG LIBRARIES
2020
RUN apt-get update && \
21-
apt-get install -qqy --no-install-recommends python2.7 zlib1g curl ca-certificates && \
22-
curl https://bootstrap.pypa.io/2.7/get-pip.py --output get-pip.py && python2.7 get-pip.py && \
23-
update-alternatives --install /usr/bin/python2 python2 /usr/bin/python2.7 1 && \
21+
apt-get install -qqy --no-install-recommends python3 python3-pip python3-setuptools python3-six zlib1g curl ca-certificates && \
2422
if [ "${UBUNTU_VERSION}" = "18.04" ] ; then \
2523
apt-get install -qqy --no-install-recommends libtinfo5 ; \
2624
else \
@@ -37,15 +35,11 @@ FROM trailofbits/anvill:llvm${LLVM_VERSION}-${DISTRO_BASE}-${ARCH} as anvill
3735
FROM trailofbits/cxx-common:llvm${LLVM_VERSION}-${DISTRO_BASE}-${ARCH} as deps
3836
ARG LIBRARIES
3937
RUN apt-get update && \
40-
apt-get install -qqy python2.7 python3 python3-pip libc6-dev wget liblzma-dev zlib1g-dev libtinfo-dev curl git build-essential ninja-build libselinux1-dev libbsd-dev ccache && \
38+
apt-get install -qqy python3 python3-pip libc6-dev wget liblzma-dev zlib1g-dev libtinfo-dev curl git build-essential ninja-build libselinux1-dev libbsd-dev ccache && \
4139
if [ "$(uname -m)" = "x86_64" ]; then dpkg --add-architecture i386 && apt-get update && apt-get install -qqy gcc-multilib g++-multilib zip zlib1g-dev:i386; fi && \
4240
rm -rf /var/lib/apt/lists/* && \
4341
pip3 install ccsyspath
4442

45-
# needed for 20.04 support until we migrate to py3
46-
RUN curl https://bootstrap.pypa.io/2.7/get-pip.py --output get-pip.py && python2.7 get-pip.py
47-
RUN update-alternatives --install /usr/bin/python2 python2 /usr/bin/python2.7 1
48-
4943
COPY --from=anvill /opt/trailofbits/remill /opt/trailofbits/remill
5044
COPY --from=anvill /opt/trailofbits/anvill /opt/trailofbits/anvill
5145

@@ -61,9 +55,13 @@ FROM deps as build
6155

6256
COPY . ./
6357

58+
# Need to move python version-specific installation directory to general
59+
# version directory since we don't know exactly which Python3 version Ubutnu
60+
# ships with to set the environment variable PYTHONPATH in dist image
6461
RUN mkdir -p ./build && cd ./build && \
6562
cmake -G Ninja -DCMAKE_PREFIX_PATH="/opt/trailofbits/remill;/opt/trailofbits/anvill" -DMCSEMA_DISABLED_ABI_LIBRARIES:STRING="" -DCMAKE_VERBOSE_MAKEFILE=True -DCMAKE_INSTALL_PREFIX=/opt/trailofbits/mcsema .. && \
66-
cmake --build . --target install
63+
cmake --build . --target install && \
64+
mv "/opt/trailofbits/mcsema/lib/python$(python3 --version 2>&1 | awk '{ print $2 }' | cut -d '.' -f 1-2)" /opt/trailofbits/mcsema/lib/python3
6765

6866
# WORKDIR tests/test_suite_generator
6967
# RUN mkdir -p build && \
@@ -75,7 +73,7 @@ RUN mkdir -p ./build && cd ./build && \
7573
# cmake --build . --target install
7674
#
7775
# RUN cd test_suite && \
78-
# PATH="/opt/trailofbits/mcsema/bin:${PATH}" python2.7 start.py
76+
# PATH="/opt/trailofbits/mcsema/bin:${PATH}" python3 start.py
7977

8078
FROM base as dist
8179
ARG LLVM_VERSION
@@ -89,7 +87,7 @@ COPY --from=build /opt/trailofbits/mcsema /opt/trailofbits/mcsema
8987
COPY scripts/docker-lifter-entrypoint.sh /opt/trailofbits/mcsema
9088
ENV LLVM_VERSION=llvm${LLVM_VERSION} \
9189
PATH="/opt/trailofbits/mcsema/bin:${PATH}" \
92-
PYTHONPATH="/opt/trailofbits/mcsema/lib/python2.7/site-packages"
90+
PYTHONPATH="/opt/trailofbits/mcsema/lib/python3/site-packages"
9391
ENTRYPOINT ["/opt/trailofbits/mcsema/docker-lifter-entrypoint.sh"]
9492

9593
################################

0 commit comments

Comments
 (0)