Skip to content

Commit

Permalink
Chore: Ecalc-1622 setup devcontainer (#624)
Browse files Browse the repository at this point in the history
Jira issue: Ecalc-1622

* chore: create python devcontainer first version

* chore: move poetry env installation from post-create.sh to dockerfile

* fix: comment out python interpreter setting not working and set POETRY_VIRTUALENVS_PROMPT

* fix: add poetry root package installation in post-create script

* docs: add section about devcontainer in readme.md

* docs: add ellipsis to spell checker ignore list

* chore: add testing related extensions to devcontainer.json

* chore: clean up devcontainer extensions and settings
  • Loading branch information
kjbrak authored Sep 27, 2024
1 parent 85ab065 commit a7b7b10
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile → .devcontainer/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Reference: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/javascript-node
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:18
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:18
2 changes: 1 addition & 1 deletion .devcontainer/README.md → .devcontainer/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ use the Ports-tab in order to navigate to the documentation preview.

[GitHub Codespaces Docs](https://docs.github.com/en/codespaces)
[DevContainers Docs](https://docs.docker.com/build/building/base-images/)
[VS Code Remote / GitHub Codespaces Development Container Images](https://hub.docker.com/_/microsoft-vscode-devcontainers)
[VS Code Remote / GitHub Codespaces Development Container Images](https://hub.docker.com/_/microsoft-vscode-devcontainers)
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"git": "latest",
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
}
}
}
60 changes: 60 additions & 0 deletions .devcontainer/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
ARG VARIANT="3.11-bookworm"
FROM mcr.microsoft.com/devcontainers/python:${VARIANT}


ARG DEBIAN_FRONTEND=noninteractive
ARG POETRY_VERSION=1.8.3
ARG POETRY_VIRTUALENVS_PATH
ENV USER=vscode

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
default-jre

# Set non-root user
USER $USER
ENV HOME="/home/$USER"
ENV PATH="${HOME}/.local/bin:$PATH"

# Set poetry related env vars
# Set poetry virtualenv path in writable dir outsde mounted workspace
ENV POETRY_VIRTUALENVS_PATH="$HOME/.venv"
ENV POETRY_VIRTUALENVS_CREATE=true
ENV POETRY_VIRTUALENVS_IN_PROJECT=false
ENV POETRY_VIRTUALENVS_PROMPT='ecalc-py{python_version}'
ENV PIP_DEFAULT_TIMEOUT=100

# Python and poetry installation
RUN echo $(which python) && echo $(which python3) \
&& python3 -m pip install --upgrade pip pipx \
&& pipx install "poetry==${POETRY_VERSION}" \
&& pip install pre-commit \
&& poetry --version \
&& pre-commit --version

# Set workdir to ecalc project
WORKDIR /workspaces/ecalc

# Copy essential file (devcontainer setup takes care of other files)
COPY pyproject.toml poetry.lock ./

# Install poetry environment without root package
RUN poetry install --no-interaction --no-ansi --no-root
44 changes: 44 additions & 0 deletions .devcontainer/python/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Github auth: F.ex. use HTTPS auth for github and a git credential manager in your OS to get your git auth working in the container.
{
"name": "eCalc Python Dev Environment",
"build": {
"dockerfile": "Dockerfile",
"context": "../..",
"args": {
"VARIANT": "3.11-bookworm",
"POETRY_VERSION": "1.8.3",
}
},
"containerEnv": {
},
"customizations": {
"vscode": {
"settings": {
// setting python.defaultInterpreterPath is not working as intended, set python interpreter manually.
"python.testing.pytestArgs": [],
"python.testing.cwd": "${workspaceFolder}/src/tests",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.editor.defaultFormatter": "charliermarsh.ruff",
"ruff.enabled": true,
"terminal.integrated.defaultProfile.linux": "bash",
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"github.copilot",
"charliermarsh.ruff",
"shardulm94.trailing-spaces",
"esbenp.prettier-vscode",
"ms-vscode.test-adapter-converter",
"littlefoxteam.vscode-python-test-adapter"
]
}
},
"remoteUser": "vscode",
"features": {
"github-cli": "latest"
},
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && bash ./.devcontainer/python/post-create.sh"
}
13 changes: 13 additions & 0 deletions .devcontainer/python/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Install Pre-commit hooks
echo "Installing Pre-commit hooks..."
pre-commit install

# Install poetry environment
poetry install

echo "Post-create script completed successfully."
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ docs/.docusaurus/

.DS_store

# local dev files
.DEV/

# generated by "snyk code test"
.dccache

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ ecalc selftest

Please refer to [Docker Docs](https://docs.docker.com/) for details on how to use Docker.

**Alternative using devcontainer**:

In vscode:
- Install extension "Dev Containers" and open command palette (ctrl+p or cmd+p or F1) and click "reopen in container" then click the alternative "eCalc Python Dev Environment".

In github codespaces:
- In the repo click the "<> Code" button -> codespaces -> in the codespaces section click the ellipsis menu (three dots) -> click "New with options.." -> under "Dev container configuration" click and choose "eCalc Python Dev Environment" -> then click button "Create Codespace".


![ecalc-selftest](docs/gifs/selftest.gif)

### Create and run your first model
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ quiet = false

[tool.codespell]
skip = '*.ts,*.lock,*package-lock.json'
ignore-words-list = "installationa, mke" # 'InstallationA' and 'Missing key error'
ignore-words-list = "installationa, mke, ellipsis" # 'InstallationA' and 'Missing key error', ellipsis (...)

0 comments on commit a7b7b10

Please sign in to comment.