restore ubuntu dockerfile

This commit is contained in:
xfy
2024-10-22 15:58:01 +08:00
parent 6359e7602b
commit b5f95e650b
3 changed files with 27 additions and 29 deletions

View File

@ -13,44 +13,40 @@ RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
ARG USER=xfy ARG USER=xfy
ARG UID=1000
ARG GID=1000
RUN groupadd -g ${GID} -o ${USER} \ RUN useradd --groups sudo --no-create-home --shell /bin/zsh ${USER} \
&& useradd --groups sudo -m -u ${UID} -g ${GID} -o --shell /bin/zsh ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \ && echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER} && chmod 0440 /etc/sudoers.d/${USER}
# RUN usermod -o -u ${USER_ID} ${USER} # RUN usermod -o -u ${USER_ID} ${USER}
# RUN usermod -g ${USER_ID} ${USER} # RUN usermod -g ${USER_ID} ${USER}
USER ${USER} USER ${USER}
WORKDIR $HOME WORKDIR /home/${USER}
RUN git clone https://github.com/DefectingCat/dotfiles \ RUN git clone https://github.com/DefectingCat/dotfiles \
# onmyzsh # onmyzsh
&& sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \ && sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
&& rm -rf $HOME/.zshrc \ && rm -rf /home/${USER}/.zshrc \
&& ln -s $HOME/dotfiles/zsh/zshrc $HOME/.zshrc \ && ln -s /home/${USER}/dotfiles/zsh/zshrc /home/${USER}/.zshrc \
&& ln -s $HOME/dotfiles/zsh/p10k.zsh $HOME/.p10k.zsh \ && ln -s /home/${USER}/dotfiles/zsh/p10k.zsh /home/${USER}/.p10k.zsh \
&& bash $HOME/dotfiles/zsh/install-plugins.sh \ && bash /home/${USER}/dotfiles/zsh/install-plugins.sh \
# neovim config # neovim config
&& git clone https://github.com/DefectingCat/nvim $HOME/.config/nvim && git clone https://github.com/DefectingCat/nvim /home/${USER}/.config/nvim
# node # node
RUN HOME=$HOME curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash \ RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
&& export NVM_DIR="/home/$USER/.nvm" \ && export NVM_DIR="/home/$USER/.nvm" \
&& ls -al $NVM_DIR \
&& \. "$NVM_DIR/nvm.sh" \ && \. "$NVM_DIR/nvm.sh" \
&& nvm install --lts \ && nvm install --lts \
&& npm i -g yarn pnpm cgr \ && npm i -g yarn pnpm cgr \
# rustup # rustup
&& curl https://sh.rustup.rs -sSf | sh -s -- -y \ && curl https://sh.rustup.rs -sSf | sh -s -- -y \
# golang # golang
&& git clone https://github.com/go-nv/goenv.git $HOME/.goenv \ && git clone https://github.com/go-nv/goenv.git /home/${USER}/.goenv \
&& $HOME/.goenv/bin/goenv install 1.22.2 \ && /home/${USER}/.goenv/bin/goenv install 1.22.2 \
&& $HOME/.goenv/bin/goenv global 1.22.2 && /home/${USER}/.goenv/bin/goenv global 1.22.2
# lazygit # lazygit
RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \ RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \
&& curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \ && curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \
&& mkdir -p $HOME/.config/lazygit \ && mkdir -p /home/${USER}/.config/lazygit \
&& cp -a $HOME/dotfiles/lazygit/mocha-pink.yml $HOME/.config/lazygit \ && cp -a /home/${USER}/dotfiles/lazygit/mocha-pink.yml /home/${USER}/.config/lazygit \
&& tar zvxf lazygit.tar.gz lazygit \ && tar zvxf lazygit.tar.gz lazygit \
&& sudo install lazygit /usr/local/bin \ && sudo install lazygit /usr/local/bin \
&& rm -rf lazygit \ && rm -rf lazygit \

View File

@ -4,8 +4,9 @@ set -xe
echo $(whoami) echo $(whoami)
# --build-arg UID=$(id -u) \
# --build-arg GID=$(id -g) \
docker build --progress=plain \ docker build --progress=plain \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
--build-arg USER=$(whoami) \ --build-arg USER=$(whoami) \
-t ubuntu-dev . -t ubuntu-dev .

View File

@ -7,18 +7,19 @@ if [ $# -lt 1 ]; then
exit 1 exit 1
fi fi
HOME_FOLDER=$1 # HOME_FOLDER=$1
PROJECT_FOLDER=$2 PROJECT_FOLDER=$1
if [ -z "$(ls -A "$HOME_FOLDER")" ]; then # if [ -z "$(ls -A "$HOME_FOLDER")" ]; then
docker run --rm -itd --name=ubuntu-dev ubuntu-dev || exit 1 # docker run --rm -itd --name=ubuntu-dev ubuntu-dev || exit 1
docker cp ubuntu-dev:/home/xfy/. $HOME_FOLDER || docker stop ubuntu-dev # docker cp ubuntu-dev:/home/xfy/. $HOME_FOLDER || docker stop ubuntu-dev
docker stop ubuntu-dev # docker stop ubuntu-dev
fi # fi
# -v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent
# -v $HOME_FOLDER:/home/xfy \
docker run --rm -it --name=ubuntu-dev \ docker run --rm -it --name=ubuntu-dev \
--user xfy:xfy \ --user xfy:xfy \
-v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent \
-v $HOME_FOLDER:/home/xfy \
-v $PROJECT_FOLDER:/app \ -v $PROJECT_FOLDER:/app \
ubuntu-dev # --user $(id -u):$(id -g) \ ubuntu-dev