~nka/docker-debian-dev

c85c7c0c169926d54b02a561a19c1df3fca5f6a3 — Nicolas Karolak 9 months ago 123d9ef main
update
M Dockerfile => Dockerfile +39 -82
@@ 1,43 1,60 @@
FROM debian:buster

# set local user settings
ARG USERNAME=code
ARG GROUPNAME=code
ARG USER_UID=1000
ARG USER_GID=1000

# avoid locale warning messages
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV LANGUAGE en_US.UTF-8
# set the default shell to bash instead of sh
ENV SHELL /bin/bash
# set home path
ENV HOME /home/$USERNAME
# avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# add local user bin to path
ENV PATH "${HOME}/.local/bin:${PATH}"

# configure shell
COPY /files/bashrc /etc/skel/.bashrc

# copy entrypoint scripts
COPY /scripts/container-entrypoint.sh /
COPY /scripts/container-entrypoint.d/* /container-entrypoint.d/

RUN \
    # create user and group
    groupadd --gid $USER_GID $GROUPNAME && \
    useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
    mkdir -p /etc/sudoers.d && \
    echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
    chmod 0440 /etc/sudoers.d/$USERNAME && \
    # configure apt-get
    apt-get update && \
    apt-get install --reinstall coreutils -y && \
    apt-get install --no-install-recommends -y \
        apt-utils \
        dialog \
	man-db \
        man-db \
        && \
    :

RUN \
    # install net tools
    # install tools
    apt-get install --no-install-recommends -y \
        # network
        curl \
        mtr \
        openssh-client \
        iproute2 \
        iputils-ping \
        traceroute \
        && \
    :

RUN \
    # install sys tools
    apt-get install --no-install-recommends -y \
        # system
        bash \
        bash-completion \
	bsdmainutils \
        bsdmainutils \
        ca-certificates \
        gnupg \
        less \


@@ 48,98 65,38 @@ RUN \
        strace \
        sudo \
        unzip \
        && \
    :

RUN \
    # install dev tools
    apt-get install --no-install-recommends -y \
        # development
        build-essential \
        git \
        git-lfs \
        make \
        neovim \
        python3-neovim \
        python3-pip \
        python3-setuptools \
        python3-wheel \
        vim \
        && \
    # install Docker CE CLI.
    curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | apt-key add - && \
    echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | \
        tee /etc/apt/sources.list.d/docker.list && \
    apt-get update && \
    apt-get install -y \
        docker-ce-cli \
	docker-compose \
	&& \
    groupadd --system docker && \
    :

RUN \
    # clean up
    apt-get autoremove -y && \
    apt-get clean -y && \
    rm -rf /var/lib/apt/lists/* &&  \
    # locales
    locale-gen && \
    # create user directories
    sudo -u $USERNAME mkdir -p \
        $HOME/.config \
        $HOME/.local/bin \
        && \
    # add vim plugin manager
    sudo -u $USERNAME curl -fLo $HOME/.vim/autoload/plug.vim --create-dirs \
        https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim && \
    :

# configure shell
COPY /files/bashrc /etc/skel/.bashrc

# switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog

# set local user settings
ARG USERNAME=code
ARG GROUPNAME=code
ARG USER_UID=1000
ARG USER_GID=1000

RUN \
    # create user and group
    groupadd --gid $USER_GID $GROUPNAME && \
    useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
    usermod -aG docker $USERNAME && \
    echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
    chmod 0440 /etc/sudoers.d/$USERNAME && \
    :

# set home path
ENV HOME /home/$USERNAME

# add local user bin to path
ENV PATH "${HOME}/.local/bin:${PATH}"

# set the default user
USER $USERNAME

RUN \
    # create user directories
    mkdir -p \
        $HOME/.config \
        $HOME/.local/bin \
        $HOME/.local/share \
        && \
    # pynvim
    python3 -m pip install --user --upgrade \
	msgpack \
    	pynvim \
	&& \
    # add nvim plugin manager
    curl -fsSL \
        https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
        --create-dirs -o $HOME/.local/share/nvim/site/autoload/plug.vim && \
    :

# set working directory
WORKDIR /workspace

# copy entrypoint scripts
COPY /scripts/container-entrypoint.sh /
COPY /scripts/container-entrypoint.d/* /container-entrypoint.d/

# wrapper script as entrypoint
ENTRYPOINT [ "/container-entrypoint.sh" ]


M Makefile => Makefile +1 -1
@@ 5,7 5,7 @@ all: help

.PHONY: build
## build: Builds the docker image
build: pull
build:
	@echo "Building..."
	@docker build -t ${DOCKER_IMAGE_NAME} .


M scripts/container-entrypoint.d/docker-group => scripts/container-entrypoint.d/docker-group +1 -1
@@ 1,4 1,4 @@
#!/usr/bin/env bash
#!/bin/sh

if [ -e /var/run/docker.sock ]; then
    # make the GID match with docker on the host

M scripts/container-entrypoint.d/gpg-agent => scripts/container-entrypoint.d/gpg-agent +2 -2
@@ 1,5 1,5 @@
#!/usr/bin/env bash
#!/bin/sh

if [ -d ~/.config/gnupg ]; then
if [ -d ~/.config/gnupg ] || [ -d ~/.gnupg ] && command -v gpg > /dev/null; then
	gpg-agent --daemon &> /dev/null
fi

D scripts/container-entrypoint.d/nvim-plugins => scripts/container-entrypoint.d/nvim-plugins +0 -7
@@ 1,7 0,0 @@
#!/usr/bin/env bash

if [ $(command -v nvim) ]; then
	nvim --headless +"PlugInstall!" +"qa!" &> /dev/null
	nvim --headless +"UpdateRemotePlugins" +"qa!" &> /dev/null
fi


A scripts/container-entrypoint.d/ssh-agent => scripts/container-entrypoint.d/ssh-agent +26 -0
@@ 0,0 1,26 @@
#!/bin/sh

# Ensure agent is running
ssh-add -l &>/dev/null
if [ "$?" == 2  ]; then
    # Could not open a connection to your authentication agent.

    # Load stored agent connection info.
    test -r ~/.ssh-agent && \
        eval "$(<~/.ssh-agent)" >/dev/null

    ssh-add -l &>/dev/null
    if [ "$?" == 2  ]; then
        # Start agent and store agent connection info.
        (umask 066; ssh-agent > ~/.ssh-agent)
        eval "$(<~/.ssh-agent)" >/dev/null
    fi
fi

# Load identities
ssh-add -l &>/dev/null
if [ "$?" == 1  ]; then
    # The agent has no identities.
    # Time to add one.
    ssh-add -t 4h
fi

A scripts/container-entrypoint.d/vim-plug => scripts/container-entrypoint.d/vim-plug +10 -0
@@ 0,0 1,10 @@
#!/bin/sh

if [ -f ~/.vimrc ] && [ -f ~/.vim/autoload/plug.vim ] && command -v vim > /dev/null; then
	vim  -c "PlugInstall" -c "qa" &> /dev/null
fi

if [ -f ~/.config/nvim/init.vim ] && [ -f ~/.local/share/nvim/site/autoload/plug.vim ] && command -v nvim > /dev/null; then
	nvim --headless +PlugInstall +qa &> /dev/null
	nvim --headless +UpdateRemotePlugins +qa &> /dev/null
fi