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

Setup devcontainer #76

Merged
merged 11 commits into from
May 17, 2022
52 changes: 52 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM paperist/texlive-ja:debian

ARG USERNAME
ARG UID
ARG GID

ENV PYTHON_VERSION="3.9.5"
ENV PYENV_ROOT="/.pyenv"
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
make \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
git \
gpg \
poppler-utils \
gosu \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# gosu is used instead of sudo in postStartCommand of devcontainer.json.
# This command allows a non-root user to run as the root user using gosu.
# ref: https://github.com/tianon/gosu/issues/11
RUN chmod +s /usr/sbin/gosu

RUN git clone https://github.com/pyenv/pyenv.git ${PYENV_ROOT} \
&& pyenv install ${PYTHON_VERSION} \
&& pyenv global ${PYTHON_VERSION} \
&& pyenv rehash \
&& chmod -R 777 /.pyenv

RUN useradd -u $UID -o -m $USERNAME
RUN groupmod -g $GID -o $USERNAME

# Requires $POETRY_HOME to install the location; poetry is installed under /root by default.
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/home/${USERNAME}/.local python3 -
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "LaTeX & Python3",
"dockerComposeFile": [
"./docker-compose.yml"
],
"service": "main",
"initializeCommand": "bash ${localWorkspaceFolder}/.devcontainer/init.sh",
"shutdownAction": "stopCompose",
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"python.defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.linting.mypyEnabled": true,
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
],
"workspaceFolder": "/workspaces/qulacs-visualizer",
"postStartCommand": "/usr/bin/git config --global gpg.program /usr/bin/gpg && gosu root chown vscode .venv",
"remoteUser": "vscode"
}
27 changes: 27 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
main:
container_name: vcs-qulacs-visualizer
build:
context: .
dockerfile: Dockerfile
args:
USERNAME: vscode
# Reads values from .env generated by init.sh.
# Match container's UID/GID with the host's.
UID: $UID
GID: $GID
tty: true
volumes:
- type: bind
source: ..
target: /workspaces/qulacs-visualizer
- type: volume
source: qulacs-visualizer-venv
target: /workspaces/qulacs-visualizer/.venv
volume:
nocopy: true
command: /bin/sh -c "while sleep 1000; do :; done"

volumes:
qulacs-visualizer-venv:
3 changes: 3 additions & 0 deletions .devcontainer/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "UID=$(id -u $USER)" > .devcontainer/.env
echo "GID=$(id -g $USER)" >> .devcontainer/.env
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true