Skip to content

Commit

Permalink
Dockerfile: add flexible Go version support (#14)
Browse files Browse the repository at this point in the history
* add example code

* update READM

* some fixes
  • Loading branch information
canthefason authored Jan 27, 2017
1 parent a9a23c8 commit 1fe9fe1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
bison \
&& rm -rf /var/lib/apt/lists/*

RUN rm /bin/sh && ln -s /bin/bash /bin/sh
SHELL ["/bin/bash", "-c"]

ENV GO_VERSION 1.7

Expand All @@ -26,6 +26,8 @@ RUN chmod +x /root/.gvm/bin/watcher

ENV GOPATH /go

WORKDIR /go/src

VOLUME /go/src
ADD entrypoint.sh /

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ Since Globs and some optional folder arrays will make it harder to configure, we

## Watcher in Docker

If you want to run Watcher in a containerized local environment, you can achieve this by using canthefason/watcher image in Docker Hub. There is an example project under /docker-example directoy. Let's first try to dockerize this example code first.
If you want to run Watcher in a containerized local environment, you can achieve this by using [canthefason/go-watcher](https://hub.docker.com/r/canthefason/go-watcher/) image in Docker Hub. There is an example project under [/docker-example](https://github.com/canthefason/go-watcher/tree/dockerfile-gvm/docker-examples) directoy. Let's try to dockerize this example code first.

In our example, we are creating a server that listens to port 7000 and responds to all clients with "watcher is running" string. The most essential thing to run your code in Docker is, mounting your project volume to a container. In the containerized Watcher, our GOPATH is set to /go directory by default, so you need to mount your project to this GOPATH.

`docker run -v /path/to/hello:/go/src/hello -p 7000:7000 canthefason/watcher watcher -run hello`
`docker run -v /path/to/hello:/go/src/hello -p 7000:7000 canthefason/go-watcher watcher -run hello`

Containerized Watcher also supports different versions of Go by leveraging [gvm](https://github.com/moovweb/gvm). Currently it only supports major versions right now. If you don't set anything, by default Watcher will pick version 1.7. If you want to change the Go version, you can use GO_VERSION environment variable. Currently it only supports 1.4, 1.5, 1.6, 1.7 at the moment

`docker run -v /path/to/hello:/go/src/hello -e GO_VERSION=1.6 -p 7000:7000 canthefason/watcher watcher -run hello`
`docker run -v /path/to/hello:/go/src/hello -e GO_VERSION=1.6 -p 7000:7000 canthefason/go-watcher watcher -run hello`

To provide a more structured repo, we also integrated a docker-compose manifest file. That file already handles volume mounting operation that and exposes the port to the localhost. With docker-compose the only thing that you need to do from the root, invoking `docker-compose up
To provide a more structured repo, we also integrated a docker-compose manifest file. That file already handles volume mounting operation that and exposes the port to the localhost. With docker-compose the only thing that you need to do from the root, invoking `docker-compose up

#### Known Issues
On Mac OS X, when you make a tls connection, you can get a message like: x509: `certificate signed by unknown authority`
Expand Down
12 changes: 12 additions & 0 deletions docker-examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2.1'

services:
hello:
image: canthefason/go-watcher:latest
command: watcher -run hello
ports:
- "7000:7000"
environment:
- GO_VERSION=1.7
volumes:
- ./hello:/go/src/hello
16 changes: 16 additions & 0 deletions docker-examples/hello/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"net/http"
)

func main() {
http.ListenAndServe(":7000",
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "watcher is running")
},
),
)
}
2 changes: 1 addition & 1 deletion watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func TestIsWatchedFileType(t *testing.T) {
fileName = "/go/src/github.com/canthefason/go-watcher/README.md"

if isWatchedFileType(fileName) {
t.Errorf("expected true, got false")
t.Errorf("expected false, got true")
}
}

0 comments on commit 1fe9fe1

Please sign in to comment.