Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[go-server] Add dockerfile for building and run petstore service #274

Merged
merged 4 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void processOpts() {
*/
supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml"));
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go"));
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.10 AS build
WORKDIR /go/src
COPY {{apiPath}} ./{{apiPath}}
COPY main.go .

ENV CGO_ENABLED=0
RUN go get -d -v ./...

RUN go build -a -installsuffix cgo -o {{packageName}} .

FROM scratch AS runtime
COPY --from=build /go/src/{{packageName}} ./
EXPOSE 8080/tcp
ENTRYPOINT ["./{{packageName}}"]
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ To run the server, follow these simple steps:
go run main.go
```

To run the server in a docker container
```
docker build --network=host -t petstore .
```

Once image is built use
```
docker run --rm -it petstore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etherealjoy should petstore be replaced by {{{packageName}}} instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, I have updated the commit.

```


Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.0.1-SNAPSHOT
14 changes: 14 additions & 0 deletions samples/server/petstore/go-api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.10 AS build
WORKDIR /go/src
COPY go ./go
COPY main.go .

ENV CGO_ENABLED=0
RUN go get -d -v ./...

RUN go build -a -installsuffix cgo -o petstoreserver .

FROM scratch AS runtime
COPY --from=build /go/src/petstoreserver ./
EXPOSE 8080/tcp
ENTRYPOINT ["./petstoreserver"]
Loading