Skip to content

Commit 5ee35c5

Browse files
committed
OPS: Use postattach instead of postcreate for more powerful devcontainer
1 parent 2b688f9 commit 5ee35c5

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@
8181
// Use 'forwardPorts' to make a list of ports inside the container available locally.
8282
"forwardPorts": [80, 443, 5500, 8000],
8383

84-
// Use 'postCreateCommand' to run commands after the container is created.
85-
// Note: Reverting to use pip requirements until we can install private dependencies in GHA with poetry
86-
"postCreateCommand": ". .devcontainer/postcreate.sh",
84+
// Use 'postAttachCommand' to run commands after the container is created and attached (ie git is available).
85+
// This is preferential to postCreateCommand as invoking git (eg for private poetry installs or addition of
86+
// git config preferences) doesn't override injected git configs
87+
// https://stackoverflow.com/a/73097009/3556110
88+
"postAttachCommand": ". .devcontainer/postattach.sh",
8789

8890
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
8991
"remoteUser": "vscode",

.devcontainer/postattach.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/zsh
2+
3+
# Install dependencies
4+
poetry install
5+
6+
# Auto set up remote when pushing new branches
7+
git config --global --add push.autoSetupRemote 1
8+
9+
# Allow precommit to install properly
10+
git config --global --add safe.directory /workspace
11+
12+
# Install precommit hooks
13+
pre-commit install && pre-commit install -t commit-msg
14+
15+
# Set zsh history location
16+
# This is done in postAttach so it's not overridden by the oh-my-zsh devcontainer feature
17+
#
18+
# We leave you to decide, but if you put this into a folder that's been mapped
19+
# into the container, then history will persist over container rebuilds :)
20+
#
21+
# !!!IMPORTANT!!!
22+
# Make sure your .zsh_history file is NOT committed into your repository, as it can contain
23+
# sensitive information. So in this case, you should add
24+
# .devcontainer/.zsh_history
25+
# to your .gitignore file.
26+
export HISTFILE="/workspace/.devcontainer/.zsh_history"
27+
28+
# Add aliases to zshrc file
29+
echo '# Aliases to avoid typing "python manage.py" repeatedly' >> ~/.zshrc
30+
echo 'alias dj="python manage.py"' >> ~/.zshrc
31+
echo 'alias djmm="python manage.py makemigrations"' >> ~/.zshrc
32+
echo 'alias djm="python manage.py migrate"' >> ~/.zshrc
33+
echo 'alias djr="python manage.py runserver"' >> ~/.zshrc
34+
echo 'alias djreset="python manage.py reset_db -c"' >> ~/.zshrc
35+
echo 'alias djs="python manage.py shell_plus"' >> ~/.zshrc
36+
echo 'alias dju="python manage.py show_urls"' >> ~/.zshrc

.devcontainer/postcreate.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-svelte-jsoneditor"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "A widget for django's JSONField using the latest-and-greatest Json Editor"
55
authors = ["Tom Clark <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)