Skip to content

Commit 49f70fb

Browse files
committed
add epics-containers style postCreate to devcontainer
1 parent e1b7cc0 commit 49f70fb

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Allow X11 apps to run inside the container
1010
"DISPLAY": "${localEnv:DISPLAY}"
1111
},
12+
"remoteUser": "${localEnv:EC_REMOTE_USER}",
1213
"customizations": {
1314
"vscode": {
1415
// Set *default* container specific settings.json values on container create.
@@ -33,14 +34,16 @@
3334
"upgradePackages": false
3435
}
3536
},
37+
// You can place any outside of the container before-launch commands here
38+
"initializeCommand": "bash .devcontainer/initializeCommand ${devcontainerId}",
39+
// One time global setup commands inside the container
40+
"postCreateCommand": "bash .devcontainer/postCreateCommand ${devcontainerId}",
3641
"runArgs": [
3742
// Allow the container to access the host X11 display and EPICS CA
3843
"--net=host",
3944
// Make sure SELinux does not disable with access to host filesystems like tmp
4045
"--security-opt=label=disable"
4146
],
4247
// Mount the parent as /workspaces so we can pip install peers as editable
43-
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
44-
// After the container is created, install the python project in editable form
45-
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
48+
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind"
4649
}

.devcontainer/initializeCommand

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# custom initialization goes here - runs outside of the dev container
4+
# just before the container is launched but after the container is created
5+
6+
echo "devcontainerID ${1}"

.devcontainer/postCreateCommand

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Custom initialization goes here if needed.
4+
# Runs inside the dev container after the container is created
5+
6+
################################################################################
7+
# When using docker we will not be root inside the container
8+
# the following steps are then required
9+
################################################################################
10+
11+
if [[ $USER != "root" ]] ; then
12+
# make sure the non-root user can access the virtual environment
13+
sudo chown -R ${USER}:${USER} /venv
14+
fi
15+
16+
################################################################################
17+
# Shell customizations
18+
################################################################################
19+
20+
# pick a theme that does not cause completion corruption in zsh
21+
sed -i $HOME/.zshrc -e 's/ZSH_THEME="devcontainers"/ZSH_THEME="lukerandall"/'
22+
23+
# allow personalization of all devcontainers in this subdirectory
24+
# by placing a .devcontainer_rc file in the workspace root
25+
if [[ -f /workspaces/.devcontainer_rc ]] ; then
26+
source /workspaces/.devcontainer_rc
27+
fi
28+
29+
#After the container is created, install the python project in editable form
30+
pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]'
31+
pre-commit install

0 commit comments

Comments
 (0)