Skip to content

Instantly share code, notes, and snippets.

@nickpascucci
Last active June 5, 2018 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpascucci/cd69c247a4123c3961e896def1f1fc3b to your computer and use it in GitHub Desktop.
Save nickpascucci/cd69c247a4123c3961e896def1f1fc3b to your computer and use it in GitHub Desktop.
Dockerfiles for dev images
export TERM="xterm-256color"
export CLICOLOR="true"
alias ls="ls --color"
alias ll="ls --color -alh"
get-git-dirty-state() {
if [[ $(git status 2> /dev/null | tail -n1) =~ "nothing to commit" ]]; then
echo ""
else
echo "*"
fi
}
get-git-branch() {
branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [ ! -z "$branch" ]; then
echo " [$branch]"
fi
}
BLUE="\[\e[0;34m\]"
LIGHT_GREEN="\[\e[1;32m\]"
WHITE="\[\e[0;37m\]"
MAGENTA="\[\e[0;35m\]"
RED="\[\e[0;31m\]"
LAMBDA=$'\uf09d'
#export PS1="$LIGHT_GREEN[\D{%H:%M:%S}]$WHITE ${debian_chroot:+($debian_chroot)}\w »$WHITE "
export PS1="$LIGHT_GREEN{SANDBOX} [\D{%H:%M:%S}]$WHITE ${debian_chroot:+($debian_chroot)}\w$MAGENTA\$(get-git-branch)$RED >$WHITE "
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
# Save and reload the history after each command finishes
# export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Helper function for sending commands to other tmux panes
function tsk {
args=$@
tmux send-keys -t right "$args" C-m
}
FROM ndpi/emacs-base
USER root
RUN apt-get update && apt-get install -y \
tmux \
sudo \
&& rm -rf /var/lib/apt/lists/*
COPY sudoers /etc/sudoers.d/90-nick-dev-image
RUN chmod 0440 /etc/sudoers.d/90-nick-dev-image
USER nick
COPY gray.tmuxtheme /home/nick/gray.tmuxtheme
COPY tmux.conf /home/nick/.tmux.conf
COPY bashrc /home/nick/.bashrc
COPY start-tmux.sh /home/nick/start-tmux.sh
WORKDIR /src
ENTRYPOINT /bin/bash /home/nick/start-tmux.sh
#! /bin/bash
# Set up a tmux session with a default layout.
{
SESSION="sandbox"
tmux start-server
tmux new-session -d -s "$SESSION"
# Set up the main window with Emacs.
tmux selectp -t 0
tmux send-keys "emacs" C-m
# Split the window horizontally, and start any worker processes specified by the sandbox.
tmux splitw -h -p 35
if [ -e "/home/nick/sandbox-init-helper.sh" ]; then
tmux send-keys "/home/nick/sandbox-init-helper.sh" C-m
else
# If no helper script defined, list the /src directory.
tmux send-keys "ls -al" C-m
fi
# Split the window again, vertically this time.
tmux selectp -t 1
tmux splitw -v -p 75
# Show git status in 3rd window.
tmux selectp -t 2
tmux send-keys "git status" C-m
# Switch back to Emacs.
tmux selectp -t 0
# Attach to the session we created.
tmux attach-session -t "$SESSION"
} &>/tmp/start-tmux.log
unbind-key C-b
set -g prefix 'C-\'
bind-key 'C-\' send-prefix
set-option -g default-shell "/bin/bash"
source-file "$HOME/gray.tmuxtheme"
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y \
emacs-nox \
python \
curl \
git \
util-linux \
coreutils \
findutils \
grep \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -m -u 501 -U nick
COPY . /home/nick/.emacs.d/
RUN chown -R nick:nick /home/nick
RUN mv /home/nick/.emacs.d/path.docker.txt /home/nick/.path.txt
RUN mkdir /src; chown -R nick:nick /src
USER nick
WORKDIR /home/nick/.emacs.d/
RUN curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python && \
/home/nick/.cask/bin/cask install && \
/home/nick/.cask/bin/cask list
WORKDIR /src
ENTRYPOINT emacs -nw
FROM ndpi/dev-base
USER root
RUN apt-get update && apt-get install -y \
nodejs \
npm \
ocaml \
&& rm -rf /var/lib/apt/lists/*
# Note: bs-platform install will fail if npm is >= 5.0.0, so install it first
# then update npm.
RUN npm install -g bs-platform reason-cli
RUN npm install -g npm@latest
USER nick
COPY sandbox-init-helper.sh /home/nick/sandbox-init-helper.sh
# Install an Emacs module which sets up ReasonML integration.
COPY reasonml.module.org /home/nick/.emacs.d/modules

Emacs configuration module for ReasonML development

(package-install 'reason-mode)
(package-install 'tuareg)
(package-install 'merlin-eldoc)

(setq refmt-width-mode 'fill)
(setq merlin-command "ocamlmerlin")
(setq merlin-eldoc-occurrences nil)

(add-hook 'reason-mode-hook
          (lambda ()
            (add-hook 'before-save-hook 'refmt-before-save)))
(add-hook 'reason-mode-hook 'merlin-eldoc-setup)
#! /bin/bash
# Helper script for setting up the sandbox.
# Start an NPM build watcher process.
if [ -e "package.json" ]; then
npm start
else
echo "No package.json found here."
echo "Navigate to the project root and run 'npm start'."
fi
#! /bin/bash
# This script helps with starting sandboxes based on the ndpi/dev-base image.
# Call it with the name of the docker image containing the dev sandbox and the
# directory to mount at /src.
docker run \
--mount type=bind,src=$2,dst=/src \
--mount type=bind,src=$HOME/.ssh,dst=/home/nick/.ssh,readonly \
-p 8080:8080 \
-p 3000:3000 \
-e TERM -e COLUMNS="`tput cols`" -e LINES="`tput lines`" \
-e TZ='America/New_York'
-it $1
# Give 'nick' user passwordless sudo functionality.
nick ALL=(ALL) NOPASSWD:ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment