Skip to content

Commit 5973118

Browse files
author
Allan Simon
committed
first commit, just enough to work
0 parents  commit 5973118

16 files changed

Lines changed: 708 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vagrant
2+
keys

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
#RUN echo '91.189.92.201 archive.ubuntu.com' >> /etc/hosts
29+
30+
# Update apt-cache, so that stuff can be installed
31+
# Install python (otherwise ansible will not work)
32+
# Install aptitude, since ansible needs it (only apt-get is installed)
33+
RUN apt-get -y update && \
34+
apt-get -y install python && \
35+
apt-get -y install aptitude
36+
37+
# Enable password-less sudo for all user (including the 'vagrant' user)
38+
RUN chmod u+w ${SUDOFILE}
39+
RUN echo '%sudo ALL=(ALL:ALL) NOPASSWD: ALL' >> ${SUDOFILE}
40+
RUN chmod u-w ${SUDOFILE}

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Devbox for golang projects using docker
2+
3+
### What you will get at the end
4+
5+
* a docker container in which you can SSH in
6+
* go 1.4.2 installed, GOPATH configured etc., with the most popular tools (godep/ goimports / oracle / etc.) installed
7+
* (optional) Vim: with [vim-go](https://github.com/fatih/vim-go) / tagbar / YouCompleMe etc. and my vimrc (that you can easily replace by yours)
8+
* (optional) Zsh: with my zshrc (that you can replace by yours
9+
* (optional, not activated by default): Postgresql with a database and user precreated
10+
11+
### Screenshots
12+
13+
Shamelessy taken from vim-go:
14+
15+
![vim-go](https://dl.dropboxusercontent.com/u/174404/vim-go-2.png)
16+
17+
18+
### Requirements
19+
20+
* docker
21+
* ansible
22+
* vagrant
23+
24+
### Creation
25+
26+
```bash
27+
./create_docker.sh
28+
```
29+
30+
### Usage
31+
32+
```bash
33+
vagrant ssh
34+
```
35+
36+
37+
### Extensive list of stuff installed:
38+
39+
TODO

Vagrantfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
## Define some app-specific stuff to be used later during provisioning: ##
5+
app_vars = {
6+
APPUSER: 'vagrant', #externalized so that we can use ansible without vagrant
7+
DBNAME: 'sentencealigner',
8+
DBUSER: 'vagrant',
9+
DBPASSWORD: 'sentence-aligner'
10+
}
11+
# ansible_verbosity = 'vvvv'
12+
##########################################################################
13+
14+
#Fix for people with strange locale settings
15+
ENV.keys.each {|k| k.start_with?('LC_') && ENV.delete(k)}
16+
17+
Vagrant.configure(2) do |dkr|
18+
19+
dkr.vm.provider "docker" do |d|
20+
d.has_ssh = true
21+
d.build_dir = "."
22+
end
23+
system("bash genkeys.sh")
24+
25+
dkr.ssh.private_key_path = "keys/vagrantssh.key"
26+
dkr.ssh.username = "vagrant"
27+
28+
verbosity_arg = if defined? ansible_verbosity then ansible_verbosity else '' end
29+
dkr.vm.synced_folder "./", "/vagrant"
30+
dkr.vm.provision :ansible do |ansible|
31+
ansible.playbook = 'provisioning/site.yml'
32+
ansible.extra_vars = app_vars
33+
ansible.verbose = verbosity_arg
34+
end
35+
36+
dkr.vm.network "forwarded_port", guest: 80, host: 8180
37+
dkr.vm.network "forwarded_port", guest: 8080, host: 8188
38+
end

create_docker.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
if ! command -v docker &>/dev/null; then
4+
>&2 echo "Docker is not installed"
5+
exit 1
6+
fi
7+
8+
if ! groups | grep '\bdocker\b' --only-matching &>/dev/null ; then
9+
>&2 echo "Current user is not member of docker group"
10+
exit 2
11+
fi
12+
13+
if ! command -v ansible &>/dev/null ; then
14+
>&2 echo "Ansible is not installed"
15+
exit 3
16+
fi
17+
18+
if ! command -v vagrant &>/dev/null; then
19+
>&2 echo "Vagrant is not installed"
20+
exit 4
21+
fi
22+
23+
vagrant provision
24+
25+
# name of the docker container given by vagrant
26+
#
27+
# vagrant store the id of the docker image, that we use
28+
# to get the image name from docker ps
29+
VAGRANT_NAME=$(
30+
docker ps |
31+
grep $(<.vagrant/machines/default/docker/docker_build_image) |
32+
grep -e '[^ ]*$' --only-matching
33+
)
34+
35+
36+
# we name the container so that we can reuse it
37+
docker commit "$VAGRANT_NAME" go_vim_docker
38+
39+
echo -n "\n\n\n\n\n"
40+
echo "container go_vim_docker created, you now can either do :"
41+
echo " * vagrant ssh => if you just need one environment"
42+
echo " * docker run -d --name YOUR_PROJECT -p YOUR_LOCAL_PORT:22 go_vim_docker => if you need one env by project"
43+
echo -n "\n\n\n\n\n"
44+

genkeys.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: Create user folder in go_path
2+
file:
3+
dest="{{ go_path }}/src/github.com/allan-simon"
4+
state=directory
5+
- name: link source folder into workspace
6+
file:
7+
src=/vagrant/src
8+
dest="{{ go_path }}/src/github.com/allan-simon/sentence-aligner"
9+
state=link
10+
11+
- name: Install go Packages required by the app
12+
command: >
13+
go get -u {{ item }}
14+
environment:
15+
GOPATH: "{{ go_path }}"
16+
GOROOT: "{{ go_root }}"
17+
PATH: "{{ go_root }}/bin:{{ go_path }}/bin:/usr/bin:/bin"
18+
with_items:
19+
- github.com/emicklei/go-restful
20+
- github.com/lib/pq
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go_path: /home/vagrant/code/go
2+
go_root: /home/vagrant/opt/go
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
- name: Download Golang binary distribution
3+
get_url:
4+
url=https://storage.googleapis.com/golang/{{ go_archive_file }}
5+
dest={{ home }}/{{ go_archive_file }}
6+
- name: Create ~/opt folder
7+
file:
8+
path={{ home }}/opt
9+
state=directory
10+
- name: Unpack the Go binary distribution
11+
unarchive:
12+
copy=no
13+
src={{ home }}/{{ go_archive_file }}
14+
dest={{ home }}/opt
15+
creates={{ home }}/opt/go
16+
- name: Add go path settings in .bashrc
17+
lineinfile: dest={{ home }}/.bashrc line="{{ item }}" insertafter=EOF
18+
with_items:
19+
- 'export GOROOT={{ go_root }}'
20+
- 'export GOPATH={{ go_path }}'
21+
- 'export PATH={{ go_root }}/bin:$PATH'
22+
- 'export PATH={{ go_path }}/bin:$PATH'
23+
24+
- name: Add go path settings in .zshrc
25+
lineinfile: dest={{ home }}/.zshrc line="{{ item }}" insertafter=EOF
26+
with_items:
27+
- 'export GOROOT={{ go_root }}'
28+
- 'export GOPATH={{ go_path }}'
29+
- 'export PATH={{ go_root }}/bin:$PATH'
30+
- 'export PATH={{ go_path }}/bin:$PATH'
31+
32+
- name: Create go code folder
33+
file:
34+
dest={{ go_path }}/src/github.com
35+
state=directory
36+
recurse=yes
37+
owner=vagrant
38+
group=vagrant
39+
- name: Install some nice go packages
40+
command: >
41+
go get {{ item }}
42+
environment:
43+
GOPATH: "{{ go_path }}"
44+
GOROOT: "{{ go_root }}"
45+
PATH: "{{ go_root }}/bin:{{ go_path }}/bin:/usr/bin:/bin"
46+
with_items:
47+
- golang.org/x/tools/cmd/oracle
48+
- github.com/nsf/gocode
49+
- github.com/tools/godep
50+
- github.com/rogpeppe/godef
51+
- github.com/jstemmer/gotags
52+
- golang.org/x/tools/cmd/goimports
53+
- bitbucket.org/gotamer/gowatch
54+
- bitbucket.org/liamstask/goose/cmd/goose
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
go_version: 1.4.2
3+
go_archive_file: go{{ go_version }}.linux-amd64.tar.gz
4+
go_binary: "{{ home }}/opt/go/bin/go"
5+
go_root: "{{ home }}/opt/go"
6+
go_path: "{{ home }}/code/go"

0 commit comments

Comments
 (0)