miguelmota / streamhut

Stream your terminal to web without installing anything 🌐
https://streamhut.io
Apache License 2.0
906 stars 38 forks source link

Dockerfile does not build #6

Closed boppy closed 4 years ago

boppy commented 4 years ago

Building of the supplied Dockerfile results in:

pkg/tcpserver/tcpserver.go:15:2: cannot find package "github.com/patrickmn/go-cache" in any of:
    /go/src/github.com/streamhut/streamhut/vendor/github.com/patrickmn/go-cache (vendor tree)
    /usr/local/go/src/github.com/patrickmn/go-cache (from $GOROOT)
    /go/src/github.com/patrickmn/go-cache (from $GOPATH)

Full Log at https://gist.github.com/boppy/ff44e290d663eda4c31d72dd015a571e

boppy commented 4 years ago

Additional: If I modify the Dockerfile to be the following, it continues with compiling, but stops with:

The command '/bin/sh -c CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o streamhut cmd/streamhut/main.go' returned a non-zero code: 2

Dockerfile:

FROM golang:1.12rc1-alpine3.9

RUN apk --no-cache add gcc musl-dev ca-certificates git
#                                                   ^ new
COPY . /go/src/github.com/streamhut/streamhut
WORKDIR /go/src/github.com/streamhut/streamhut

RUN go get github.com/patrickmn/go-cache
# ^ full line is new

RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o streamhut cmd/streamhut/main.go

CMD ["./streamhut", "server"]
miguelmota commented 4 years ago

@boppy that is bizarre since go-cache is definitely in the vendor directory. You could try re-downloading the dependencies right before the build command:

FROM golang:1.12rc1-alpine3.9

RUN apk --no-cache add gcc musl-dev ca-certificates git
COPY . /go/src/github.com/streamhut/streamhut
WORKDIR /go/src/github.com/streamhut/streamhut

RUN GO111MODULE=on go mod download
RUN GO111MODULE=on go mod vendor

RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o streamhut cmd/streamhut/main.go

CMD ["./streamhut", "server"]
boppy commented 4 years ago

download+vendor does the trick!

But without downloading I still get the same error with the current git version.

miguelmota commented 4 years ago

There was an issue with the .gitignore file causing some of the dependencies in the vendor directory to be ignored. It's resolved now and this should work. I tested it on a fresh git clone:

Dockerfile

FROM golang:1.12rc1-alpine3.9

RUN apk --no-cache add gcc musl-dev ca-certificates
COPY . /go/src/github.com/streamhut/streamhut
WORKDIR /go/src/github.com/streamhut/streamhut

RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o streamhut cmd/streamhut/main.go

CMD ["./streamhut", "server"]

Build

docker build -t streamhut/streamhut .

Run

docker run -p 8080:8080 -p 1337:1337 streamhut/streamhut:latest

Closing the issue but let me know if it doesn't work still.