Skip to content

Commit 1433621

Browse files
authored
Fix docker (#4230)
#4134
1 parent 55417ee commit 1433621

File tree

4 files changed

+52
-79
lines changed

4 files changed

+52
-79
lines changed

Dockerfile

+6-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
FROM python:3.8-slim AS compile-image
1+
FROM python:3.8-slim AS cirq_base
22

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

@@ -21,28 +17,10 @@ ENV LC_ALL en_US.UTF-8
2117
# Make python3 default
2218
RUN rm -f /usr/bin/python \
2319
&& ln -s /usr/bin/python3 /usr/bin/python
24-
25-
# Create a virtual enironment to copy over into
26-
# the final docker image
27-
RUN python -m venv /opt/venv
28-
ENV PATH="/opt/venv/bin:$PATH"
29-
30-
# Copy current folder instead of cloning.
31-
COPY ./ .
32-
COPY requirements.txt .
33-
COPY ./cirq/contrib/contrib-requirements.txt .
34-
COPY ./dev_tools/conf/pip-list-dev-tools.txt .
35-
36-
RUN pip3 install -r requirements.txt -r contrib-requirements.txt -r pip-list-dev-tools.txt
37-
38-
# Install cirq
20+
#cirq stable image
21+
FROM cirq_base AS cirq_stable
3922
RUN pip3 install cirq
4023

41-
FROM python:3.8-slim AS build-image
42-
COPY --from=compile-image /opt/venv /opt/venv
43-
44-
# Make sure scripts in .local are usable:
45-
ENV PATH="/opt/venv/bin:$PATH"
46-
47-
WORKDIR /Cirq
48-
EXPOSE 8888
24+
##cirq pre_release image
25+
FROM cirq_base AS cirq_pre_release
26+
RUN pip3 install cirq --pre

dev_tools/Dockerfile

-48
This file was deleted.

dev_tools/docker_test.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import subprocess
2+
import pathlib
3+
import platform
4+
import pytest
5+
6+
7+
def test_docker_stable():
8+
if platform.system() != 'Linux':
9+
pytest.skip("Unsupported os")
10+
root_folder = pathlib.Path(__file__).parent.parent
11+
buildResult = subprocess.run(
12+
['docker', 'build', '--target', 'cirq_stable', '-t', 'cirq_image', '.'], cwd=root_folder
13+
)
14+
assert buildResult.returncode == 0
15+
16+
result = subprocess.run(
17+
['docker run cirq_image python -c "import cirq; assert cirq.__version__ is not None"'],
18+
cwd=root_folder,
19+
shell=True,
20+
)
21+
assert result.returncode == 0
22+
23+
24+
def test_docker_pre():
25+
if platform.system() != 'Linux':
26+
pytest.skip("Unsupported os")
27+
root_folder = pathlib.Path(__file__).parent.parent
28+
buildResult = subprocess.run(
29+
['docker', 'build', '--target', 'cirq_pre_release', '-t', 'cirq_image_pre', '.'],
30+
cwd=root_folder,
31+
)
32+
assert buildResult.returncode == 0
33+
34+
result = subprocess.run(
35+
['docker run cirq_image_pre python -c "import cirq; assert cirq.__version__ is not None"'],
36+
cwd=root_folder,
37+
shell=True,
38+
)
39+
assert result.returncode == 0

docs/dev/development.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ git config blame.ignoreRevsFile .git-blame-ignore-revs
2424
Note that if you are using PyCharm, you might have to Restart & Invalidate Caches to have the change being picked up.
2525

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

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

34+
```bash
35+
docker build -t cirq_pre --target cirq_pre_release .
36+
docker run -it cirq_pre python -c "import cirq_google; print(cirq_google.Foxtail)"
37+
```
3438

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

0 commit comments

Comments
 (0)