~nka/docker-archlinux-dev

a9c964d658c287553b1b371549cb4e3109e54a54 — Nicolas KAROLAK 6 months ago
init
A  => Dockerfile +119 -0
@@ 1,119 @@
FROM archlinux:latest

# 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

RUN \
    # install net tools
    pacman -Syuq --noconfirm \
        curl \
        mtr \
        openssh \
        iproute2 \
        iputils \
        traceroute \
        && \
    :

RUN \
    # install sys tools
    pacman -Syuq --noconfirm \
        bash \
        bash-completion \
        ca-certificates \
        gnupg \
        less \
        lsb-release \
        procps-ng \
        psutils \
        strace \
        sudo \
        unzip \
        && \
    :

RUN \
    # install dev tools
    pacman -Syuq --noconfirm \
        base-devel \
	docker \
	docker-compose \
        git \
        git-lfs \
        make \
        neovim \
        python-neovim \
        python-pip \
        python-setuptools \
        python-wheel \
	&& \
    :

RUN \
    # clean up
    pacman -Scc --noconfirm &&  \
    # locales
    locale-gen && \
    :

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

# 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" ]

# keep it running
CMD [ "sleep", "infinity" ]

A  => Makefile +39 -0
@@ 1,39 @@
DOCKER_IMAGE_NAME := nikaro/archlinux-dev

.PHONY: all
all: help

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

.PHONY: rebuild
## rebuild: Rebuilds the docker image from scratch
rebuild:
	@echo "Rebuilding..."
	@docker build --pull --no-cache -t ${DOCKER_IMAGE_NAME} .

.PHONY: pull
## pull: Pulls the docker image
pull:
	@echo "Pulling..."
	@-docker pull ${DOCKER_IMAGE_NAME}  # this command will not propagate any non-zero return code

.PHONY: push
## push: Pushes the docker image to registry
push:
	@echo "Pushing..."
	@docker push ${DOCKER_IMAGE_NAME}

.PHONY: shell
## shell: Runs a bash shell inside the docker container
shell: build
	@docker run -ti ${DOCKER_IMAGE_NAME} /bin/bash

.PHONY: help
## help: Prints this help message
help:
	@echo -e "Usage: \n"
	@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' |  sed -e 's/^/ /'

A  => files/bashrc +164 -0
@@ 1,164 @@
#!/bin/bash

# if not running interactively, don't do anything
[ -z "$PS1" ] && return

# source system bashrc
[ -f /etc/bashrc ] && source /etc/bashrc
[ -f /etc/bash.bashrc ] && source /etc/bash.bashrc


## GENERAL OPTIONS ##

# diable ctrl-s and ctrl-q for control-flow
stty start ''
stty stop ''
stty -ixon
stty -ixoff

# update window size after every command
shopt -s checkwinsize

# automatically trim long paths in the prompt (requires Bash 4.x)
export PROMPT_DIRTRIM=15

# enable history expansion with space
# e.g. typing !!<space> will replace the !! with your last command
bind Space:magic-space

# turn on recursive globbing (enables ** to recurse all directories)
shopt -s globstar 2> /dev/null

# case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob;


## SMARTER TAB-COMPLETION (Readline bindings) ##

# perform file completion in a case insensitive fashion
bind "set completion-ignore-case on"

# do not treat hyphens and underscores as equivalent
bind "set completion-map-case off"

# display matches for ambiguous patterns at first tab press
bind "set show-all-if-ambiguous on"

# immediately add a trailing slash when autocompleting symlinks to directories
bind "set mark-symlinked-directories on"

# enable bash completion in interactive shells
if ! shopt -oq posix; then
    if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
    elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
    fi
fi

# enable custom completion
if [ -d "${XDG_CONFIG_HOME}/bash/completion" ]; then
    for compl in "${XDG_CONFIG_HOME}"/bash/completion/_*.bash; do
        source "$compl"
    done
fi


## SANE HISTORY DEFAULTS ##

# append to the history file, don't overwrite it
shopt -s histappend

# save multi-line commands as one command
shopt -s cmdhist

# huge history. doesn't appear to slow things down, so why not?
export HISTSIZE=500000
export HISTFILESIZE=100000

# avoid duplicate entries
export HISTCONTROL="erasedups:ignoreboth"

# don't record some commands
export HISTIGNORE="&:[ ]*:exit:history:clear"

# use standard ISO 8601 timestamp
# %F equivalent to %Y-%m-%d
# %T equivalent to %H:%M:%S (24-hours format)
export HISTTIMEFORMAT='%F %T '

# enable incremental history search with up/down arrows (also Readline goodness)
# learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'


## BETTER DIRECTORY NAVIGATION ##

# prepend cd to directory names automatically
shopt -s autocd 2> /dev/null
# correct spelling errors during tab-completion
shopt -s dirspell 2> /dev/null
# correct spelling errors in arguments supplied to cd
shopt -s cdspell 2> /dev/null

# this defines where cd looks for targets
# add the directories you want to have fast access to, separated by colon
# xx: CDPATH=".:~:~/projects" will look for targets in the current working directory, in home and in the ~/projects folder
export CDPATH="."

# this allows you to bookmark your favorite places across the file system
# define a variable containing a path and you will be able to cd into it regardless of the directory you're in
shopt -s cdable_vars


## MISC ##

# default editor
export VISUAL=vim
export EDITOR=vim

if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
    [ -f /etc/profile.d/vte.sh ] && source /etc/profile.d/vte.sh
    [ -f /etc/profile.d/vte-2.91.sh ] && source /etc/profile.d/vte-2.91.sh
fi

# prompt
PROMPT_COMMAND=__prompt_command

__prompt_command() {
    local curr_exit="$?"

    # colors
    local Def='\[\e[00m\]'
    local Blu='\[\e[01;34m\]'
    local Gre='\[\e[01;32m\]'
    local Red='\[\e[01;31m\]'

    # symbol
    local Sym='$'

    # base prompt
    PS1="${Gre}\u@\h${Def}: ${Blu}\W${Def} "

    # change symbol if root
    if [ "$EUID" -eq 0 ]; then
        local Sym='#'
    fi

    # change symbol color on error
    if [ "$curr_exit" != 0 ]; then
        PS1+="${Red}${Sym}${Def} "
    else
        PS1+="${Sym} "
    fi

    # vte
    if type __vte_osc7 &> /dev/null; then
        VTE_PWD='\[$(__vte_osc7)\]'
        PS1+="${VTE_PWD}"
    fi
}


A  => scripts/container-entrypoint.d/docker-group +6 -0
@@ 1,6 @@
#!/usr/bin/env bash

if [ -e /var/run/docker.sock ]; then
    # make the GID match with docker on the host
    sudo groupmod -g $(ls -ln /var/run/docker.sock | awk '{ print $4 }') docker
fi

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

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

A  => scripts/container-entrypoint.d/nvim-plugins +7 -0
@@ 1,7 @@
#!/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.sh +23 -0
@@ 1,23 @@
#!/usr/bin/env bash

set +e

DIR=/container-entrypoint.d

if [ -d "$DIR" ]; then
    # Ignore *~ and *, scripts
    for i in $(LC_ALL=C; echo ${DIR%/}/*[^~,]) ; do
        [ -d $i ] && continue
        [ "${i%.swp}" != "${i}" ] && continue
        if [ -e $i ]; then
            echo $i
            $i
        fi
    done
else
    echo "Not a directory: $DIR"
    exit 1
fi

exec "$@"