mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
[go-server] Add dockerfile for building and run petstore service (#274)
* Add possibility to build and run go service in a container * Remove tabs * Update Pet Store server sample * Add {{{packageName}}} instead of petstore
This commit is contained in:
parent
55f9e31f81
commit
299527370e
@ -110,6 +110,7 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
||||
*/
|
||||
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"));
|
||||
|
@ -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}}"]
|
@ -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 {{{packageName}}} .
|
||||
```
|
||||
|
||||
Once image is built use
|
||||
```
|
||||
docker run --rm -it {{{packageName}}}
|
||||
```
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT
|
||||
3.0.1-SNAPSHOT
|
14
samples/server/petstore/go-api-server/Dockerfile
Normal file
14
samples/server/petstore/go-api-server/Dockerfile
Normal file
@ -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"]
|
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,16 @@
|
||||
# Go API Server for petstoreserver
|
||||
|
||||
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen]
|
||||
(https://github.com/swagger-api/swagger-codegen) project.
|
||||
This server was generated by the [openapi-generator]
|
||||
(https://openapi-generator.tech) project.
|
||||
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
|
||||
-
|
||||
|
||||
To see how to make this your own, look here:
|
||||
|
||||
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
|
||||
[README]((https://openapi-generator.tech))
|
||||
|
||||
- API version: 1.0.0
|
||||
|
||||
@ -22,3 +22,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 petstoreserver .
|
||||
```
|
||||
|
||||
Once image is built use
|
||||
```
|
||||
docker run --rm -it petstoreserver
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user