From 28d47582bdc4bd69f566221d66fbd17c07252e14 Mon Sep 17 00:00:00 2001 From: Simon Emms Date: Mon, 21 Aug 2023 20:35:29 +0000 Subject: [PATCH] feat(base): check for local dotfiles when running container --- base/.devcontainer/Dockerfile | 1 + base/.devcontainer/devcontainer.json | 15 ++++++++++++-- base/.devcontainer/exec-dotfiles.sh | 30 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 base/.devcontainer/exec-dotfiles.sh diff --git a/base/.devcontainer/Dockerfile b/base/.devcontainer/Dockerfile index c28d1af..2a241bf 100644 --- a/base/.devcontainer/Dockerfile +++ b/base/.devcontainer/Dockerfile @@ -79,6 +79,7 @@ RUN { echo && echo "PS1='\[\033[01;32m\]\u\[\033[00m\] \[\033[01;34m\]\w\[\033[0 COPY --chown=vscode:vscode bash_aliases .bash_aliases COPY --chown=vscode:vscode gitconfig .config/git/config +COPY --chown=vscode:vscode exec-dotfiles.sh $HOME/.local/bin/exec-dotfiles # Custom PATH additions ENV PATH=$HOME/.local/bin:$PATH diff --git a/base/.devcontainer/devcontainer.json b/base/.devcontainer/devcontainer.json index 37708c9..7095377 100644 --- a/base/.devcontainer/devcontainer.json +++ b/base/.devcontainer/devcontainer.json @@ -16,7 +16,18 @@ }, "shutdownAction": "stopContainer", "remoteUser": "vscode", + "initializeCommand": { + "ensure-dotfiles": "mkdir -p ${localEnv:HOME}${localEnv:USERPROFILE}/.dotfiles" + }, "postCreateCommand": { - "direnv": "direnv allow || true" - } + "direnv": "direnv allow || true", + "exec-dotfiles": "exec-dotfiles" + }, + "mounts": [ + { + "source": "${localEnv:HOME}${localEnv:USERPROFILE}/.dotfiles", + "target": "/home/vscode/.dotfiles", + "type": "bind" + } + ] } diff --git a/base/.devcontainer/exec-dotfiles.sh b/base/.devcontainer/exec-dotfiles.sh new file mode 100755 index 0000000..3dd7499 --- /dev/null +++ b/base/.devcontainer/exec-dotfiles.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Copyright 2023 Simon Emms +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This gives the same functionality as Gitpod's implementation +# @link https://www.gitpod.io/docs/configure/user-settings/dotfiles +# @link https://github.com/gitpod-io/gitpod/blob/158a948b4d6bdff636da1d23404f8d9232ea9ff6/components/supervisor/pkg/supervisor/supervisor.go#L524,L687 + +DOTFILES_DIR="${HOME}/.dotfiles" +files=("install.sh" "install" "bootstrap.sh" "bootstrap" "script/bootstrap" "setup.sh" "setup" "script/setup") + +for file in "${files[@]}"; do + full_path="${DOTFILES_DIR}/${file}" + if [ -f "${full_path}" ]; then + echo "Found ${full_path} - executing" + + echo ${full_path} + fi +done