goaltools / goal

Goal is a toolkit for high productivity web development in Go language in the spirit of Revel Framework that is built around the concept of code generation.
BSD 2-Clause "Simplified" License
87 stars 3 forks source link

Docker support #27

Open davidhunterxyz opened 8 years ago

davidhunterxyz commented 8 years ago

Goal gives a error while trying to build a docker image with this dockerfile. It works if the project files are on a public github repo.

fatal: could not read Username for 'https://github.com': No such device or address package github.com/davidhunter/goal-sample/server: exit status 128

FROM golang:onbuild
EXPOSE 8080

Then their is another issue where I can't connect to it outside a container.

ghost commented 8 years ago

@DavidHunter Not really something Goal specific as a project developed with Goal is just a regular Go app that can be built as follows:

go build github.com/davidhunter/goal-sample

So, any Dockerfile that works for a standard library based Go app will work for your project, too. E.g., Revel's Dockerfile from the thread:

FROM debian
RUN apt-get update

WORKDIR /home
ADD ./ /home

ENTRYPOINT /home/bin/run
EXPOSE 8080

In this case you have to have an already compiled binary of your project.

Alternatively, use this sample from Go language's docs, do not try to install Goal, install your project:

# Build the outyet command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN go install github.com/davidhunter/goal-sample

fatal: could not read Username for 'https://github.com': No such device or address package github.com/davidhunter/goal-sample/server: exit status 128

Do you have access for git clone github.com/davidhunter/goal-sample/server? Here is a related SO question: Docker: go get from a private GitHub repo.

ghost commented 8 years ago

The issue has been resolved, it is not enough to listen on localhost:8080 (#32).

The way to run an app with the Dockerfile mentioned in the message above:

# Build the image and tag it as myImage (use whatever tag name you want).
docker build -t myImage .

# Run the app, publish container's :8080 port on the external :8080 port
# (format: `external_addr_or_port:container's_port`), give the app a predictable name.
docker run --publish 8080:8080 --name myApp
davidhunterxyz commented 8 years ago

@alkchr I think a docker file inside the project skeleton would be useful for this project

ghost commented 8 years ago

:+1: Should it be a Dockerfile that uses golang:onbuild to compile the app and then start it as in your https://github.com/colegion/goal/issues/27#issue-116486718? Or we can just copy already compiled binary from bin directory and use it with debian image as in my https://github.com/colegion/goal/issues/27#issuecomment-156020484?

davidhunterxyz commented 8 years ago

golang:onbuild only worked for me if the Goal project repository was on github.com and I had to build the binary with env GOOS=linux go build -o bin/run for it to work in docker when just copying over the binary.

I am not sure if I am using golang:onbuild wrong or if their is a way to build the binary for mac and linux.

This Dockerfile seems to work when the install path is set to the same project gopath.

FROM golang:1.5

COPY . /go/src/github.com/colegion/goal/internal/skeleton
WORKDIR /go/src/github.com/colegion/goal/internal/skeleton

RUN go get -u github.com/colegion/goal/...
RUN go install github.com/colegion/goal/internal/skeleton

ENTRYPOINT /go/bin/skeleton

EXPOSE 8080
ghost commented 8 years ago

This Dockerfile seems to work when the install path is set to the same project gopath.

Yeah, right. Because generated apps use absolute import paths (e.g. github.com/johndoe/forum/controllers instead of ./controllers). So, you have to keep the structure in order to compile the code.

Your Dockerfile looks good. Does it work without the RUN go get -u github.com/colegion/goal/...? If so, I would go with the following config:

FROM golang:1.5

COPY . /go/src/github.com/colegion/goal/internal/skeleton
WORKDIR /go/src/github.com/colegion/goal/internal/skeleton

# Flag "-d" means download only, do not install.
RUN go get -d github.com/colegion/goal/internal/skeleton
RUN go build -o ./bin/run github.com/colegion/goal/internal/skeleton

ENTRYPOINT ./bin/run --http.addr :8080

EXPOSE 8080

If this works, we can add to the skeleton and close this issue.

davidhunterxyz commented 8 years ago

@alkchr Your docker file works