Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QI2-663] Make devcontainer work with ARM #103

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ ENV DEBIAN_FRONTEND noninteractive
# Set up user
ARG USER=vagrant
ENV PATH /home/${USER}/.local/bin:$PATH
RUN groupadd -r ${USER} && useradd -m -r -s /bin/bash -g ${USER} ${USER}
RUN groupadd -r ${USER} && \
useradd -m -r -s /bin/bash -g ${USER} ${USER}

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
sudo && \
apt-get clean && \
echo -n "${USER}:${USER}" | chpasswd && \
echo "${USER} ALL = NOPASSWD: ALL" > /etc/sudoers.d/${USER} && \
chmod 440 /etc/sudoers.d/${USER}

USER ${USER}

RUN pip install --upgrade pip wheel setuptools tox

# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

Expand All @@ -24,18 +35,13 @@ USER root
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
ssh \
sudo \
ca-certificates \
curl \
gnupg \
lsb-release \
openssh-client && \
apt-get clean

RUN echo -n "${USER}:${USER}" | chpasswd && \
echo "${USER} ALL = NOPASSWD: ALL" > /etc/sudoers.d/${USER} && \
chmod 440 /etc/sudoers.d/${USER}

RUN sed -i -e 's/Defaults.*requiretty/#&/' /etc/sudoers && \
sed -i -e 's/\(UsePAM \)yes/\1 no/' /etc/ssh/sshd_config && \
mkdir -p /var/run/sshd /home/${USER}/.ssh/
Expand Down
38 changes: 13 additions & 25 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3
{
"name": "Python 3.10",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"target": "vscode",
"args": {
"USER": "vscode"
"name": "QI2 SDK",
"dockerComposeFile": [
"./docker-compose.yaml"
],
"service": "qi2sdk",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
}
},
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"remoteUser": "vscode"
}
15 changes: 15 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
qi2sdk:
build:
context: .
dockerfile: Dockerfile
target: vscode
args:
USER: vscode
platform: linux/amd64
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
- ..:/workspace:cached
user: vscode
2 changes: 1 addition & 1 deletion examples/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def f(theta):
return f


async def execute(qi) -> None:
def execute(qi) -> None:
"""Run the entire qaoa alogrithm.

Args:
Expand Down
4 changes: 3 additions & 1 deletion quantuminspire/util/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def ensure_config_file_exists(file_path: Path, file_encoding: Optional[str]) ->
"""
if not file_path.exists():
file_path.parent.mkdir(parents=True, exist_ok=True)
file_path.open("w", encoding=file_encoding).write("{}")
file_path.open("w", encoding=file_encoding).write(
'{"auths": {"https://staging.qi2.quantum-inspire.com": {"user_id": 1}}}'
)


def json_config_settings(settings: BaseSettings) -> Any:
Expand Down
4 changes: 3 additions & 1 deletion tests/util/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def test_force_file_into_existence_file_does_not_exist(self) -> None:
configuration.ensure_config_file_exists(path, "utf-8")
path.parent.mkdir.assert_called_once_with(parents=True, exist_ok=True)
path.open.assert_called_once_with("w", encoding="utf-8")
open_mock.write.assert_called_once_with("{}")
open_mock.write.assert_called_once_with(
'{"auths": {"https://staging.qi2.quantum-inspire.com": {"user_id": 1}}}'
)

def test_force_file_into_existence_file_exists(self) -> None:
path = MagicMock()
Expand Down