Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from commitdev/docker-http-generation
Docker http generation
- Loading branch information
Showing
22 changed files
with
228 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build | ||
WORKDIR /cache | ||
COPY go.mod . | ||
COPY . . | ||
RUN go build -o hello-world | ||
|
||
FROM alpine | ||
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
RUN apk update && apk add ca-certificates | ||
COPY --from=build /cache/hello-world /app/ | ||
ENTRYPOINT /app/hello-world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build | ||
WORKDIR /cache | ||
COPY . . | ||
RUN go build http/main.go -o hello-world-http | ||
|
||
FROM alpine | ||
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
RUN apk update && apk add ca-certificates | ||
COPY --from=build /cache/hello-world /app/ | ||
ENTRYPOINT /app/hello-world-http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"context" | ||
"net/http" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"google.golang.org/grpc" | ||
|
||
health "github.com/yourrepo/hello-world-idl/gen/go/health" | ||
helloworld "github.com/yourrepo/hello-world-idl/gen/go/helloworld" | ||
) | ||
|
||
func run(endpoint string, listening string) error { | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
mux := runtime.NewServeMux() | ||
opts := []grpc.DialOption{grpc.WithInsecure()} | ||
err := health.RegisterHealthHandlerFromEndpoint(ctx, mux, endpoint, opts) | ||
err = helloworld.RegisterHelloworldHandlerFromEndpoint(ctx, mux, endpoint, opts) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return http.ListenAndServe(listening, mux) | ||
} | ||
|
||
func main() { | ||
endpoint := "0.0.0.0:3000" | ||
listening := "0.0.0.0:8080" | ||
log.Printf("Starting http grpc gateway server on %v...", listening) | ||
|
||
if err := run(endpoint, listening); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package docker | ||
|
||
import ( | ||
"github.com/commitdev/sprout/util" | ||
|
||
"github.com/commitdev/sprout/config" | ||
"github.com/commitdev/sprout/templator" | ||
) | ||
|
||
func GenerateGoAppDockerFile(templator *templator.Templator, config *config.SproutConfig) { | ||
util.TemplateFileIfDoesNotExist("docker/app", "Dockerfile", templator.Docker.ApplicationDocker, config) | ||
util.TemplateFileIfDoesNotExist("./", ".dockerignore", templator.Docker.DockerIgnore, config) | ||
|
||
} | ||
|
||
func GenerateGoHttpGWDockerFile(templator *templator.Templator, config *config.SproutConfig) { | ||
util.TemplateFileIfDoesNotExist("docker/http", "Dockerfile", templator.Docker.HttpGatewayDocker, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package http | ||
|
||
import ( | ||
"github.com/commitdev/sprout/util" | ||
|
||
"github.com/commitdev/sprout/config" | ||
"github.com/commitdev/sprout/templator" | ||
) | ||
|
||
func GenerateHttpGW(templator *templator.Templator, config *config.SproutConfig) { | ||
util.TemplateFileIfDoesNotExist("http", "main.go", templator.Go.GoHttpGW, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build | ||
WORKDIR /cache | ||
COPY go.mod . | ||
COPY . . | ||
RUN go build -o {{ .Name }} | ||
|
||
FROM alpine | ||
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
RUN apk update && apk add ca-certificates | ||
COPY --from=build /cache/{{ .Name }} /app/ | ||
ENTRYPOINT /app/{{ .Name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build | ||
WORKDIR /cache | ||
COPY . . | ||
RUN go build http/main.go -o {{ .Name }}-http | ||
|
||
FROM alpine | ||
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 | ||
RUN apk update && apk add ca-certificates | ||
COPY --from=build /cache/{{ .Name }} /app/ | ||
ENTRYPOINT /app/{{ .Name }}-http |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"context" | ||
"net/http" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"google.golang.org/grpc" | ||
|
||
health "{{ $.GitRepo }}/{{ $.Name }}-idl/gen/go/health" | ||
{{- range .Services}} | ||
{{ .Name }} "{{ $.GitRepo }}/{{ $.Name }}-idl/gen/go/{{ .Name }}" | ||
{{- end}} | ||
) | ||
|
||
func run(endpoint string, listening string) error { | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
mux := runtime.NewServeMux() | ||
opts := []grpc.DialOption{grpc.WithInsecure()} | ||
err := health.RegisterHealthHandlerFromEndpoint(ctx, mux, endpoint, opts) | ||
{{- range .Services}} | ||
err = {{ .Name }}.Register{{ .Name | Title }}HandlerFromEndpoint(ctx, mux, endpoint, opts) | ||
{{- end}} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return http.ListenAndServe(listening, mux) | ||
} | ||
|
||
func main() { | ||
endpoint := "0.0.0.0:{{ .Network.Grpc.Port }}" | ||
listening := "0.0.0.0:{{ .Network.Http.Port }}" | ||
log.Printf("Starting http grpc gateway server on %v...", listening) | ||
|
||
if err := run(endpoint, listening); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters