From b0ab07cac3f203ff9d81dbdf2f3c6e57ed30e220 Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Sun, 13 Jan 2019 16:44:51 +1100 Subject: [PATCH] bootstrap --- Dockerfile | 10 +++++----- config/zsh/.zshenv | 5 +++++ scripts/bootstrap-host.sh | 17 +++++++++++++++++ scripts/bootstrap-volumes.sh | 23 ++++++++++++++++++++++ scripts/bootstrap.sh | 37 +++++------------------------------- scripts/clean.sh | 1 + 6 files changed, 56 insertions(+), 37 deletions(-) create mode 100755 scripts/bootstrap-host.sh create mode 100755 scripts/bootstrap-volumes.sh diff --git a/Dockerfile b/Dockerfile index a9c3e53..f8f0042 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,15 +60,15 @@ RUN wget -O rescuetime.deb -nv https://www.rescuetime.com/installers/rescuetime_ # Install operating system utilities RUN apt install --yes \ - sudo \ vcsh # Enable password-less sudo for user -RUN echo "$USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers +RUN echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers # Clone dotfiles configuration RUN alias https-to-git="sed 's;https://github.com/\(.*\);git@github.com:\1.git;'" RUN git clone https://github.com/sabrehagen/dotfiles-alacritty +RUN git clone https://github.com/sabrehagen/dotfiles-code RUN git clone https://github.com/sabrehagen/dotfiles-git RUN git clone https://github.com/sabrehagen/dotfiles-scripts RUN git clone https://github.com/sabrehagen/dotfiles-tmux @@ -78,13 +78,13 @@ RUN git clone https://github.com/sabrehagen/dotfiles-zsh # Add program configurations COPY config/tmuxinator $HOME/.config/tmuxinator COPY config/zsh/.zshenv $HOME/.zshenv.desktop -RUN echo "source $HOME/.zshenv.desktop" >> $HOME/.zshenv +RUN sed -i '1s;^;source $HOME/.zshenv.desktop\n\n;' $HOME/.zshenv # Add custom binaries COPY bin /usr/local/bin # Remove root ownership of all files under non-root user directory -RUN chown -R $USER:$USER $HOME +RUN chown -R $USER:$USER /$USER # Record container build information ARG CONTAINER_BUILD_DATE @@ -98,4 +98,4 @@ USER $USER WORKDIR $HOME # Start the long-lived tmux session -ENTRYPOINT zsh -c "tmux -S $HOME/.tmux/tmux.sock new-session -d -s $STEMN_TMUX_SESSION && sleep infinity" +ENTRYPOINT zsh -c "tmux new-session -d -s $STEMN_TMUX_SESSION && sleep infinity" diff --git a/config/zsh/.zshenv b/config/zsh/.zshenv index c577fea..69475fb 100644 --- a/config/zsh/.zshenv +++ b/config/zsh/.zshenv @@ -1,2 +1,7 @@ +# Configure tmux to always use utf8 mode and a fixed socket path +export CONTAINER_TMUX_SOCKET=$HOME/.tmux/tmux.sock +touch $CONTAINER_TMUX_SOCKET +alias tmux="tmux -u -S $CONTAINER_TMUX_SOCKET" + # Change to the most frequently used directory cd $HOME/repositories/stemn/stemn-backend diff --git a/scripts/bootstrap-host.sh b/scripts/bootstrap-host.sh new file mode 100755 index 0000000..909fb19 --- /dev/null +++ b/scripts/bootstrap-host.sh @@ -0,0 +1,17 @@ +# Host machine user configuration +HOST_HOME=$HOME +HOST_USER=$(whoami) + +# Allow connections from docker containers to the host machine's X server +xhost local:docker + +# Enable password-less sudo for the user on the host machine +echo "$HOST_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers + +# Install alacritty +wget -q -O alacritty.deb https://github.com/jwilm/alacritty/releases/download/v0.2.5/Alacritty-v0.2.5_amd64.deb && \ + dpkg -i alacritty.deb && \ + rm alacritty.deb + +# Install the latest alacritty config on the host machine +wget -q -O $HOST_HOME/.config/alacritty/alacritty.yml https://raw.githubusercontent.com/sabrehagen/dotfiles-alacritty/master/.config/alacritty/alacritty.yml diff --git a/scripts/bootstrap-volumes.sh b/scripts/bootstrap-volumes.sh new file mode 100755 index 0000000..c60c6c7 --- /dev/null +++ b/scripts/bootstrap-volumes.sh @@ -0,0 +1,23 @@ +# Jackson container user configuration +CONTAINER_USER=jackson +CONTAINER_HOME=/$CONTAINER_USER/home + +# Jackson container volume configuration +JACKSON_CONFIG_CHROME=$CONTAINER_HOME/.config/google-chrome +JACKSON_CONFIG_CODE=$CONTAINER_HOME/.config/Code + +# Give the container user ownership of the JACKSON_CONFIG_CHROME volume +docker run \ + --rm \ + --user root \ + --volume JACKSON_CONFIG_CHROME:$JACKSON_CONFIG_CHROME \ + sabrehagen/desktop-environment:latest \ + chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_CHROME + +# Give the container user ownership of the JACKSON_CONFIG_CODE volume +docker run \ + --rm \ + --user root \ + --volume JACKSON_CONFIG_CODE:$JACKSON_CONFIG_CODE \ + sabrehagen/desktop-environment:latest \ + chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_CODE diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index f42b834..e670299 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,34 +1,7 @@ -# Host machine user configuration -HOST_HOME=$HOME -HOST_USER=$(whoami) +REPO_ROOT=$(dirname $(realpath $0))/.. -# Jackson container user configuration -CONTAINER_USER=jackson -CONTAINER_HOME=/$CONTAINER_USER/home -JACKSON_CONFIG_CHROME=$CONTAINER_HOME/.config/google-chrome -JACKSON_CONFIG_CODE=$CONTAINER_HOME/.config/Code +# Bootstrap the local host +sh $REPO_ROOT/scripts/bootstrap-host.sh -# Allow connections from docker containers to the host's X server -xhost local:docker - -# Enable password-less sudo for the host user -echo "$HOST_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers - -# Install the latest alacritty config on the host -wget -q -O $HOST_HOME/.config/alacritty/alacritty.yml https://raw.githubusercontent.com/sabrehagen/dotfiles-alacritty/master/.config/alacritty/alacritty.yml - -# Take ownership of the JACKSON_CONFIG_CHROME volume -docker run \ - --rm \ - --user root \ - --volume JACKSON_CONFIG_CHROME:$JACKSON_CONFIG_CHROME \ - sabrehagen/desktop-environment:latest \ - chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_CHROME - -# Take ownership of the JACKSON_CONFIG_CODE volume -docker run \ - --rm \ - --user root \ - --volume JACKSON_CONFIG_CODE:$JACKSON_CONFIG_CODE \ - sabrehagen/desktop-environment:latest \ - chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_CODE +# Bootstrap the docker volumes +sh $REPO_ROOT/scripts/bootstrap-volumes.sh diff --git a/scripts/clean.sh b/scripts/clean.sh index 3b9904c..62aa3ed 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -3,4 +3,5 @@ REPO_ROOT=$(dirname $(realpath $0))/.. # Stop the running environment so there are no containers using the volumes, ignoring errors if it does not exist sh $REPO_ROOT/scripts/stop.sh 2>/dev/null +# Remove volumes that can be recreated from scratch, directly from the container filesystem docker volume rm JACKSON_HOME