Skip to content

Commit 8fb4bcc

Browse files
bearritobstrausseralexanderankintotallyzen
authored
chore(build): improve devcontainers setup with poetry (#506)
1. Replaces uses an image directly. 2. Creates a custom image, still based off the original Image. 3. Installs poetry inside the container. This saves the user about 20 seconds every container load. 4. Installs `pre-commit` in the container. Saves more time. 5. Enables `pre-commit`. From inside the container the user cannot commit without `pre-commit` running. 6. Adds in git autocomplete to the container (see screenshot) 7. Adds in poetry autocomplete to the container (see screenshot) ![devcontainer-completion](https://github.com/testcontainers/testcontainers-python/assets/1908139/11446f78-4fbf-4d08-a997-043ae1632919) --------- Co-authored-by: bstrausser <[email protected]> Co-authored-by: David Ankin <[email protected]> Co-authored-by: Bálint Bartha <[email protected]>
1 parent 63fcd52 commit 8fb4bcc

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.devcontainer/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM mcr.microsoft.com/devcontainers/python:1-3.11-bookworm
2+
3+
4+
RUN \
5+
apt update && apt install bash-completion -y && \
6+
pip install pre-commit && \
7+
curl -sSL https://install.python-poetry.org | POETRY_HOME=/home/vscode/.local python3 -
8+
9+
10+
RUN \
11+
echo >> /home/vscode/.bashrc && \
12+
# add completions to bashrc
13+
# see how ubuntu does it for reference:
14+
# https://git.launchpad.net/ubuntu/+source/base-files/tree/share/dot.bashrc
15+
# https://stackoverflow.com/a/68566555
16+
echo 'if [ -f /etc/bash_completion ] && ! shopt -oq posix; then' >> /home/vscode/.bashrc && \
17+
echo ' . /etc/bash_completion' >> /home/vscode/.bashrc && \
18+
echo 'fi' >> /home/vscode/.bashrc && \
19+
echo >> /home/vscode/.bashrc && \
20+
echo '. <(poetry completions)' >> /home/vscode/.bashrc
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
echo "Running post-create-command.sh"
22

3-
curl -sSL https://install.python-poetry.org | python3 -
4-
3+
pre-commit install
54
poetry install --all-extras

.devcontainer/devcontainer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
{
44
"name": "Python 3",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
6+
"build": {
7+
// Path is relative to the devcontainer.json file.
8+
// We prebuild the image to get poetry into the image
9+
// This saves the user a bit of time, when re-opening containers
10+
"dockerfile": "Dockerfile"
11+
},
12+
713
"features": {
814
"ghcr.io/devcontainers/features/docker-in-docker:2": {
915
"version": "latest",

0 commit comments

Comments
 (0)