diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..8e7826259 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +// For use with Visual Studio Code +{ + "name": "${localWorkspaceFolderBasename}", + "dockerComposeFile": [ + "../docker-compose.yaml", + "docker-compose.extend.yaml" + ], + "remoteUser": "rigetti", + "service": "lab", + "workspaceFolder": "/home/rigetti/${localWorkspaceFolderBasename}", + "shutdownAction": "stopCompose", + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "ms-toolsai.jupyter", + ], + "settings": { + "python.defaultInterpreterPath": "/home/quil/.venv/${localWorkspaceFolderBasename}/bin/python", + "python.pythonpath": "/home/rigetti/.venv/${localWorkspaceFolderBasename}/bin/python" + } +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.extend.yaml b/.devcontainer/docker-compose.extend.yaml new file mode 100644 index 000000000..5322049db --- /dev/null +++ b/.devcontainer/docker-compose.extend.yaml @@ -0,0 +1,5 @@ +version: '3' +services: + lab: + # Overrides default command so things don't shut down after the process ends. + command: /bin/bash -c "while sleep 1000; do :; done" diff --git a/Dockerfile b/Dockerfile index 2f49e0de3..175510a34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,67 @@ -# use multi-stage builds to independently pull dependency versions -ARG quilc_version=1.20.0 -ARG qvm_version=1.17.1 -ARG python_version=3.7 +# syntax=docker/dockerfile:1.3 +ARG PYTHON_VERSION=3.9 +FROM python:$PYTHON_VERSION AS dev -# use multi-stage builds to independently pull dependency versions -FROM rigetti/quilc:$quilc_version as quilc -FROM rigetti/qvm:$qvm_version as qvm -FROM python:$python_version-buster +USER root -ARG pyquil_version +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get install -y \ + curl \ + wget \ + git \ + build-essential \ + software-properties-common \ + bash-completion \ + libblas-dev \ + libffi-dev \ + liblapack-dev \ + libzmq3-dev \ + sudo -# copy over the pre-built quilc binary from the first build stage -COPY --from=quilc /src/quilc/quilc /src/quilc/quilc +# Create the docker user 'rigetti' +ENV USER=rigetti +ARG UID=1000 +ARG GID=1000 +RUN addgroup --gid ${GID} ${USER} \ + && adduser \ + --disabled-password \ + --gecos ${USER} \ + --gid ${GID} \ + --uid ${UID} \ + --home /home/rigetti/ \ + ${USER} \ + && usermod -aG sudo ${USER} \ + && passwd -d ${USER} -# copy over the pre-built qvm binary from the second build stage -COPY --from=qvm /src/qvm/qvm /src/qvm/qvm +# Create our project directory and switch to it +ARG PROJECT_SLUG=pyquil +ARG SRC_DIR=. +ENV APP_DIR=/home/${USER}/${PROJECT_SLUG} +RUN mkdir -p ${APP_DIR}/${SRC_DIR} && chown -R ${USER}:${USER} ${APP_DIR}/${SRC_DIR} -# install the missing apt packages that aren't copied over -RUN apt-get update && apt-get -yq dist-upgrade && \ - apt-get install --no-install-recommends -yq \ - git libblas-dev libffi-dev liblapack-dev libzmq3-dev && \ - rm -rf /var/lib/apt/lists/* +WORKDIR ${APP_DIR}/${SRC_DIR} -# install ipython -RUN pip install --no-cache-dir ipython +USER ${USER} -# install pyquil -RUN pip install pyquil==$pyquil_version +# Install poetry +RUN curl -sSL https://install.python-poetry.org | python3 - +ENV PATH="${PATH}:/home/${USER}/.local/bin" +RUN mkdir -p /home/${USER}/.config/pypoetry/ -# use an entrypoint script to add startup commands (qvm & quilc server spinup) -COPY ./entrypoint.sh /src/pyquil/entrypoint.sh -ENTRYPOINT ["/src/pyquil/entrypoint.sh"] -CMD ["ipython"] +# Install the package +COPY --chown=${USER}:${USER} ${SRC_DIR}/README.md ${SRC_DIR}/pyproject.toml ${SRC_DIR}/poetry.lock ./ +COPY --chown=${USER}:${USER} --chmod=775 ${SRC_DIR}/pyquil/__init__.py ./pyquil/__init__.py +RUN poetry install \ + --no-interaction \ + --no-ansi \ + --extras latex +RUN rm -r ./pyquil + +# Set up the venv +RUN mkdir ${HOME}/.venv/ && ln -s $(poetry env info -p) /home/${USER}/.venv/${PROJECT_SLUG} +ENV VIRTUAL_ENV=/home/${USER}/.venv/${PROJECT_SLUG} +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +WORKDIR ${APP_DIR} +ENV SHELL /bin/bash diff --git a/docker-compose.yaml b/docker-compose.yaml index 45c062e74..f43c553eb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,27 +1,27 @@ -version: '3' +version: '3.5' services: + lab: + build: + context: . + dockerfile: Dockerfile + args: + PYTHON_VERSION: ${PYTHON_VERSION:-3.9} + volumes: + - .:/home/rigetti/pyquil/ + environment: + - QCS_SETTINGS_APPLICATIONS_PYQUIL_QVM_URL=http://qvm:5000 + - QCS_SETTINGS_APPLICATIONS_PYQUIL_QUILC_URL=tcp://quilc:5555 quilc: image: rigetti/quilc - command: -S - expose: + command: + - -R + - -p - "5555" - ports: - - '5555:5555' - networks: - - test - + - -P qvm: image: rigetti/qvm - command: -S - expose: + command: + - -p - "5000" - ports: - - '5000:5000' - networks: - - test - -networks: - test: - driver: bridge - + - -S diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 946cec47d..000000000 --- a/entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -echo -e "=========================================" -echo -e "= WELCOME TO THE RIGETTI FOREST SDK =" -echo -e "=========================================" -echo -e "Copyright (c) 2016-2019 Rigetti Computing\n" - -/src/quilc/quilc --quiet -R &> quilc.log & -/src/qvm/qvm --quiet -S &> qvm.log & - -exec "$@"