Last active
October 14, 2020 17:32
-
-
Save Chuxel/c4a4eeb7e3e9e2007bc02b9b75ea439b to your computer and use it in GitHub Desktop.
Script to ensure using "docker -v" from the workspace folder functions in Codespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "${CODESPACES}" != "true" ]; then | |
echo 'Not in a codespace. Aborting.' | |
exit 0 | |
fi | |
WORKSPACE_PATH_IN_CONTAINER=${1:-"$HOME/workspace"} | |
WORKSPACE_PATH_ON_HOST=${1:-"/var/lib/docker/vsonlinemount/workspace"} | |
VM_CONTAINER_WORKSPACE_PATH=/vm-host/$WORKSPACE_PATH_IN_CONTAINER | |
VM_CONTAINER_WORKSPACE_BASE_FOLDER=$(dirname $VM_CONTAINER_WORKSPACE_PATH) | |
VM_HOST_WORKSPACE_PATH=/vm-host/$WORKSPACE_PATH_ON_HOST | |
echo -e "Workspace path in container: ${WORKSPACE_PATH_IN_CONTAINER}\nWorkspace path on host: ${WORKSPACE_PATH_ON_HOST}" | |
docker run --rm -v /:/vm-host alpine sh -c "\ | |
if [ -L "${VM_CONTAINER_WORKSPACE_PATH}" ]; then echo \"${WORKSPACE_PATH_IN_CONTAINER} already exists on host. Aborting.\" && return 0; fi | |
apk add coreutils > /dev/null \ | |
&& mkdir -p $VM_CONTAINER_WORKSPACE_BASE_FOLDER \ | |
&& cd $VM_CONTAINER_WORKSPACE_BASE_FOLDER \ | |
&& ln -s \$(realpath --relative-to='.' $VM_HOST_WORKSPACE_PATH) .\ | |
&& echo 'Symlink created!'" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment