Skip to content

Commit

Permalink
chore(build): improve devcontainers setup with poetry (#506)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
4 people committed Mar 30, 2024
1 parent 95100a3 commit 99c13b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.11-bookworm


RUN \
apt update && apt install bash-completion -y && \
pip install pre-commit && \
curl -sSL https://install.python-poetry.org | POETRY_HOME=/home/vscode/.local python3 -


RUN \
echo >> /home/vscode/.bashrc && \
# add completions to bashrc
# see how ubuntu does it for reference:
# https://git.launchpad.net/ubuntu/+source/base-files/tree/share/dot.bashrc
# https://stackoverflow.com/a/68566555
echo 'if [ -f /etc/bash_completion ] && ! shopt -oq posix; then' >> /home/vscode/.bashrc && \
echo ' . /etc/bash_completion' >> /home/vscode/.bashrc && \
echo 'fi' >> /home/vscode/.bashrc && \
echo >> /home/vscode/.bashrc && \
echo '. <(poetry completions)' >> /home/vscode/.bashrc
3 changes: 1 addition & 2 deletions .devcontainer/commands/post-create-command.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
echo "Running post-create-command.sh"

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

pre-commit install
poetry install --all-extras
8 changes: 7 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
"build": {
// Path is relative to the devcontainer.json file.
// We prebuild the image to get poetry into the image
// This saves the user a bit of time, when re-opening containers
"dockerfile": "Dockerfile"
},

"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
Expand Down

0 comments on commit 99c13b7

Please sign in to comment.