Skip to content

Commit e83263f

Browse files
author
Edward Muller
committed
docker: make the setup work locally for dev.
Also don't error when the websocket is closed.
1 parent 83444f5 commit e83263f

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

Dockerfile

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
FROM heroku/go:latest
1+
FROM heroku/cedar:14
2+
MAINTAINER Heroku Build & Packaging Team <[email protected]>
3+
4+
COPY . /app/src/github.com/heroku-examples/go-websocket-chat-demo
5+
WORKDIR /app/src/github.com/heroku-examples/go-websocket-chat-demo
6+
7+
ENV HOME /app
8+
ENV GOVERSION=1.8
9+
ENV GOROOT $HOME/.go/$GOVERSION/go
10+
ENV GOPATH $HOME
11+
ENV PATH $PATH:$HOME/bin:$GOROOT/bin:$GOPATH/bin
12+
13+
RUN mkdir -p $HOME/.go/$GOVERSION
14+
RUN cd $HOME/.go/$GOVERSION; curl -s https://storage.googleapis.com/golang/go$GOVERSION.linux-amd64.tar.gz | tar zxf -
15+
RUN go install -v github.com/heroku-examples/go-websocket-chat-demo

app.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"keywords": [
55
"streaming",
66
"redis",
7-
"go"
7+
"go",
8+
"websocket"
89
],
9-
"image": "heroku/go:latest",
10-
"mount_dir": "src/github.com/heroku-examples/go-websocket-chat-demo",
1110
"website": "http://github.com/heroku-examples/go-websocket-chat-demo",
1211
"repository": "http://github.com/heroku-examples/go-websocket-chat-demol",
1312
"addons": [

chat.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ func handleWebsocket(w http.ResponseWriter, r *http.Request) {
6060
mt, data, err := ws.ReadMessage()
6161
l := log.WithFields(logrus.Fields{"mt": mt, "data": data, "err": err})
6262
if err != nil {
63-
if err == io.EOF {
63+
if websocket.IsCloseError(err, websocket.CloseGoingAway) || err == io.EOF {
6464
l.Info("Websocket closed!")
65-
} else {
66-
l.Error("Error reading websocket message")
65+
break
6766
}
68-
break
67+
l.Error("Error reading websocket message")
6968
}
7069
switch mt {
7170
case websocket.TextMessage:

docker-compose.yml

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
web:
2-
build: .
3-
command: 'bash -c ''go-websocket-chat-demo-web'''
4-
working_dir: /app/user/src/github.com/heroku-examples/go-websocket-chat-demo
5-
environment:
6-
PORT: 8080
7-
REDIS_URL: 'redis://herokuRedis:6379'
8-
ports:
9-
- '8080:8080'
10-
links:
11-
- herokuRedis
12-
shell:
13-
build: .
14-
command: bash
15-
working_dir: /app/user/src/github.com/heroku-examples/go-websocket-chat-demo
16-
environment:
17-
PORT: 8080
18-
REDIS_URL: 'redis://herokuRedis:6379'
19-
ports:
20-
- '8080:8080'
21-
links:
22-
- herokuRedis
23-
volumes:
24-
- '.:/app/user/src/github.com/heroku-examples/go-websocket-chat-demo'
25-
herokuRedis:
26-
image: redis
1+
version: '2'
2+
3+
services:
4+
app:
5+
command: go-websocket-chat-demo
6+
build: .
7+
environment:
8+
PORT: '5000'
9+
REDIS_URL: 'redis://redis:6379'
10+
depends_on:
11+
- redis
12+
ports:
13+
- "127.0.0.1:5000:5000"
14+
15+
redis:
16+
image: redis
17+
ports:
18+
- "6379:6379"

0 commit comments

Comments
 (0)