From 12d081b9fceb42c3c74a5551ae0633b837b2d47a Mon Sep 17 00:00:00 2001 From: Ned Bingham Date: Sat, 3 Jun 2023 15:44:43 +0000 Subject: [PATCH] x11 forwarding now works --- Dockerfile | 26 +++++++++++++++----------- bcli-develop.sh | 4 ++-- home/.Xauthority | 0 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 home/.Xauthority diff --git a/Dockerfile b/Dockerfile index cca4160..1916376 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,16 +68,6 @@ RUN apt-get -y install wget RUN /usr/bin/wget https://go.dev/dl/go1.19.1.linux-amd64.tar.gz RUN tar -C /opt -xzf go1.19.1.linux-amd64.tar.gz -# install editors -WORKDIR "/" -ADD home template -RUN apt-get install -y vim -RUN mkdir -p /template/.vim/pack/plugins/start -RUN git clone https://www.github.com/fatih/vim-go.git /template/.vim/pack/plugins/start/vim-go -RUN git clone https://github.com/tpope/vim-fugitive /template/.vim/pack/plugins/start/fugitive -RUN git clone https://www.github.com/preservim/nerdtree.git /template/.vim/pack/plugins/start/nerdtree -RUN vim +GoInstallBinaries +qall - # install gaw RUN apt-get update --fix-missing; DEBIAN_FRONTEND=noninteractive apt-get install -y libgtk-3-dev libcanberra-gtk3-module WORKDIR /toolsrc @@ -163,6 +153,18 @@ WORKDIR /toolsrc RUN --mount=type=secret,id=user --mount=type=secret,id=token git clone https://$(cat /run/secrets/user):$(cat /run/secrets/token)@git.broccolimicro.io/Broccoli/pr.git RUN cp -r pr/* /opt/cad/bin +RUN apt-get -y install sudo + +# install editors +WORKDIR "/" +ADD home template +RUN apt-get install -y vim +RUN mkdir -p /template/.vim/pack/plugins/start +RUN git clone https://www.github.com/fatih/vim-go.git /template/.vim/pack/plugins/start/vim-go +RUN git clone https://github.com/tpope/vim-fugitive /template/.vim/pack/plugins/start/fugitive +RUN git clone https://www.github.com/preservim/nerdtree.git /template/.vim/pack/plugins/start/nerdtree +RUN vim +GoInstallBinaries +qall + # Clean up source code folder #RUN rm -rf /toolsrc @@ -176,11 +178,13 @@ ENV USER "bcli" ENV USER_ID "1000" ENV GROUP_ID "1000" ENV MEMBERS "" +ENV XAUTH_TOKEN "" -RUN echo "HELLO!?!?1" CMD exec /bin/bash -c "echo \"$MEMBERS\" | sed 's/ /\n/g' | xargs -n 2 /usr/sbin/groupadd -g; \ /usr/sbin/useradd -u $USER_ID -g $USER $USER; \ echo \"$MEMBERS\" | sed 's/ [0-9]\+ /,/g' | sed 's/[0-9]\+ //g' | xargs -I{} /usr/sbin/usermod -aG {} $USER; \ cp -r /template /home/$USER; \ + xauth -f /home/$USER/.Xauthority add $XAUTH_TOKEN; \ chown -R $USER:$USER /home/$USER; \ + /usr/sbin/usermod -p \$(openssl passwd -1 'bcli') $USER; \ trap : TERM INT; sleep infinity & wait" diff --git a/bcli-develop.sh b/bcli-develop.sh index d13eca3..c7646ad 100644 --- a/bcli-develop.sh +++ b/bcli-develop.sh @@ -1,7 +1,7 @@ bcli() { if [ "$1" = "up" ]; then export MEMBERS="$(groups | sed 's/ /\n/g' | xargs -I{} getent group {} | sed 's/\([^:]*\):[^:]*:\([^:]*\):.*/\2 \1/g')" - docker run --rm -d -v $HOME:/host -v "/opt/tech:/opt/cad/conf" --name "bcli-$USER" -h "bcli-$USER" -e USER=$USER -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -e DISPLAY=$DISPLAY -e MEMBERS="$MEMBERS" -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" public.ecr.aws/l5h5o6z4/broccoli-cli:latest > /dev/null + docker run --rm -d --net=host -v $HOME:/host -v "/opt/tech:/opt/cad/conf" --name "bcli-$USER" -h "bcli-$USER" -e USER=$USER -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -e DISPLAY=$DISPLAY -e MEMBERS="$MEMBERS" -e XAUTH_TOKEN="$(xauth list | sed 's/^[^:]*/localhost/g')" -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" public.ecr.aws/l5h5o6z4/broccoli-cli:latest > /dev/null #docker run --rm -d -v $HOME:/host -v "${BCLI_TECH:/opt/tech}:/opt/cad/conf" --name "bcli-$USER" -h "bcli-$USER" -e USER=$USER -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) -e DISPLAY=$DISPLAY -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" ${BCLI_IMAGE:-public.ecr.aws/l5h5o6z4/broccoli-cli:latest} > /dev/null echo "bcli-$USER started" elif [ "$1" = "down" ]; then @@ -29,7 +29,7 @@ bcli() { if [[ "$PWD" = "$HOME/"* ]]; then WD="/host${PWD#$HOME}" fi - docker exec -u $(id -u) -w $WD -it "bcli-$USER" /bin/bash + docker exec -u $(id -u) -w $WD -e DISPLAY=$DISPLAY -it "bcli-$USER" /bin/bash else if [ "$1" != "--help" ]; then echo "error: unrecognized command '$1'" diff --git a/home/.Xauthority b/home/.Xauthority new file mode 100644 index 0000000..e69de29