add dev container template

This commit is contained in:
Tyler Starr 2024-01-15 00:26:35 -08:00
parent 53ca47a5fb
commit be046acb9e
2 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,57 @@
FROM fedora:latest
ENV TERM xterm-256color
###############################################################################
# install
###############################################################################
# base
RUN dnf install -y \
git \
git-lfs \
python \
python3 \
python3-pip \
python3-tornado \ # for WebAgg matplotlib
gcc \
gcc-c++ \
make \
openssl-devel \
libffi-devel \
redhat-rpm-config \
vim \
tmux \
hostname \
&& dnf clean all
# user
RUN dnf install -y \
neovim
###############################################################################
# general
###############################################################################
# add user
RUN useradd -u 1000 -g 100 -ms /bin/bash dev \
&& echo 'dev:pass' | chpasswd
RUN usermod -aG wheel dev
###############################################################################
# user config
###############################################################################
USER dev
WORKDIR /home/dev
RUN git clone --depth 1 https://github.com/wbthomason/packer.nvim \
~/.local/share/nvim/site/pack/packer/start/packer.nvim
# clone dotfiles
RUN sh -c "$(curl -fsLS get.chezmoi.io)"
ENV PATH="/home/dev/bin:${PATH}"
RUN chezmoi init --apply https://github.com/starr-dusT/dotfiles
CMD ["/bin/bash"]

View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# https://github.com/starr-dusT/dotfiles
image_name="<image name>"
container_name="<container name>"
# if container image doesn't exist build it
if [ "$(docker images -q $image_name)" ]; then
echo "Image exists don't need to build..."
else
docker run -t "$image_name" .
fi
# if container doesn't exist run it else start/attach
if [ "$(docker ps -a --filter "status=exited" --format "{{.Names}}" -f name=$container_name)" ]; then
echo "Attaching to existing container..."
docker start "$container_name"
docker attach "$container_name"
else
echo "Running new container..."
docker run --name "$container_name" --network host -v ./:/home/dev/src -it "$image_name"
fi