├── keys └── README ├── roles ├── dotfiles │ ├── files │ │ ├── .gitignore │ │ ├── .bashrc_mods │ │ ├── .vimrc_vundle │ │ ├── .tmux.conf │ │ ├── .vimrc │ │ ├── .vim │ │ │ └── colors │ │ │ │ └── cyanic.vim │ │ └── .bash_aliases │ └── tasks │ │ └── main.yml ├── golang │ ├── vars │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── mesos │ └── tasks │ │ └── main.yml └── youcompleteme │ └── tasks │ └── main.yml ├── golang-vagrant-ansible.png ├── genkeys.sh ├── .gitignore ├── copysshkey.sh ├── playbook.yml ├── Dockerfile ├── Vagrantfile └── README.md /keys/README: -------------------------------------------------------------------------------- 1 | SSH keys will be generated here, on vagrant up 2 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.gitignore: -------------------------------------------------------------------------------- 1 | .config/geany/geany.conf 2 | .vim/bundle* 3 | -------------------------------------------------------------------------------- /golang-vagrant-ansible.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samuell/devbox-golang/HEAD/golang-vagrant-ansible.png -------------------------------------------------------------------------------- /genkeys.sh: -------------------------------------------------------------------------------- 1 | keyfile=keys/vagrantssh.key; 2 | if [[ ! -f $keyfile".pub" ]]; then 3 | rm $keyfile; 4 | ssh-keygen -N '' -f $keyfile; 5 | fi 6 | ssh-add $keyfile; 7 | -------------------------------------------------------------------------------- /roles/golang/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | go_version: 1.9 3 | go_archive_file: go{{ go_version }}.linux-amd64.tar.gz 4 | go_binary: /home/ubuntu/opt/go/bin/go 5 | go_root: /home/ubuntu/opt/go 6 | go_path: /home/ubuntu/code/go 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /roles/mesos/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add key for Mesosphere apt repo 3 | sudo: true 4 | apt_key: keyserver=keyserver.ubuntu.com id=E56151BF 5 | - name: Add Mesosphere apt repo 6 | sudo: true 7 | apt_repository: repo='deb http://repos.mesosphere.io/ubuntu trusty main' state=present 8 | - name: Install Mesos from Mesosphere apt repo 9 | sudo: true 10 | apt: name={{ item }} state=latest 11 | with_items: 12 | - mesos 13 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.bashrc_mods: -------------------------------------------------------------------------------- 1 | HISTSIZE=10000 2 | HISTFILESIZE=10000 3 | 4 | if [[ $SHELL = "/bin/bash" ]]; then 5 | source /etc/bash_completion; 6 | fi; 7 | 8 | if [ -f ~/.bashrc_local ]; then 9 | . ~/.bashrc_local; 10 | fi 11 | if [ -f ~/.bash_aliases ]; then 12 | . ~/.bash_aliases; 13 | fi 14 | if [ -f ~/.bash_aliases_local ]; then 15 | . ~/.bash_aliases_local; 16 | fi 17 | 18 | export PS1="[\u \W]$ " 19 | export GOROOT=~/opt/go 20 | export GOPATH=~/code/go 21 | export PATH=~/opt/go/bin:$PATH 22 | export PATH=~/code/go/bin:$PATH 23 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.vimrc_vundle: -------------------------------------------------------------------------------- 1 | " -------------------------------------------------------------------------------- 2 | " Vundle installation 3 | " -------------------------------------------------------------------------------- 4 | set nocompatible " be iMproved 5 | filetype off " required! 6 | 7 | set rtp+=~/.vim/bundle/vundle/ 8 | call vundle#rc() 9 | 10 | " let Vundle manage Vundle 11 | " required! 12 | Plugin 'gmarik/vundle' 13 | 14 | " -------------------------------------------------------------------------------- 15 | " My plugins below 16 | " -------------------------------------------------------------------------------- 17 | Plugin 'junegunn/goyo.vim' 18 | Plugin 'junegunn/limelight.vim' 19 | 20 | filetype on 21 | set nocompatible! 22 | -------------------------------------------------------------------------------- /roles/youcompleteme/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install apt packages for YouCompleteMe vim completion engine 3 | sudo: yes 4 | apt: 5 | name={{ item }} state=latest 6 | with_items: 7 | - build-essential 8 | - cmake 9 | - python-dev 10 | - name: Check out YouCompleteMe 11 | git: 12 | repo=https://github.com/Valloric/YouCompleteMe.git 13 | dest={{ home }}/src/YouCompleteMe 14 | - name: Symlink YouCompleteMe to ~/vim/bundle 15 | file: 16 | src={{ home }}/src/YouCompleteMe 17 | dest={{ home }}/.vim/bundle/YouCompleteMe 18 | state=link 19 | - name: Compile YouCompleteMe binaries 20 | command: ./install.sh --clang-completer 21 | chdir={{ home }}/src/YouCompleteMe 22 | creates={{ home }}/src/YouCompleteMe/third_party/ycmd/ycm_core.so 23 | 24 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.tmux.conf: -------------------------------------------------------------------------------- 1 | # Use bash when starting new sessions 2 | new-session -n SomeWindowName '/bin/bash -li' 3 | # Reload the tmux conf 4 | bind r source-file ~/.tmux.conf \; display "Reloaded!" 5 | # Set Ctrl + a to the standard prefix 6 | set -g prefix C-a 7 | # Free the original `Ctrl-b` prefix keybinding. 8 | unbind C-b 9 | # Ensure that we can send `Ctrl-a` to other apps. 10 | bind C-a send-prefix 11 | # Moving between panes. 12 | bind h select-pane -L 13 | bind j select-pane -D 14 | bind k select-pane -U 15 | bind l select-pane -R 16 | # Pane resizing 17 | bind -r H resize-pane -L 5 18 | bind -r J resize-pane -D 5 19 | bind -r K resize-pane -U 5 20 | bind -r L resize-pane -R 5 21 | # Resize one cell at a time 22 | bind -r C-h resize-pane -L 23 | bind -r C-j resize-pane -D 24 | bind -r C-k resize-pane -U 25 | bind -r C-l resize-pane -R 26 | # Enable vi keys. 27 | setw -g mode-keys vi 28 | # Misc 29 | #bind " choose-window 30 | bind - split-window -v 31 | bind | split-window -h 32 | bind '"' choose-window 33 | # Set bash as default shell 34 | #set-option -g default-shell '/bin/bash -l' 35 | #set-option -g default-command "/bin/bash -l" 36 | #new -n WindowName '/bin/bash -l' 37 | -------------------------------------------------------------------------------- /roles/dotfiles/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Symlink config files in rc folder 3 | file: src=/vagrant/roles/dotfiles/files/{{ item }} dest={{ home }}/{{ item }} state=link 4 | with_items: 5 | - .bashrc_mods 6 | - .bash_aliases 7 | - .tmux.conf 8 | - .vimrc 9 | - .vim 10 | - name: Create ~/src folder 11 | file: dest={{ home }}/src/vim-pathogen state=directory 12 | - name: Check out pathogen 13 | git: 14 | repo=https://github.com/tpope/vim-pathogen.git 15 | dest={{ home }}/src/vim-pathogen 16 | update=yes 17 | - name: Create /vagrant/roles/dotfiles/files/.vim/autoload folder 18 | file: dest=/vagrant/roles/dotfiles/files/.vim/autoload state=directory 19 | - name: Symlink pathogen into ~/.vim/autoload 20 | file: 21 | src={{ home }}/src/vim-pathogen/autoload/pathogen.vim 22 | dest={{ home }}/.vim/autoload/pathogen.vim 23 | state=link 24 | - name: Create empty .bash_aliases_local file 25 | shell: 26 | echo '# Add local aliases here' > {{ home }}/.bash_aliases_local 27 | creates={{ home }}/.bash_aliases_local 28 | - name: Include .bashrc_mods in .bashrc 29 | lineinfile: 30 | "dest={{ home }}/.bashrc line='. ~/.bashrc_mods # Include local mods' insertafter=EOF" 31 | -------------------------------------------------------------------------------- /copysshkey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ---- 3 | # Copy a specifed SSH key into the ~/.ssh folder of the docker or virtualbox 4 | # ---- 5 | 6 | if [[ $1 == '' || $2 == '' ]]; then 7 | echo "Usage: ./copysshfile.sh (docker|virtualbox) "; 8 | else 9 | destination=$1; 10 | keyfile=$2; 11 | tempfile=.sshconfiginfo.tmp 12 | 13 | # Run the ssh-config command only once and save to temp file, to speed up things 14 | vagrant ssh-config $destination > $tempfile; 15 | 16 | echo "--------------------------------------------------------------------------------"; 17 | localkey=$(cat $tempfile | grep IdentityFile | awk '{ print $2 }'); 18 | hostname=$(cat $tempfile | grep HostName | awk '{ print $2 }'); 19 | port=$(cat $tempfile | grep Port | awk '{ print $2 }'); 20 | 21 | echo "Destination: "$destination; 22 | echo "HostName: "$hostname; 23 | echo "Port: "$port; 24 | echo "Key to copy: "$keyfile; 25 | echo "Localkey: "$localkey; 26 | 27 | echo "--------------------------------------------------------------------------------"; 28 | echo "Trying to copy now: $keyfile ..."; 29 | 30 | scp -i $localkey $keyfile vagrant@$hostname:~/.ssh/ 31 | 32 | echo "--------------------------------------------------------------------------------"; 33 | 34 | rm $tempfile; 35 | fi; 36 | -------------------------------------------------------------------------------- /playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | become: true 4 | vars: 5 | home: /home/ubuntu 6 | document_root: /vagrant 7 | os: ubuntu 8 | user: ubuntu 9 | osversioncode: xenial 10 | gather_facts: no 11 | pre_tasks: 12 | - name: 'install python2' 13 | raw: sudo apt-get -y install python-simplejson 14 | - name: Symlink sh to bash rather than dash 15 | file: src=/bin/bash dest=/bin/sh state=link force=true 16 | - name: Update apt cache and optionally upgrade 17 | apt: 18 | update_cache=yes 19 | cache_valid_time=7200 20 | #upgrade=yes # Uncomment this to force full upgrade! 21 | - name: Install stuff from Aptitude 22 | apt: name={{ item }} state=installed 23 | with_items: 24 | - git 25 | - tig 26 | - vim 27 | - gdb 28 | - cgdb 29 | - bash-completion # Not included in the docker image 30 | - make 31 | - tree 32 | - htop 33 | - tmux 34 | - man-db 35 | roles: 36 | - { role: dotfiles, become: false } 37 | - { role: golang, become: false } 38 | #- { role: youcompleteme, sudo: false } # Comment out this to save time!! 39 | #- { role: mesos, sudo: false } 40 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.vimrc: -------------------------------------------------------------------------------- 1 | " -------------------------------------------- 2 | " Various settings 3 | " -------------------------------------------- 4 | syntax on 5 | colorscheme cyanic 6 | set showmatch 7 | set ignorecase 8 | set showmode 9 | set nowrap 10 | set hlsearch 11 | set shell=/bin/sh " Needed to get at least Go autocompletion to work 12 | set nu 13 | 14 | " Settings for using only tabs, not spaces, for indent 15 | set tabstop=4 16 | set shiftwidth=4 17 | set noexpandtab 18 | 19 | " -------------------------------------------- 20 | " Convenience mappings 21 | " -------------------------------------------- 22 | nmap :noh 23 | " Use jj to get out of insert mode 24 | imap jj 25 | " Remap Ctrl + Z to save, in all modes 26 | noremap :update 27 | vnoremap ::update 28 | inoremap :update 29 | " -------------------------------------------- 30 | 31 | " -------------------------------------------- 32 | " Speed up navigation 4x by holding Ctrl key 33 | " -------------------------------------------- 34 | nmap 4j 35 | nmap 4k 36 | nmap 4h 37 | nmap 4l 38 | " -------------------------------------------- 39 | 40 | " -------------------------------------------- 41 | " Pathogen setup 42 | " -------------------------------------------- 43 | execute pathogen#infect() 44 | filetype plugin indent on 45 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Re-use the phusion baseimage which runs an SSH server etc 2 | FROM phusion/baseimage 3 | 4 | # Some definitions 5 | ENV SUDOFILE /etc/sudoers 6 | ENV SSHKEYFILE vagrantssh.key 7 | 8 | # Do what? 9 | RUN rm -f /etc/service/sshd/down 10 | 11 | # Import the newly generated public key into the docker image 12 | ADD keys/${SSHKEYFILE}.pub /tmp/${SSHKEYFILE}.pub 13 | 14 | # Install the public key for root user 15 | RUN cat /tmp/${SSHKEYFILE}.pub >> /root/.ssh/authorized_keys 16 | 17 | # Create vagrant user 18 | RUN useradd --shell /bin/bash --create-home --base-dir /home --user-group --groups sudo,ssh --password '' vagrant 19 | 20 | # Install the public key for vagrant user 21 | RUN mkdir -p /home/vagrant/.ssh 22 | RUN cat /tmp/${SSHKEYFILE}.pub >> /home/vagrant/.ssh/authorized_keys 23 | RUN chown -R vagrant:vagrant /home/vagrant/.ssh 24 | 25 | # Remove the temporary location for the key 26 | RUN rm -f /tmp/${SSHKEYFILE}.pub 27 | 28 | # Update apt-cache, so that stuff can be installed 29 | RUN apt-get -y update 30 | # Install python (otherwise ansible will not work) 31 | RUN apt-get -y install python 32 | # Install aptitude, since ansible needs it (only apt-get is installed) 33 | RUN apt-get -y install aptitude 34 | 35 | # Enable password-less sudo for all user (including the 'vagrant' user) 36 | RUN chmod u+w ${SUDOFILE} 37 | RUN echo '%sudo ALL=(ALL:ALL) NOPASSWD: ALL' >> ${SUDOFILE} 38 | RUN chmod u-w ${SUDOFILE} 39 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | 8 | # -------------------------------------------------------------------- 9 | # Definitions for the VirtualBox machine 10 | # -------------------------------------------------------------------- 11 | config.vm.define "virtualbox", autostart: true do |vbox| 12 | vbox.vm.provider "virtualbox" do |v| 13 | v.memory = 2048 14 | v.cpus = 2 15 | end 16 | vbox.vm.box = "ubuntu/xenial64" 17 | vbox.vm.network "forwarded_port", guest: 80, host: 8080 18 | vbox.vm.network "forwarded_port", guest: 5050, host: 5050 19 | vbox.vm.provision :ansible do |ansible| 20 | ansible.playbook = "playbook.yml" 21 | end 22 | # Tell the user what to do next 23 | vbox.vm.provision "shell", inline: "echo 'Finished! Now try logging in with: vagrant ssh virtualbox'" 24 | end 25 | 26 | # -------------------------------------------------------------------- 27 | # Definitions for the Docker container 28 | # -------------------------------------------------------------------- 29 | #config.vm.define "docker", autostart: false do |dkr| 30 | # system("bash genkeys.sh") 31 | # dkr.vm.provider "docker" do |d| 32 | # d.has_ssh = true 33 | # d.build_dir = "." 34 | # end 35 | 36 | # dkr.ssh.private_key_path = "keys/vagrantssh.key" 37 | # dkr.ssh.username = "vagrant" 38 | 39 | # dkr.vm.provision :ansible do |ansible| 40 | # ansible.playbook = "playbook.yml" 41 | # ansible.extra_vars = { ansible_ssh_user: 'vagrant' } 42 | # #ansible.verbose = "vvvv" 43 | # end 44 | # dkr.vm.synced_folder ".", "/vagrant" 45 | # # Tell the user what to do next 46 | # dkr.vm.provision "shell", inline: "echo 'Finished! Now try logging in with: vagrant ssh docker'" 47 | #end 48 | end 49 | -------------------------------------------------------------------------------- /roles/golang/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | #- name: Install go-specific apt packages 3 | # sudo: true 4 | # apt: name={{ item }} state=latest 5 | # with_items: 6 | # - vim-gocomplete 7 | - name: Download Golang binary distribution 8 | get_url: 9 | url=https://storage.googleapis.com/golang/{{ go_archive_file }} 10 | dest={{ document_root }}/{{ go_archive_file }} 11 | - name: Create ~/opt folder 12 | file: 13 | path={{ home }}/opt 14 | state=directory 15 | - name: Unpack the Go binary distribution 16 | unarchive: 17 | copy=no 18 | src={{ document_root }}/{{ go_archive_file }} 19 | dest={{ home }}/opt 20 | creates={{ home }}/opt/go 21 | - name: Add go path settings in .bashrc_mods 22 | lineinfile: dest={{ home }}/.bashrc_mods line="{{ item }}" insertafter=EOF 23 | with_items: 24 | - 'export GOROOT={{ go_root }}' 25 | - 'export GOPATH={{ go_path }}' 26 | - 'export PATH={{ go_root }}/bin:$PATH' 27 | - 'export PATH={{ go_path }}/bin:$PATH' 28 | - name: Create go code folder 29 | file: 30 | dest={{ go_path }}/src/github.com 31 | state=directory 32 | recurse=yes 33 | owner={{ user }} 34 | group={{ user }} 35 | - name: Install some nice go packages 36 | command: > 37 | go get -u {{ item }} 38 | environment: 39 | GOPATH: "{{ go_path }}" 40 | GOROOT: "{{ go_root }}" 41 | PATH: "{{ go_root }}/bin:{{ go_path }}/bin:/usr/bin:/bin" 42 | with_items: 43 | - github.com/nsf/gocode 44 | - bitbucket.org/gotamer/gowatch 45 | - name: Check out vim-go 46 | git: 47 | repo=https://github.com/fatih/vim-go.git 48 | dest={{ home }}/src/vim-go 49 | update=yes 50 | - name: Ensure ~/.vim/bundle exists 51 | file: 52 | dest={{ home }}/.vim/bundle 53 | state=directory 54 | - name: Symlink vim-go to .vim/bundle 55 | file: 56 | src={{ home }}/src/vim-go 57 | dest={{ home }}/.vim/bundle/vim-go 58 | state=link 59 | # TODO: Add bitbucket.org/gotamer/gowatch for folder watching and running tests! 60 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.vim/colors/cyanic.vim: -------------------------------------------------------------------------------- 1 | " local syntax file - set colors on a per-machine basis: 2 | " vim: tw=0 ts=4 sw=4 3 | " Vim color file 4 | " Maintainer: Samuel Lampa 5 | " Last Change: 2015 Feb 2 6 | 7 | hi clear 8 | set background=light 9 | if exists("syntax_on") 10 | syntax reset 11 | endif 12 | let g:colors_name = "cyanic" 13 | hi Normal guifg=white guibg=black ctermfg=darkgrey 14 | hi Scrollbar guifg=darkgrey guibg=grey 15 | hi Menu guifg=white guibg=cyan ctermfg=white ctermbg=lightmagenta 16 | hi Pmenu guifg=white guibg=magenta ctermfg=White ctermbg=lightmagenta 17 | hi SpecialKey ctermfg=darkred guifg=#cc0000 18 | hi NonText ctermfg=darkred guifg=#cc0000 19 | hi Directory ctermfg=brown guifg=#cc8000 20 | hi ErrorMsg term=standout ctermfg=grey ctermbg=red guifg=White guibg=Red 21 | hi Search cterm=NONE ctermfg=black ctermbg=grey guifg=white guibg=Lightyellow 22 | hi MoreMsg ctermfg=darkgreen guifg=SeaGreen 23 | hi ModeMsg guifg=White guibg=lightblue 24 | hi LineNr term=underline ctermfg=grey guifg=grey 25 | hi Question term=standout ctermfg=darkgreen guifg=Green 26 | hi StatusLine cterm=NONE ctermfg=darkgrey ctermbg=grey guifg=blue guibg=white 27 | hi StatusLineNC cterm=NONE ctermfg=white ctermbg=lightblue guifg=white guibg=blue 28 | hi Title ctermfg=magenta guifg=Magenta 29 | hi Visual term=reverse cterm=reverse gui=reverse 30 | hi WarningMsg term=standout ctermfg=red guifg=Red 31 | hi Cursor guifg=bg guibg=Green 32 | hi Comment ctermfg=darkcyan guifg=#337733 33 | hi Constant ctermfg=blue guifg=#0000ff 34 | hi Special ctermfg=darkyellow guifg=Orange 35 | hi Identifier ctermfg=blue guifg=white 36 | hi Statement ctermfg=lightblue guifg=#0000ff 37 | hi PreProc term=underline ctermfg=blue guifg=#000099 38 | hi Type term=underline ctermfg=blue guifg=#000099 39 | hi Error term=reverse ctermfg=darkcyan ctermbg=black guifg=Red guibg=Black 40 | hi Todo term=standout ctermfg=black ctermbg=darkcyan guifg=lightblue guibg=Yellow 41 | hi CursorLine term=underline guibg=#555555 cterm=underline 42 | hi CursorColumn term=underline guibg=#555555 cterm=underline 43 | hi MatchParen term=reverse ctermfg=lightblue guibg=lightblue 44 | hi TabLine ctermfg=lightblue ctermbg=white guifg=lightblue guibg=white 45 | hi TabLineFill ctermfg=lightblue ctermbg=white guifg=lightblue guibg=white 46 | hi TabLineSel term=reverse ctermfg=white ctermbg=lightblue guifg=white guibg=blue 47 | hi link IncSearch Visual 48 | hi String ctermfg=magenta guifg=#990099 49 | hi link Character String 50 | hi link Number Constant 51 | hi link Boolean Constant 52 | hi link Float Number 53 | hi link Function Identifier 54 | hi link Conditional Statement 55 | hi link Repeat Statement 56 | hi link Label Statement 57 | hi Operator ctermfg=darkred 58 | hi link Keyword Statement 59 | hi link Exception Statement 60 | hi link Include Keyword 61 | hi link Define PreProc 62 | hi link Macro PreProc 63 | hi link PreCondit PreProc 64 | hi link StorageClass Type 65 | hi link Structure Type 66 | hi link Typedef Type 67 | hi link Tag Special 68 | hi link SpecialChar Special 69 | hi link Delimiter Operator 70 | hi link SpecialComment Special 71 | hi link Debug Special 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DevBox-Golong 2 | *Vagrant box backed by Docker or Virtualbox, with Ansible provisioning* 3 | 4 | A Vagrant box (Virtualbox or Docker as providers) with Ansible provisioning 5 | for setting up a Vim-based Golang development environment. 6 | 7 | ![Screenshot](golang-vagrant-ansible.png) 8 | 9 | ### Note: There are currently problems with the docker version of the script, so please use the virtualbox version until this is solved! 10 | 11 | ## Ingredients 12 | 13 | - [Ubuntu 16.04 "xenial" LTS 64bit base image](http://www.ubuntu.com/) 14 | - [Go(lang) 1.6.2](http://golang.org/) 15 | - [Vim](http://www.vim.org/) 16 | - [Fatih's vim-go plugin](https://github.com/fatih/vim-go), providing syntax highlight, gocode integration for autocompletion, and more. 17 | - See the [vim-go](https://github.com/fatih/vim-go) README for more info on how you can easily enable additional included features. 18 | - [GoCode Go completion engine](https://github.com/nsf/gocode) 19 | - [Git](http://git-scm.com/) 20 | - [Tig - text mode interface to git](http://jonas.nitro.dk/tig/) 21 | - [gdb - the GNU debugger](http://www.gnu.org/software/gdb) 22 | - [cgdb - Curses based user interface to gdb](https://cgdb.github.io) 23 | 24 | ## Optional ingredients 25 | 26 | *Uncomment roles in playbook.yml to enable these.* 27 | 28 | - [Valloric's YouCompleteMe](https://github.com/Valloric/YouCompleteMe) for as-you-type completion (NB: Requires uncommenting the YouCompleteMe role in playbook.yml!)). 29 | - [Apache Mesos](http://mesos.apache.org) - An open source computer cluster manager. (UI on [localhost:5050](http://localhost:5050)). 30 | 31 | ## Prerequisites 32 | 33 | - [Vagrant](https://www.vagrantup.com/) 34 | - [Ansible](http://www.ansible.com/) 35 | - [VirtualBox](https://www.virtualbox.org/) (Not required if you use Docker as provider!) 36 | - [Docker](https://www.docker.com) (Not required if you use Virtualbox as provider!) 37 | 38 | ### Installing the requirements in Ubuntu (tested with 14.04) 39 | 40 | 1. Install Virtualbox: 41 | ```bash 42 | sudo apt-get install virtualbox 43 | ``` 44 | 45 | 2. Install Docker: 46 | ```bash 47 | sudo apt-get install docker.io 48 | ``` 49 | 50 | 3. Install a recent version of ansible: 51 | ```bash 52 | sudo apt-get install ansible/trusty-backports 53 | ``` 54 | 55 | *(if you ubuntu version is "trusty", otherwise, replace it with your appropriate version)* 56 | 4. Install Vagrant, by first downloadng the proper .deb file from [vagrantup.com](https://www.vagrantup.com/downloads.html) 57 | 58 | 5. ... and then installing it with: 59 | ```bash 60 | sudo dpkg -i 61 | ``` 62 | 63 | ## Setup and Usage 64 | 65 | #### Clone the github repository: 66 | 67 | ```bash 68 | git clone git@github.com:samuell/devbox-golang 69 | cd devbox-golang 70 | ``` 71 | 72 | #### Bring up the VM 73 | 74 | With docker provider (Expect it to take at least ~8m): 75 | 76 | ```bash 77 | vagrant up docker 78 | ``` 79 | 80 | With VirtualBox provider (Expect it to take at least ~20m): 81 | 82 | ```bash 83 | vagrant up virtualbox 84 | ``` 85 | 86 | #### Log in to the VM 87 | 88 | With docker provider: 89 | 90 | ```bash 91 | vagrant ssh docker 92 | ``` 93 | 94 | With VirtualBox provider: 95 | 96 | ```bash 97 | vagrant ssh virtualbox 98 | ``` 99 | 100 | #### Create a repository for uploading to github: 101 | 102 | ```bash 103 | mkcd ~/code/go/src/github// 104 | git init . 105 | ``` 106 | 107 | #### Now, start coding! 108 | 109 | ```bash 110 | vim main.go 111 | ``` 112 | 113 | #### A tip on how you can upload your existing git ssh keys to the new vm: 114 | 115 | With the following command you can get the info you need to run scp 116 | against the machine: 117 | 118 | ```bash 119 | vagrant ssh-config [docker | virtualbox] 120 | ``` 121 | 122 | Note the hostname and port number (and identity file, if you with), 123 | and run, for example: 124 | 125 | ```bash 126 | scp -i -P \ 127 | ~/.ssh/id_rsa_ \ 128 | vagrant@:/home/vagrant/.ssh/ 129 | ``` 130 | 131 | Then, sometimes, in order to get the new key activated in your shell 132 | after logging in to the vm, you might need to do: 133 | 134 | ```bash 135 | ssh-agent bash -l 136 | ssh-add ~/.ssh/id_rsa_ 137 | ``` 138 | 139 | - Autocompletion will happen automatically 140 | - If you have turned off the YouCompleteMe role, you will get autocompletion with `` 141 | 142 | ## Known issues 143 | 144 | - GDB Breakpoints don't take, unless you follow the advice given [here](https://github.com/docker/docker/issues/7276#issuecomment-50436671). 145 | That is, in short, do this on your **Host machine**, if you run Ubuntu: 146 | 147 | ```bash 148 | sudo apt-get install apparmor-utils 149 | sudo echo 'aa-complain /etc/apparmor.d/docker' >> /etc/rc.local 150 | sudo aa-complain /etc/apparmor.d/docker 151 | ``` 152 | 153 | The problem seems to be that `ptrace` is not given access to the process otherwise. 154 | - There are some really red message from the docker daemon when running `vagrant halt`. 155 | Everything seems to work as expected though (including the shutdown) 156 | - There are some red message on vagrant up, but they are nothing serious, and can be ignored for now. 157 | - When building Go 1.5 dev, the build will end with a lot of error messages, but that is from the 158 | tests after the build. The build itself seems to work, largely. 159 | 160 | ## References 161 | 162 | - [Vagrant & Ansible Quickstart Tutorial](http://adamcod.es/2014/09/23/vagrant-ansible-quickstart-tutorial.html) 163 | -------------------------------------------------------------------------------- /roles/dotfiles/files/.bash_aliases: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # -------------------------------------------------------------------------------- 4 | # Edit dotfiles 5 | # -------------------------------------------------------------------------------- 6 | vs() { 7 | vim $1; 8 | source $1; 9 | } 10 | alias ev='vim ~/.vimrc' 11 | alias ea='vs ~/.bash_aliases' 12 | alias eal='vs ~/.bash_aliases_local' 13 | alias eb='vs ~/.bashrc' 14 | alias ebm='vs ~/.bashrc_mods' 15 | alias ebl='vs ~/.bashrc_local' 16 | alias ep='vs ~/.profile' 17 | alias et='vim ~/.tmux.conf' 18 | 19 | # -------------------------------------------------------------------------------- 20 | # Various short-hand commands 21 | # -------------------------------------------------------------------------------- 22 | # Text editing 23 | alias e='vim' 24 | alias v='vim' 25 | alias n='nano' 26 | # Aptitude 27 | alias aptg='sudo apt-get install' 28 | alias aptr='sudo apt-get remove' 29 | alias apts='apt-cache search' 30 | alias aptu='sudo apt-get update' 31 | alias aptug='sudo apt-get upgrade' 32 | alias ubuntu_version='lsb_release -a' 33 | # Git 34 | alias t='tig' 35 | alias glog='git log --pretty=oneline|tig' 36 | alias gdiff='git diff|tig' 37 | alias gcommit='git commit' 38 | alias gpush='git push' 39 | alias gpp='git pull origin master; git push origin master;' 40 | alias gprp='git pull --rebase origin master; git push origin master;' 41 | alias gadd='git add' 42 | alias gb='git branch -av' 43 | alias dus='du -sh * | sort -h' 44 | alias dusa='du -ash .* | sort -h' 45 | # SSH 46 | alias sshpass='ssh -o PubkeyAuthentication=no' 47 | alias scppass='scp -o PubkeyAuthentication=no' 48 | # Screen 49 | alias sl='screen -ls' 50 | alias sms='screen -mS' 51 | alias sr='screen -r' 52 | alias sdr='screen -dr' 53 | ks() { 54 | screen -X -S $1 quit 55 | } 56 | # tmux 57 | alias tn='tmux new' 58 | alias tns='tmux new -s' 59 | alias ta='tmux attach' 60 | alias tas='tmux attach -t' 61 | alias ts='tmux switch' 62 | alias tss='tmux switch -s' 63 | alias tl='tmux list-sessions' 64 | # The ls command 65 | alias ls='ls --color=auto -h' 66 | alias l='ls -1' 67 | alias la='ls -1a' 68 | alias ltr='ls -1tr' 69 | alias ltra='ls -1tra' 70 | alias lltr='ls -ltr' 71 | alias lltra='ls -ltra' 72 | alias last='tail -n 1' 73 | alias llast='ls -1tr | last' 74 | alias slast='llast | xargs less -iS' 75 | alias lslast='llast | xargs less -i' 76 | # Misc 77 | alias s='less -S' 78 | alias py='python' 79 | alias p='python' 80 | alias ipy='ipython' 81 | psa() { 82 | term=$1; 83 | echo "Now showing processes including $term in name ..."; 84 | /bin/ps aux | grep "$term"; 85 | } 86 | alias k='kill -9' 87 | alias R='R --no-save' 88 | padold() { 89 | mv $1{,.old} 90 | } 91 | padtmp() { 92 | mv $1{,.tmp} 93 | } 94 | pad() { 95 | mv $1{,.$2} 96 | } 97 | padrem() { 98 | mv $1{.$2,} 99 | } 100 | alias vg='vagrant' 101 | alias vgu='vagrant up' 102 | alias vgp='vagrant provision' 103 | alias vgs='vagrant ssh' 104 | alias vgd='vagrant destroy' 105 | alias sm='snakemake' 106 | function gitsshify() { 107 | echo 'git@github.com:'$1'.git'; 108 | } 109 | 110 | # -------------------------------------------------------------------------------- 111 | # Directory browsing and handling 112 | # -------------------------------------------------------------------------------- 113 | c() { 114 | cd "$1"; 115 | ls -ltra --color=always | tail -n 25; 116 | echo " "; 117 | pwd; 118 | } 119 | alias ..='cd ..' 120 | alias ....='cd ../..' 121 | alias ......='cd ../../..' 122 | mkcd() { 123 | mkdir -p $1; 124 | cd $1; 125 | } 126 | 127 | # -------------------------------------------------------------------------------- 128 | # Switch keyboard layout 129 | # -------------------------------------------------------------------------------- 130 | alias kb='setxkbmap' 131 | alias se='setxkbmap se' 132 | us() { 133 | echo "Setting keyboard map to US"; 134 | setxkbmap 'us'; 135 | # Enable åäö by holding Alt Gr and ['; 136 | xmodmap -e 'keycode 108 = Mode_switch'; 137 | xmodmap -e 'remove mod1 = Mode_switch'; 138 | xmodmap -e 'keycode 34 = bracketleft braceleft aring Aring'; 139 | xmodmap -e 'keycode 48 = apostrophe quotedbl adiaeresis Adiaeresis'; 140 | xmodmap -e 'keycode 47 = semicolon colon odiaeresis Odiaeresis'; 141 | } 142 | 143 | # -------------------------------------------------------------------------------- 144 | # Create test file 145 | # -------------------------------------------------------------------------------- 146 | alias foo='echo "Foo" > foo.txt' 147 | 148 | # -------------------------------------------------------------------------------- 149 | # Misc advanced stuff 150 | # -------------------------------------------------------------------------------- 151 | alias switchjava='sudo update-alternatives --config java' 152 | topname() { 153 | top -p $(pgrep -d"," $1); 154 | } 155 | alias ...='echo … | xsel --clipboard' 156 | time3() { 157 | if [[ ! -z "$2" ]]; then 158 | procs=$2; 159 | export GOMAXPROCS=$procs; 160 | fi; 161 | cmd=$1; 162 | echo "Benchmarking command: $cmd" 163 | echo "GOMAXPROCS: $GOMAXPROCS" 164 | t1=$({ time ./$cmd > output.txt; } 2>&1 |grep real|grep -oP "\d\.\d+") 165 | echo "Time 1: $t1" 166 | sleep 1 167 | t2=$({ time ./$cmd > output.txt; } 2>&1 |grep real|grep -oP "\d\.\d+") 168 | echo "Time 2: $t2" 169 | sleep 1 170 | t3=$({ time ./$cmd > output.txt; } 2>&1 |grep real|grep -oP "\d\.\d+") 171 | echo "Time 3: $t3" 172 | sleep 1 173 | echo "Average (3 samples): "`echo "scale=3; ($t1 + $t2 + $t3)/3.0"|bc`; 174 | } 175 | install_vundle() { 176 | git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/vundle 177 | echo "Now open vim and execute: :PluginInstall !" 178 | } 179 | bookmark() { 180 | if [[ ! $1 ]]; then 181 | echo "Usage: bookmark BOOKMARKNAME"; 182 | else 183 | name=$1; 184 | dir=$(pwd); 185 | echo "alias c$name='c $dir'" >> ~/.bash_aliases_local 186 | source ~/.bash_aliases_local 187 | fi 188 | } 189 | bookmarks() { 190 | cat ~/.bash_aliases_local | grep "alias c" 191 | } 192 | source ~/.bash_aliases_local 193 | alias installflash='sudo apt-get install pepperflashplugin-nonfree' 194 | alias updateflash='sudo update-pepperflashplugin-nonfree --install' 195 | function lf() { 196 | ls -1tr | tail -n 1; 197 | } 198 | alias cutt='cut -c -$COLUMNS' 199 | div() { 200 | echo "==========================================================================" 201 | echo " $1" 202 | echo "==========================================================================" 203 | } 204 | alias now='date +%Y%m%d_%H%M%S'; 205 | alias d='sudo docker' 206 | alias docker='sudo docker' 207 | p12_to_pem() { 208 | openssl pkcs12 -in $1 -out $1'.crt.pem' -clcerts -nokeys 209 | openssl pkcs12 -in $1 -out $1'.key.pem' -nocerts -nodes 210 | } 211 | dh() { 212 | cat <