Skip to content

Commit

Permalink
Fix docker (quantumlib#4230)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanth authored Jun 30, 2021
1 parent 55417ee commit 1433621
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 79 deletions.
34 changes: 6 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM python:3.8-slim AS compile-image
FROM python:3.8-slim AS cirq_base

# Install dependencies.
# rm -rf /var/lib/apt/lists/* cleans up apt cache. See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
python3-pip \
python3-tk \
texlive-latex-base \
latexmk \
git \
locales \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -21,28 +17,10 @@ ENV LC_ALL en_US.UTF-8
# Make python3 default
RUN rm -f /usr/bin/python \
&& ln -s /usr/bin/python3 /usr/bin/python

# Create a virtual enironment to copy over into
# the final docker image
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Copy current folder instead of cloning.
COPY ./ .
COPY requirements.txt .
COPY ./cirq/contrib/contrib-requirements.txt .
COPY ./dev_tools/conf/pip-list-dev-tools.txt .

RUN pip3 install -r requirements.txt -r contrib-requirements.txt -r pip-list-dev-tools.txt

# Install cirq
#cirq stable image
FROM cirq_base AS cirq_stable
RUN pip3 install cirq

FROM python:3.8-slim AS build-image
COPY --from=compile-image /opt/venv /opt/venv

# Make sure scripts in .local are usable:
ENV PATH="/opt/venv/bin:$PATH"

WORKDIR /Cirq
EXPOSE 8888
##cirq pre_release image
FROM cirq_base AS cirq_pre_release
RUN pip3 install cirq --pre
48 changes: 0 additions & 48 deletions dev_tools/Dockerfile

This file was deleted.

39 changes: 39 additions & 0 deletions dev_tools/docker_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import subprocess
import pathlib
import platform
import pytest


def test_docker_stable():
if platform.system() != 'Linux':
pytest.skip("Unsupported os")
root_folder = pathlib.Path(__file__).parent.parent
buildResult = subprocess.run(
['docker', 'build', '--target', 'cirq_stable', '-t', 'cirq_image', '.'], cwd=root_folder
)
assert buildResult.returncode == 0

result = subprocess.run(
['docker run cirq_image python -c "import cirq; assert cirq.__version__ is not None"'],
cwd=root_folder,
shell=True,
)
assert result.returncode == 0


def test_docker_pre():
if platform.system() != 'Linux':
pytest.skip("Unsupported os")
root_folder = pathlib.Path(__file__).parent.parent
buildResult = subprocess.run(
['docker', 'build', '--target', 'cirq_pre_release', '-t', 'cirq_image_pre', '.'],
cwd=root_folder,
)
assert buildResult.returncode == 0

result = subprocess.run(
['docker run cirq_image_pre python -c "import cirq; assert cirq.__version__ is not None"'],
cwd=root_folder,
shell=True,
)
assert result.returncode == 0
10 changes: 7 additions & 3 deletions docs/dev/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ git config blame.ignoreRevsFile .git-blame-ignore-revs
Note that if you are using PyCharm, you might have to Restart & Invalidate Caches to have the change being picked up.

## Docker
You can build the stable and pre_release docker images with our `Dockerfile`.

To do your development in a Docker image, you can build one with our `Dockerfile`.
```bash
docker build -t cirq .
docker run -it cirq python -c "import cirq; print(cirq.google.Foxtail)"
docker build -t cirq --target cirq_stable .
docker run -it cirq python -c "import cirq_google; print(cirq_google.Foxtail)"
```

```bash
docker build -t cirq_pre --target cirq_pre_release .
docker run -it cirq_pre python -c "import cirq_google; print(cirq_google.Foxtail)"
```

If you want to contribute changes to Cirq, you will instead want to fork the repository and submit pull requests from your fork.

Expand Down

0 comments on commit 1433621

Please sign in to comment.