Skip to content

Commit

Permalink
Dockerfile now takes --build-arg PYTHON_VERSION={major}.{minor}
Browse files Browse the repository at this point in the history
- added .dockerignore file
- cleaned up Dockerfile
- updated contributing.md with example
  • Loading branch information
madhavajay committed Jun 2, 2020
1 parent ffc8881 commit e0446dd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
/third_party
83 changes: 47 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,67 @@
# Pull base image.
FROM python:3.7-slim-buster
# Pull base image
ARG PYTHON_VERSION=3.7
FROM python:${PYTHON_VERSION}-slim-buster

# Set environment variables.
ENV HOME /root
ENV PATH "/root/bin:${PATH}"
# must be redefined after FROM
ARG PYTHON_VERSION=$PYTHON_VERSION
ARG BAZEL_VERSION=3.2.0
ARG BAZEL_INSTALLER=bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh
ARG BAZEL_DOWNLOAD_URL=https://github.com/bazelbuild/bazel/releases/download

# Define working directory.
WORKDIR /root
# Set environment variables
ENV HOME=/root
ENV PROJECT_DIR="${HOME}/PyDP"
ENV PATH="/root/bin:${PATH}"

# Install.
RUN \
apt-get update && \
apt-get -y install software-properties-common \
# Define working directory
WORKDIR ${HOME}

# Install apt-get packages
RUN apt-get update && \
apt-get -y install \
sudo \
wget \
unzip \
zip \
git \
software-properties-common \
gcc \
g++ \
build-essential \
python3-distutils \
pkg-config \
zip \
zlib1g-dev \
git && \
wget https://github.com/bazelbuild/bazel/releases/download/2.1.0/bazel-2.1.0-installer-linux-x86_64.sh && \
chmod +x bazel-2.1.0-installer-linux-x86_64.sh && \
./bazel-2.1.0-installer-linux-x86_64.sh --user && \
export PATH="$PATH:$HOME/bin" && \
rm bazel-2.1.0-installer-linux-x86_64.sh
zlib1g-dev

# get third-party dependencies
WORKDIR /tmp/third_party
# Download and Install Bazel
RUN wget ${BAZEL_DOWNLOAD_URL}/${BAZEL_VERSION}/${BAZEL_INSTALLER} && \
chmod +x ${BAZEL_INSTALLER} && ./${BAZEL_INSTALLER} --user && rm ${BAZEL_INSTALLER}

RUN git clone https://github.com/google/differential-privacy.git
RUN pip3 install pipenv
# Update pip and setuptools and install pipenv
RUN pip install --upgrade pip setuptools wheel && \
pip install pipenv

WORKDIR /root/PyDP
COPY . /root/PyDP
# Change working dir
WORKDIR ${PROJECT_DIR}

RUN rm -rf third_party/differential-privacy/ && \
cp -r /tmp/third_party/* /root/PyDP/third_party
# Copy local source over
COPY . ${PROJECT_DIR}

# Get google dp dependency
RUN mkdir -p third_party && \
cd third_party && \
git clone https://github.com/google/differential-privacy.git

# Remove unused java code
RUN rm -rf third_party/differential-privacy/java && \
rm -rf third_party/differential-privacy/examples/java

# build the bindings using Bazel and create a fresh wheel file after deleting the old one in dist folder.
RUN \
pipenv run bazel build src/python:bindings_test --verbose_failures && \
cp -f ./bazel-bin/src/bindings/pydp.so ./pydp && \
# Build the bindings using Bazel and create a python wheel
RUN pipenv --python ${PYTHON_VERSION} && \
pipenv run bazel build src/python:bindings_test --verbose_failures

RUN cp -f ./bazel-bin/src/bindings/pydp.so ./pydp && \
rm -rf dist/ && \
pipenv run python3 setup.py bdist_wheel && \
pip3 install dist/*.whl
pipenv run python setup.py bdist_wheel && \
pip install dist/*.whl

# Define default command.
CMD ["bash"]
# Default entrypoint
CMD ["/bin/bash"]
8 changes: 7 additions & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ $ pip install dist/*.whl
Dockerfile is added so users on all systems can get involved in development.
Windows developers can start contributing with the help of Docker support.

To build the image:
To build the image with the default python version:

```
$ docker build -t pydp:test .
```

To change the python version use the --build-arg parameter:

```
$ docker build --build-args PYTHON_VERSION=3.8 -t pydp:test .
```

To run the image:

```
Expand Down

0 comments on commit e0446dd

Please sign in to comment.