diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ef37e18..5d436cb 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,26 +1,72 @@ +#FROM node:25 +#FROM node:alpine AS development FROM node:18 +# Update apt cache +RUN apt-get update +RUN apt-get install -y + +# Set locale to en_US.UTF-8 +ENV LANG=en_US.UTF-8 +RUN apt-get install -y locales && \ + sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale.gen && \ + dpkg-reconfigure --frontend=noninteractive locales && \ + update-locale LANG=$LANG + # locale-gen en_US.UTF-8 + # Install some apt packages -RUN apt-get update && apt-get install -y sudo zsh git vim tmux lsof +RUN apt-get install -y sudo zsh git vim bat tmux jq lsof gawk + +# Cache busting argument to force re-builds of following steps (e.g. to get latest dotfiles) +ARG CACHE_BUST=1 +# For this to be effictive set `"runArgs": ["--build-arg", "CACHE_BUST=$(date +%s)"]` in devcontainer.json # Variable for default user `node` to be used in the following steps ARG USERNAME=node -# Ensure basic setup of default `node` user +# Set zsh as default shell for `USERNAME` +RUN chsh -s /bin/zsh $USERNAME + +# Ensure basic setup of default user `$USERNAME` # Not needed since node:18 already comes with a node user #RUN useradd -ms /bin/zsh $USERNAME \ # && chown -R node:node /home/$USERNAME -# Set zsh as default shell for node user -RUN chsh -s /bin/zsh node - -# Ensure `node` user has access to `sudo` +# Ensure user `$USERNAME` has full access to `sudo` RUN mkdir -p /etc/sudoers.d \ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME -# Set working directory -WORKDIR /workspace - -# Use non-root user +# From now on continue as user `$USERNAME` in user's home directory USER $USERNAME +WORKDIR ~/ + +# Set zsh as default shell for node user and install zsh-in-docker (ohmyzsh, Powerlevel10k, etc.) +# TODO review plugins, some may not even work without appropriate setup +# TODO consider using dotfiles repo instead (requires: zplug install) +#RUN echo "skip_global_compinit=1" | su - $USERNAME -c tee -a /home/$USERNAME/.zshenv + +# Install zplug +#RUN curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh + +# Clone dotfiles to `/home/$USERNAME/dotfiles` and create all symlinks +RUN git clone https://github.com/cbaoth/dotfiles ~/dotfiles; ~/dotfiles/link.sh; touch ~/.zplug-force-install + +# Start zsh one time with dotfiles to setup stuff (e.g. install zplug and plugins) +RUN zsh -ic true +#RUN ["zsh", "-ic", "source ~/.zplug/init.zsh; "] +#RUN ["zsh", "-ic", "zplug install"] + +# COPY .zshenv .zshrc /home/$USERNAME/ +# RUN chown $USERNAME:$USERNAME /home/$USERNAME/.zshenv /home/$USERNAME/.zshrc +# RUN su - $USERNAME sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh)" -- \ +# -p git \ +# -p git-extras \ +# -p gitfast \ +# -p ssh-agent \ + +ARG CACHE_BUST=0 + +# From now on continue as user `$USERNAME` in dev container working directory +USER $USERNAME +WORKDIR /workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d2a224c..9e6792d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,11 @@ { "name": "React Dev Container", "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "args": { + // Set CACHE_BUST in your local env when you want to force a rebuild + "CACHE_BUST": "${localEnv:CACHE_BUST}" + } }, "customizations": { "vscode": { @@ -21,6 +25,6 @@ "onAutoForward": "notify" } }, - "postCreateCommand": "npm install", + //"postCreateCommand": "npm install", "remoteUser": "node" }