Skip to content

Commit

Permalink
Add docker devenv.
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Jun 28, 2019
1 parent 71c32d4 commit e6ab111
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# FROM ubuntu:xenial
FROM openjdk:8-jdk
LABEL maintainer="Andrey Antukh <[email protected]>"

ARG EXTERNAL_UID=1000

ENV CLOJURE_VERSION=1.10.0.442 \
LANG=en_US.UTF-8 \
LC_ALL=C.UTF-8

RUN set -ex; \
apt-get update && \
apt-get install -yq \
locales \
ca-certificates \
wget \
sudo \
curl \
bash \
zsh \
git \
rlwrap \
; \
rm -rf /var/lib/apt/lists/*;

RUN set -ex; \
echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" >> /etc/apt/sources.list; \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -; \
apt-get update -yq && \
apt-get install -yq \
postgresql-9.6 \
postgresql-contrib-9.6 \
;\
rm -rf /var/lib/apt/lists/*;

COPY pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf

# Copy user config files
COPY bashrc /root/.bashrc
COPY zshrc /root/.zshrc
COPY vimrc /root/.vimrc
COPY entrypoint.sh /entrypoint.sh
COPY tmux.conf /root/.tmux.conf

RUN set -ex; \
/etc/init.d/postgresql start \
&& createuser -U postgres -sl devuser \
&& createdb -U devuser test \
&& /etc/init.d/postgresql stop

RUN set -ex; \
wget "https://download.clojure.org/install/linux-install-$CLOJURE_VERSION.sh"; \
chmod +x "linux-install-$CLOJURE_VERSION.sh"; \
"./linux-install-$CLOJURE_VERSION.sh"; \
rm -rf "linux-install-$CLOJURE_VERSION.sh"

RUN set -ex; \
useradd -m -g users -s /bin/zsh -u $EXTERNAL_UID devuser; \
passwd devuser -d; \
echo "devuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

USER devuser
WORKDIR /home/devuser

# Copy user config files
COPY bashrc /home/devuser/.bashrc
COPY zshrc /home/devuser/.zshrc
COPY vimrc /home/devuser/.vimrc
COPY tmux.conf /home/devuser/.tmux.conf

ENTRYPOINT ["zsh", "/entrypoint.sh"]
9 changes: 9 additions & 0 deletions docker/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export PATH=$HOME/.local/bin:$PATH

alias l='ls --color -GFlh'
alias rm='rm -r'
alias ls='ls --color -F'
alias lsd='ls -d *(/)'
alias lsf='ls -h *(.)'

export LEIN_FAST_TRAMPOLINE=y
5 changes: 5 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env zsh
set -ex
sudo pg_ctlcluster 9.6 main start

exec "$@"
11 changes: 11 additions & 0 deletions docker/pg_hba.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Database administrative login by Unix domain socket
local all postgres trust

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
3 changes: 3 additions & 0 deletions docker/tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -g mouse off
set -g history-limit 50000
setw -g mode-keys emacs
26 changes: 26 additions & 0 deletions docker/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set nocompatible

set bs=2
set ts=4
set tw=1000000000

set expandtab
set tabstop=8
set softtabstop=4
set shiftwidth=4
filetype indent off
filetype plugin on

syntax on

set autoindent
set showmatch
set showmode
set mousehide

set nowrapscan
set hlsearch
set incsearch

set fileencoding=utf8
set encoding=utf8
54 changes: 54 additions & 0 deletions docker/zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env zsh

export EDITOR=vim

bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey '^R' history-incremental-search-backward

bindkey -e

autoload -U promptinit
promptinit
prompt off

#------------------------------
## Comp stuff
##------------------------------
zmodload zsh/complist
autoload -Uz compinit
compinit

#------------------------------
# Alias stuff
#------------------------------
alias cp='cp -r'
alias ls='ls -F'
alias l='ls -Flha'
alias rm='rm -r'
alias ls='ls --color -F'
alias lsd='ls -d *(/)'
alias lsf='ls -h *(.)'

#-----------------
# Options
#-----------------

setopt AUTO_CD # implicate cd for non-commands
setopt CORRECT_ALL # correct spelling
setopt COMPLETE_IN_WORD # complete commands anywhere in the word
setopt NOTIFY # Notify when jobs finish
setopt BASH_AUTO_LIST # Autolist options on repeition of ambiguous args
setopt AUTO_PUSHD # Push dirs into history
setopt MULTIOS # Allow Multiple pipes
setopt MAGIC_EQUAL_SUBST # Expand inside equals
setopt EXTENDED_GLOB
setopt NOBEEP
setopt INC_APPEND_HISTORY
export HISTSIZE=100000
export SAVEHIST=100000
export HISTFILE=~/.zhistory
setopt hist_ignore_all_dups
setopt hist_ignore_space

export PATH=$HOME/.local/bin:$PATH
83 changes: 83 additions & 0 deletions manage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash
set -e

REV=`git log -n 1 --pretty=format:%h -- docker/`
IMGNAME="suricatta-devenv"

function kill-container {
echo "Cleaning development container $IMGNAME:$REV..."
if $(docker ps | grep -q $IMGNAME); then
docker ps | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker kill
fi
if $(docker ps -a | grep -q $IMGNAME); then
docker ps -a | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker rm
fi
}

function remove-image {
echo "Clean old development image $IMGNAME..."
docker images | grep $IMGNAME | awk '{print $3}' | xargs --no-run-if-empty docker rmi
}

function build-devenv {
kill-container
echo "Building development image $IMGNAME:$REV..."
docker build --rm=true -t $IMGNAME:$REV -t $IMGNAME:latest --build-arg EXTERNAL_UID=$(id -u) docker/
}

function reset {
kill-container

if ! $(docker images | grep $IMGNAME | grep -q $REV); then
build-devenv
fi
}

function docker-run {
docker run --rm -ti \
-v `pwd`:/home/devuser/suricatta \
-v $HOME/.m2:/home/devuser/.m2 \
-w /home/devuser/suricatta \
$IMGNAME:latest $@
}


function run-devenv {
reset || exit -1;
mkdir -p $HOME/.m2
docker-run /bin/zsh
}

function run-tests {
reset || exit -1;
docker-run clojure -Adev:test
}

function help {
echo "suricatta devenv manager v$REV"
echo "USAGE: $0 OPTION"
echo "Options:"
echo "- clean Kill container and remove image"
echo "- build-devenv Build docker container for development"
echo "- run-devenv Run (and build if necessary) development container"
echo "- run-tests Execute unit tests for both backend and frontend"
}

case $1 in
clean)
kill-container
remove-image
;;
build-devenv)
build-devenv
;;
run-devenv)
run-devenv
;;
run-tests)
run-tests
;;
*)
help
;;
esac

0 comments on commit e6ab111

Please sign in to comment.