devcontainer: handle hosts without X11 (#29537)

* Setup xauthority link on host in initializeCommand

* Create a dummy xauthority if it does no exist on host machine

* Remove xauthority line from ci test
old-commit-hash: 659795b1db
beeps
Kacper Rączy 2 years ago committed by GitHub
parent 004a097c95
commit 3681c1d1b2
  1. 1
      .devcontainer/.gitignore
  2. 3
      .devcontainer/devcontainer.json
  3. 16
      .devcontainer/setup_host.sh
  4. 4
      .github/workflows/tools_tests.yaml

@ -0,0 +1 @@
.Xauthority

@ -5,6 +5,7 @@
}, },
"postCreateCommand": "bash -c 'if [[ $DISPLAY == *xquartz* ]]; then echo \"export DISPLAY=host.docker.internal:0\" >> /root/.bashrc; fi'", "postCreateCommand": "bash -c 'if [[ $DISPLAY == *xquartz* ]]; then echo \"export DISPLAY=host.docker.internal:0\" >> /root/.bashrc; fi'",
"postStartCommand": "git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | xargs -I{} git config --global --add safe.directory \"$PWD/{}\"", "postStartCommand": "git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | xargs -I{} git config --global --add safe.directory \"$PWD/{}\"",
"initializeCommand": ".devcontainer/setup_host.sh",
"privileged": true, "privileged": true,
"containerEnv": { "containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}", "DISPLAY": "${localEnv:DISPLAY}",
@ -13,7 +14,7 @@
}, },
"runArgs": [ "runArgs": [
"--volume=/tmp/.X11-unix:/tmp/.X11-unix", "--volume=/tmp/.X11-unix:/tmp/.X11-unix",
"--volume=${localEnv:XAUTHORITY}:/root/.Xauthority", "--volume=${localWorkspaceFolder}/.devcontainer/.Xauthority:/root/.Xauthority",
"--volume=${localEnv:HOME}/.comma:/root/.comma", "--volume=${localEnv:HOME}/.comma:/root/.comma",
"--volume=/tmp/comma_download_cache:/tmp/comma_download_cache", "--volume=/tmp/comma_download_cache:/tmp/comma_download_cache",
"--volume=/tmp/devcontainer_scons_cache:/tmp/scons_cache", "--volume=/tmp/devcontainer_scons_cache:/tmp/scons_cache",

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# setup links to Xauthority
XAUTHORITY_LINK=".devcontainer/.Xauthority"
rm -f $XAUTHORITY_LINK
if [[ -z $XAUTHORITY ]]; then
echo "XAUTHORITY not set. Fallback to ~/.Xauthority ..."
if ! [[ -f $HOME/.Xauthority ]]; then
echo "~/.XAuthority file does not exist. GUI tools may not work properly."
touch $XAUTHORITY_LINK # dummy file to satisfy container volume mount
else
ln -sf $HOME/.Xauthority $XAUTHORITY_LINK
fi
else
ln -sf $XAUTHORITY $XAUTHORITY_LINK
fi

@ -105,8 +105,6 @@ jobs:
- name: Build dev container image - name: Build dev container image
run: devcontainer build --workspace-folder . run: devcontainer build --workspace-folder .
- name: Run dev container - name: Run dev container
run: | run: devcontainer up --workspace-folder .
export XAUTHORITY="$HOME/.Xauthority"
devcontainer up --workspace-folder .
- name: Test environment - name: Test environment
run: devcontainer exec --workspace-folder . scons --dry-run run: devcontainer exec --workspace-folder . scons --dry-run

Loading…
Cancel
Save