nquest/.devcontainer/Dockerfile
2023-11-19 22:54:54 +03:00

100 lines
No EOL
3 KiB
Docker

FROM ubuntu
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
# Create system wide environment as root
## Supports linux/amd64 or linux/arm64
ARG TARGETPLATFORM
## Ensure installation does not prompt for input
ARG DEBIAN_FRONTEND=noninteractive
## Install basic tools
RUN apt-get -yq update && \
apt-get -yq upgrade && \
apt-get -yq install \
git \
vim \
tmux \
curl \
wget \
build-essential \
cmake \
gcc \
shellcheck \
unzip \
tree \
software-properties-common \
jq \
gettext-base \
uuid-runtime \
postgresql-client \
sqlite3 \
pandoc \
texlive \
texlive-latex-extra \
wkhtmltopdf \
htop
## Install latest go
RUN GO_VERSION="$(git ls-remote https://github.com/golang/go | grep -oE "refs/tags/go[0-9]+\.[0-9]+(\.[0-9])?$" | sed 's|refs/tags/go||g' | sort --version-sort | tail -n 1)" && \
ARCH=$(basename "${TARGETPLATFORM}") && \
curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-${ARCH}.tar.gz" | tar -xz -C /usr/local
# Customize environment for nonroot user
ARG USERNAME=nonroot
ENV HOME=/home/nonroot
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd --gid "${USER_GID}" "${USERNAME}" && \
useradd --uid "${USER_UID}" --gid "${USER_GID}" --create-home "${USERNAME}" && \
apt-get update && \
apt-get -yq install sudo && \
echo "${USERNAME}" ALL=\(root\) NOPASSWD:ALL > "/etc/sudoers.d/${USERNAME}" && \
chmod 0440 "/etc/sudoers.d/${USERNAME}" && \
usermod -aG docker "${USERNAME}"
USER "${USERNAME}:${USERNAME}"
## Delete default configs
RUN rm "${HOME}/.profile" "${HOME}/.bashrc" && \
touch "${HOME}/.bashrc"
## Install latest node
RUN curl -fsSL "https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh" | PROFILE="${HOME}/.bashrc" bash && \
source "${HOME}/.bashrc" && \
nvm install node && \
nvm use node
## Install go packages
### Note: coc-go installs gopls when using vim - instead of coc-go, just install gopls so it is ready on container startup.
### Other coc-* extensions behave much better.
ENV GOROOT="/usr/local/go"
ENV GOPATH="${HOME}/go"
ENV PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"
RUN go install golang.org/x/tools/gopls@latest && \
go install github.com/go-delve/delve/cmd/dlv@latest
## Customize tmux
RUN echo "set-option -g default-command /bin/bash" > "${HOME}/.tmux.conf" && \
echo "set-option -g mouse on" >> "${HOME}/.tmux.conf"
## Customize bashrc
RUN echo "export TERM=xterm-color" >> "${HOME}/.bashrc" && \
sudo cat /root/.bashrc >> "${HOME}/.bashrc" && \
echo "set -o vi" >> "${HOME}/.bashrc" && \
echo "alias tmux='tmux -u'" >> "${HOME}/.bashrc" && \
echo "export PATH=${PATH}" >> "${HOME}/.bashrc" && \
echo "nvm use node > /dev/null 2>&1" >> "${HOME}/.bashrc"
## Customize .profile
RUN sudo cat /root/.profile >> "${HOME}/.profile"
## Cleanup
RUN sudo apt-get clean && \
sudo rm -rf /var/lib/apt/lists/*
# Mimic VSCode's workspace
RUN mkdir -p "${HOME}/workspaces/dev-container"
WORKDIR "${HOME}/workspaces/dev-container"