From a92cca2e7b9398ccd88ee810a906b6e6c2af6321 Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Mon, 14 Jan 2019 12:56:39 +1100 Subject: [PATCH 1/4] host --- scripts/bootstrap-host.sh | 49 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/scripts/bootstrap-host.sh b/scripts/bootstrap-host.sh index 9a94eba..974e0c4 100755 --- a/scripts/bootstrap-host.sh +++ b/scripts/bootstrap-host.sh @@ -1,28 +1,47 @@ +# Script is run as root to create the host user +if [ $USER != "root" ]; then + echo "Host configuration script must be run as root!" + exit 1 +fi + # Host user configuration -HOST_USER=$(whoami) -HOST_HOME=$HOME +HOST_USER=jackson +HOST_USER_ID=1000 +HOST_HOME=/$HOST_USER/home -# Container user configuration -CONTAINER_USER=jackson -CONTAINER_HOME=/$CONTAINER_USER/home +# Make the host user home directory +mkdir -p $HOST_HOME -# Install docker on the host -apt update && apt install --yes \ - docker.io +# Create the host user group +groupadd \ + --gid $HOST_USER_ID \ + $HOST_USER -# Add the container user to the docker group on the host -usermod -aG docker $CONTAINER_USER +# Create the host user +useradd \ + --gid $HOST_USER_ID \ + --uid $HOST_USER_ID \ + $HOST_USER + +# Add the host user to the docker group +usermod -aG docker $HOST_USER # Allow connections from docker containers to the host's X server xhost local:docker -# Enable password-less sudo for the container user on the host -echo "$HOST_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers +# Enable password-less sudo for the host user +echo "$HOST_USER ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers # Install alacritty on the host -wget -q -O alacritty.deb https://github.com/jwilm/alacritty/releases/download/v0.2.5/Alacritty-v0.2.5_amd64.deb && \ +wget -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 -wget -q -O $HOST_HOME/.config/alacritty/alacritty.yml https://raw.githubusercontent.com/sabrehagen/dotfiles-alacritty/master/.config/alacritty/alacritty.yml +# Install latest alacritty configuration for host user +ALACRITTY_CONFIG=$HOST_HOME/.config/alacritty/alacritty.yml +mkdir -p $(dirname $ALACRITTY_CONFIG) && \ + wget -q -O $ALACRITTY_CONFIG https://raw.githubusercontent.com/sabrehagen/dotfiles-alacritty/master/.config/alacritty/alacritty.yml && \ + chown $HOST_USER:$HOST_USER $ALACRITTY_CONFIG + +# Swap escape and capslock keys +setxkbmap -option caps:swapescape From ed972ed18b556f0a6ce17c50401e304212e1799a Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Mon, 14 Jan 2019 17:46:35 +1100 Subject: [PATCH 2/4] build --- Dockerfile | 38 +++++++++++++++++--------------------- config/zsh/.zshenv | 5 ++++- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 240468f..6533e49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ RUN groupmod \ # Rename the first non-root user to jackson RUN usermod \ --home $HOME \ - --groups docker \ + --groups $USER,docker \ --login $USER \ --move-home \ $BASE_USER @@ -49,7 +49,7 @@ RUN apt update && apt install --yes \ # Add user to groups required to run chrome RUN groupadd --system chrome && \ - usermod --groups audio,chrome,video $USER + usermod --append --groups audio,chrome,video $USER # Install vs code RUN echo 'deb http://au.archive.ubuntu.com/ubuntu/ xenial main restricted universe' > /etc/apt/sources.list && \ @@ -70,24 +70,6 @@ RUN apt install --yes \ # Enable password-less sudo for user RUN echo "$USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers -# Clear and re-cache zsh plugins -RUN zsh -c "source antigen.zsh; antigen reset; source $HOME/.zshrc" - -# 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 -RUN git clone https://github.com/sabrehagen/dotfiles-vcsh -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 sed -i '1s;^;source $HOME/.zshenv.desktop\n\n;' $HOME/.zshenv - # Add custom binaries COPY bin /usr/local/bin @@ -105,5 +87,19 @@ ENV CONTAINER_IMAGE_NAME sabrehagen/desktop-environment USER $USER WORKDIR $HOME +# Remove base container configuration and clone dotfiles configuration +RUN alias https-to-git="sed 's;https://github.com/\(.*\);git@github.com:\1.git;'" +RUN vcsh clone https://github.com/sabrehagen/dotfiles-alacritty && \ + vcsh clone https://github.com/sabrehagen/dotfiles-code && \ + vcsh clone https://github.com/sabrehagen/dotfiles-scripts + +# Add program configurations +COPY config/tmuxinator $HOME/.config/tmuxinator +COPY config/zsh/.zshenv $HOME/.zshenv.desktop +RUN sed -i '1s;^;source $HOME/.zshenv.desktop\n\n;' $HOME/.zshenv + +# Clear and re-cache zsh plugins +RUN zsh -c "source antigen.zsh; antigen reset; source $HOME/.zshrc" + # Start the long-lived tmux session -CMD zsh -c "tmux new-session -d -s $STEMN_TMUX_SESSION && sleep infinity" +CMD zsh diff --git a/config/zsh/.zshenv b/config/zsh/.zshenv index 69475fb..2e83fb2 100644 --- a/config/zsh/.zshenv +++ b/config/zsh/.zshenv @@ -4,4 +4,7 @@ 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 +STARTUP_DIR=$HOME/repositories/stemn/stemn-backend +if [ -d $STARTUP_DIR ]; then + cd $STARTUP_DIR +fi From 786724a5500feb883ea2c3037c6fbe72b9f3fa12 Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Mon, 14 Jan 2019 18:18:56 +1100 Subject: [PATCH 3/4] volumes --- scripts/bootstrap-host.sh | 18 +++++++++++------- scripts/bootstrap-volumes.sh | 9 +++++++++ scripts/clean-hard.sh | 1 + scripts/start.sh | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/bootstrap-host.sh b/scripts/bootstrap-host.sh index 974e0c4..3946d7b 100755 --- a/scripts/bootstrap-host.sh +++ b/scripts/bootstrap-host.sh @@ -29,6 +29,11 @@ usermod -aG docker $HOST_USER # Allow connections from docker containers to the host's X server xhost local:docker +# Install utilities +apt update && apt install --yes && \ + docker.io && \ + vcsh + # Enable password-less sudo for the host user echo "$HOST_USER ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers @@ -37,11 +42,10 @@ wget -O alacritty.deb https://github.com/jwilm/alacritty/releases/download/v0.2. dpkg -i alacritty.deb && \ rm alacritty.deb -# Install latest alacritty configuration for host user -ALACRITTY_CONFIG=$HOST_HOME/.config/alacritty/alacritty.yml -mkdir -p $(dirname $ALACRITTY_CONFIG) && \ - wget -q -O $ALACRITTY_CONFIG https://raw.githubusercontent.com/sabrehagen/dotfiles-alacritty/master/.config/alacritty/alacritty.yml && \ - chown $HOST_USER:$HOST_USER $ALACRITTY_CONFIG +# Take ownership of all files under the user's directory +chown $HOST_USER:$HOST_USER /$HOST_USER -# Swap escape and capslock keys -setxkbmap -option caps:swapescape +# Install dotfiles configuration for host user +su $HOST_USER +vcsh clone https://github.com/sabrehagen/dotfiles-alacritty.git +vcsh clone https://github.com/sabrehagen/dotfiles-scripts.git diff --git a/scripts/bootstrap-volumes.sh b/scripts/bootstrap-volumes.sh index 50b8884..3cdd0b3 100755 --- a/scripts/bootstrap-volumes.sh +++ b/scripts/bootstrap-volumes.sh @@ -2,6 +2,7 @@ CONTAINER_USER=jackson JACKSON_CONFIG_CHROME=/$CONTAINER_USER/home/.config/google-chrome JACKSON_CONFIG_CODE=/$CONTAINER_USER/home/.config/Code +JACKSON_CONFIG_GITHUB=/$CONTAINER_USER/home/.config/hub # Give the container user ownership of the JACKSON_CONFIG_CHROME volume docker run \ @@ -18,3 +19,11 @@ docker run \ --volume JACKSON_CONFIG_CODE:$JACKSON_CONFIG_CODE \ sabrehagen/desktop-environment:latest \ chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_CODE + +# Give the container user ownership of the JACKSON_CONFIG_GITHUB volume +docker run \ + --rm \ + --user root \ + --volume JACKSON_CONFIG_GITHUB:$JACKSON_CONFIG_GITHUB \ + sabrehagen/desktop-environment:latest \ + chown -R $CONTAINER_USER:$CONTAINER_USER $JACKSON_CONFIG_GITHUB diff --git a/scripts/clean-hard.sh b/scripts/clean-hard.sh index c4db9d5..594df2b 100755 --- a/scripts/clean-hard.sh +++ b/scripts/clean-hard.sh @@ -6,3 +6,4 @@ sh $REPO_ROOT/scripts/clean.sh # Remove volumes that can be recreated from scratch, but require manual configuration in app docker volume rm JACKSON_CONFIG_CODE docker volume rm JACKSON_CONFIG_CHROME +docker volume rm JACKSON_CONFIG_GITHUB diff --git a/scripts/start.sh b/scripts/start.sh index 6a13b69..04867d0 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -15,6 +15,7 @@ docker run \ --env SSH_AUTH_SOCK=$JACKSON_HOME/.ssh/auth.sock \ --env STEMN_GIT_EMAIL="$(git config --get user.email)" \ --env STEMN_GIT_NAME="$(git config --get user.name)" \ + --env STEMN_TMUX_SESSION=desktop-session \ --group-add audio \ --group-add video \ --interactive \ @@ -36,6 +37,7 @@ docker run \ --volume ${SSH_AUTH_SOCK-$HOME/.ssh/auth.sock}:$JACKSON_HOME/.ssh/auth.sock \ --volume JACKSON_CONFIG_CHROME:$JACKSON_HOME/.config/google-chrome \ --volume JACKSON_CONFIG_CODE:$JACKSON_HOME/.config/Code \ + --volume JACKSON_CONFIG_GITHUB:$JACKSON_HOME/.config/hub \ --volume JACKSON_HOME:$JACKSON_HOME \ --workdir $JACKSON_HOME \ sabrehagen/desktop-environment:latest From fa91e711d807f7142bd608fd1449210b593ed738 Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Tue, 15 Jan 2019 11:21:52 +1100 Subject: [PATCH 4/4] mount-hosts --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 04867d0..1ed5f35 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -25,6 +25,7 @@ docker run \ --security-opt seccomp:$REPO_ROOT/config/chrome/chrome.json \ --tty \ --volume /dev/shm:/dev/shm \ + --volume /etc/hosts:/etc/hosts \ --volume /etc/localtime:/etc/localtime:ro \ --volume /tmp/.X11-unix:/tmp/.X11-unix \ --volume /var/run/docker.sock:/var/run/docker.sock \ @@ -37,7 +38,6 @@ docker run \ --volume ${SSH_AUTH_SOCK-$HOME/.ssh/auth.sock}:$JACKSON_HOME/.ssh/auth.sock \ --volume JACKSON_CONFIG_CHROME:$JACKSON_HOME/.config/google-chrome \ --volume JACKSON_CONFIG_CODE:$JACKSON_HOME/.config/Code \ - --volume JACKSON_CONFIG_GITHUB:$JACKSON_HOME/.config/hub \ --volume JACKSON_HOME:$JACKSON_HOME \ --workdir $JACKSON_HOME \ sabrehagen/desktop-environment:latest