Dockerize

This commit is contained in:
simon987 2020-03-19 11:00:59 -04:00
parent a9eb0cb659
commit 2b7813cc1b
5 changed files with 64 additions and 7 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea/
*.iml
*.iml
ws_feed_adapter

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
# Build
FROM golang:1.14 as go_build
WORKDIR /build/
COPY main.go .
COPY go.mod .
RUN GOOS=linux CGO_ENABLED=0 go build -a -installsuffix cgo -o ws_feed_adapter .
FROM scratch
WORKDIR /root/
COPY --from=go_build ["/build/ws_feed_adapter", "/root/"]
CMD ["/root/ws_feed_adapter"]

10
go.mod Normal file
View File

@ -0,0 +1,10 @@
module github.com/simon987/ws_feed_adapter
go 1.14
require (
github.com/gorilla/websocket v1.4.1
github.com/sirupsen/logrus v1.4.2
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
github.com/urfave/cli/v2 v2.2.0
)

26
go.sum Normal file
View File

@ -0,0 +1,26 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71 h1:2MR0pKUzlP3SGgj5NYJe/zRYDwOu9ku6YHy+Iw7l5DM=
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

18
main.go
View File

@ -5,7 +5,7 @@ import (
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"github.com/streadway/amqp"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"log"
"net/http"
"os"
@ -28,24 +28,30 @@ func main() {
app := cli.NewApp()
app.Name = "ws_feed_adapter"
app.Usage = "Expose RabbitMQ feed to websocket"
app.Email = "me@simon987.net"
app.Author = "simon987"
app.Version = "1.0"
app.Authors = []*cli.Author{
{
Name: "simon987",
Email: "me@simon987.net",
},
}
var listenAddr string
app.Flags = []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "rabbitmq_host",
Usage: "RabbitMQ Host",
Destination: &serverCtx.rabbitmqHost,
Value: "amqp://guest:guest@localhost:5672/",
EnvVars: []string{"WSA_MQ_CONNSTR"},
},
cli.StringFlag{
&cli.StringFlag{
Name: "listen, l",
Usage: "Listen address",
Destination: &listenAddr,
Value: "localhost:3090",
Value: "0.0.0.0:3090",
EnvVars: []string{"WSA_LISTEN"},
},
}