Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 26a4268

Browse files
committed
add devcontainer
1 parent 05a2c5d commit 26a4268

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ideas from https://www.docker.com/blog/containerized-python-development-part-1/
2+
3+
# This file is for use as a .vscode devcontainer as well as a runtime
4+
# container. The devcontainer should be rootful and use podman or docker
5+
# with user namespaces.
6+
7+
ARG BASE="mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye"
8+
FROM ${BASE} as base
9+
10+
# use root to pin where the packages will install
11+
USER root
12+
ENV PATH=/root/.local/bin:$PATH
13+
14+
FROM base as developer
15+
16+
WORKDIR /workspace
17+
COPY . .
18+
19+
# install runtime from DIST if there is one
20+
RUN mkdir -p /root/.local && \
21+
if [ -d dist ] ; then \
22+
touch requirements.txt && \
23+
pip install --user -r requirements.txt dist/*.whl ; \
24+
fi
25+
26+
FROM base as runtime
27+
28+
COPY --from=developer /root/.local /root/.local
29+
30+
ENTRYPOINT ["python3-pip-skeleton"]
31+
CMD ["--version"]

.devcontainer/devcontainer.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
"target": "developer",
8+
"context": "..",
9+
"args": {}
10+
},
11+
"remoteEnv": {
12+
"DISPLAY": "${localEnv:DISPLAY}"
13+
},
14+
// Set *default* container specific settings.json values on container create.
15+
"settings": {
16+
"python.defaultInterpreterPath": "/usr/local/bin/python",
17+
"python.linting.enabled": true,
18+
"python.linting.pylintEnabled": true,
19+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
20+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
21+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
22+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
23+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
24+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
25+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
26+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
27+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
28+
},
29+
// Add the IDs of extensions you want installed when the container is created.
30+
"extensions": [
31+
"ms-python.python",
32+
"ms-python.vscode-pylance",
33+
"streetsidesoftware.code-spell-checker",
34+
"ryanluker.vscode-coverage-gutters",
35+
"mhutchie.git-graph",
36+
"eamodio.gitlens",
37+
"gruntfuggly.todo-tree",
38+
"redhat.vscode-yaml",
39+
"nsd.vscode-epics",
40+
"alefragnani.bookmarks"
41+
],
42+
"features": {
43+
//"docker-from-docker": "20.10",
44+
"git": "os-provided"
45+
},
46+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
47+
// "forwardPorts": [],
48+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
49+
// "remoteUser": "vscode",
50+
// Make sure the files we are mapping into the container exist on the host
51+
"initializeCommand": "bash -c 'for i in $HOME/.inputrc $HOME/.bashrc_dev; do [ -f $i ] || touch $i; done'",
52+
"runArgs": [
53+
"--privileged",
54+
"--net=host",
55+
"-v=${localEnv:HOME}/.ssh:/root/.ssh",
56+
"-v=${localEnv:HOME}/.bashrc_dev:/root/.bashrc",
57+
"-v=${localEnv:HOME}/.inputrc:/root/.inputrc"
58+
],
59+
"mounts": [
60+
// map in home directory - not strictly necessary but may be useful
61+
"source=${localEnv:HOME},target=${localEnv:HOME},type=bind,consistency=cached"
62+
],
63+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
64+
"workspaceFolder": "/workspace",
65+
// After the container is created, install the python project in editable form
66+
// This installs into the system python of the container
67+
"postCreateCommand": "pip install $([ -f requirements_dev.txt ] && echo -r requirements_dev.txt ) -e .[dev]"
68+
}

.devcontainer/local_build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# locally build a runtime container for testing
2+
3+
# first make sure a wheel is built
4+
(
5+
cd ..
6+
pip install build
7+
rm -r dist
8+
python -m build --wheel
9+
)
10+
11+
# make the container name the same as the root folder name of this clone
12+
container_name=$(cd ..; basename $(realpath .))
13+
echo building $container_name ...
14+
15+
# run the build with required build-args for a runtime build
16+
ln -s ../dist .
17+
podman build --build-arg BASE=python:3.10-slim --build-arg ENTRYPOINT=$container_name -t $container_name .. --file ./Dockerfile
18+
unlink dist

0 commit comments

Comments
 (0)