Skip to content

Commit 45931f4

Browse files
committed
Merge pull request #5 from vise890/dockerize-cloujera
[RFC] Dockerize cloujera
2 parents 25671b4 + a8869f3 commit 45931f4

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM java:7
2+
3+
ADD ./target/uberjar/cloujera-0.1.0-SNAPSHOT-standalone.jar /srv/cloujera.jar
4+
5+
EXPOSE 8080
6+
7+
CMD ["java", "-jar", "/srv/cloujera.jar"]

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,30 @@ videos on [coursera](http://coursera.org).
2020
(it will error out ridiculously with an `IndexMissingException` from
2121
elasticsearch if you don't do this!);
2222

23+
### Testing dockerized cloujera inside Vagrant VM
2324

24-
## Testing uberjar inside Vagrant
25+
```bash
26+
$ vagrant ssh
27+
$ cd /vagrant
28+
$ ./scripts/deploy.sh
29+
```
30+
31+
**NOTE:** the address to access the dockerized cloujera is
32+
`http://127.0.0.1:8081` (see `Vagrantfile`)
33+
34+
35+
### Testing uberjar inside Vagrant
2536

2637
```bash
2738
$ vagrant ssh
2839
$ cd /vagrant
2940
$ source ./scripts/prod-env.sh
30-
$ ./scripts/deploy.sh
41+
$ lein uberjar
42+
$ java -jar ./target/uberjar/cloujera-*-standalone.jar
3143
```
3244

3345
**NOTE:** the address to access the uberjarred cloujera running on port `8080`
34-
is `http://127.0.0.1:8081` (see `Vagrantfile`)
35-
36-
**FIXME**: the sourcing of prod-env.sh is just a temporary fix while we move to
37-
docker ....
46+
is `http://127.0.0.1:8082` (see `Vagrantfile`)
3847

3948

4049
## Scraping courses
@@ -76,7 +85,6 @@ $ sudo ./scripts/provision.sh
7685

7786
```bash
7887
# in the cloujera directory...
79-
$ source ./scripts/prod-env.sh
8088
$ ./scripts/deploy.sh
8189
```
8290

@@ -92,13 +100,14 @@ $ vagrant ssh
92100
$ sudo docker ps -a
93101
```
94102

95-
You should see `redis` and `elasticsearch` running
103+
You should see `redis`, `elasticsearch` and `cloujera` running
96104

97105

98106
### Checking the cloujera logs
99107

100108
```bash
101-
$ cat cloujera.log
109+
$ vagrant ssh
110+
$ sudo docker exec cloujera cat /var/cloujera.log
102111
```
103112

104113
### Checking elasticsearch health
@@ -114,6 +123,13 @@ Visit `http://localhost:9200/`, you should see `status: 200`
114123
**NOTE**: this works form the host as well as in the Vagrant VM
115124

116125

126+
### Dropping into a shell inside a container
127+
```bash
128+
$ vagrant ssh || ssh user@cloudbox
129+
$ sudo docker exec -i -t cloujera bash
130+
```
131+
132+
117133
# BUGS
118134
- `lein run` doesn't give any output initially
119135
- `lein run` doesn't reload

Vagrantfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1515
config.vm.network "forwarded_port", guest: 6379, host: 6379
1616

1717
# Cloujera port
18-
config.vm.network "forwarded_port", guest: 8080, host: 8081 # for lein run/uberjar inside VM
18+
config.vm.network "forwarded_port", guest: 80, host: 8081 # for cloujera Docker container
19+
config.vm.network "forwarded_port", guest: 8080, host: 8082 # for lein run/uberjar inside VM
1920

2021
# provisioning: docker, elasticsearch, redis
2122
config.vm.provision "shell", path: "./scripts/provision.sh"

profiles.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
;; we define :elasticsearch-port and :redis-port with weird names and format
66
;; because that's the the ones Docker exports in linked containers
77
{:dev {:env {:elasticsearch-port "tcp://127.0.0.1:9200"
8-
:redis-port "tcp://127.0.0.1:9300"}}}
8+
:redis-port "tcp://127.0.0.1:6379"}}}

scripts/deploy.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
set -euo pipefail
33
IFS=$'\n\t'
44

5+
sudo -v
6+
7+
cloujera_container_name="cloujera"
8+
cloujera_image_tag=$cloujera_container_name
9+
510
echo "==> pulling most recent version (git)"
611
# FIXME: it would be nice to checkout to avoid weird
712
# stuff happening, but it's really easy to run this
@@ -16,5 +21,17 @@ lein cljsbuild once
1621
echo "==> Uberjarring"
1722
lein uberjar
1823

19-
echo "==> Running cloujera"
20-
java -jar ./target/uberjar/cloujera-0.1.0-SNAPSHOT-standalone.jar > cloujera.log 2>&1
24+
echo "==> Building new cloujera container"
25+
sudo docker build --tag $cloujera_image_tag ./
26+
27+
echo "==> Removing existing cloujera container"
28+
sudo docker rm -f $cloujera_container_name || true
29+
30+
echo "==> Running container"
31+
sudo docker run \
32+
--detach \
33+
--publish 80:8080 \
34+
--name $cloujera_container_name \
35+
--link redis:redis \
36+
--link elasticsearch:elasticsearch \
37+
$cloujera_image_tag

src/clj/cloujera/cache/core.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
redis-uri (.replaceAll redis-tcp-uri
99
"^tcp://" "")
1010
[host port] (string/split redis-uri #":")]
11-
{:host host
12-
:port (Integer. port)}))
11+
{:spec {:host host
12+
:port (Integer. port)}}))
1313

1414
(defn persist [f]
1515
(fn [k]

0 commit comments

Comments
 (0)