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

refactor: dockerization #155

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
*~
.git/
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
FROM znly/protoc:0.3.0
# builder
FROM golang:1.14-alpine as builder
RUN apk --no-cache add make git go rsync libc-dev
RUN go get -u golang.org/x/tools/cmd/goimports
RUN go get -u github.com/gobuffalo/packr/v2/packr2
COPY . /go/src/moul.io/protoc-gen-gotemplate
WORKDIR /go/src/moul.io/protoc-gen-gotemplate
RUN packr2
RUN go install -a -tags netgo -ldflags '-w -extldflags "-static"' . ./cmd/web-editor
RUN ls -la /go/bin

ENV GOPATH=/go \
PATH=/go/bin:${PATH}

# Install deps and common tools
RUN apk --update add make git go rsync libc-dev \
&& go get -u golang.org/x/tools/cmd/goimports

# Install protoc-gen-gotemplate
COPY . /go/src/moul.io/protoc-gen-gotemplate
WORKDIR /go/src/moul.io/protoc-gen-gotemplate
RUN git remote set-url origin https://github.com/moul/protoc-gen-gotemplate
RUN go install . ./cmd/web-editor
# runtime
FROM znly/protoc:0.3.0
COPY --from=builder /go/bin/web-editor /go/bin/
COPY --from=builder /go/bin/protoc-gen-gotemplate /go/bin/
ENV PATH=$PATH:/go/bin
EXPOSE 8080
ENTRYPOINT []
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GOPKG ?= moul.io/protoc-gen-gotemplate
DOCKER_IMAGE ?= moul/golang-repo-template
DOCKER_IMAGE ?= moul/protoc-gen-gotemplate
GOBINS ?= . ./cmd/web-editor
GOLIBS ?= .

Expand Down
5 changes: 4 additions & 1 deletion cmd/web-editor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"

packr "github.com/gobuffalo/packr/v2"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
Expand Down Expand Up @@ -101,7 +102,9 @@ func returnError(w http.ResponseWriter, err error) {
func main() {
r := mux.NewRouter()

r.Handle("/", http.FileServer(http.Dir("static")))
box := packr.New("static", "./static")

r.Handle("/", http.FileServer(box))
r.HandleFunc("/generate", generate)
addr := fmt.Sprintf(":%s", os.Getenv("PORT"))
if addr == ":" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/web-editor/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<style>.ace_editor { height: 80%; }</style>
<style>.ace_editor { height: 80%; min-height: 500px; }</style>
</head>
<body ng-app="pggt">
<div class="container-fluid" ng-controller="PggtCtrl">
Expand Down
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions go.sum

Large diffs are not rendered by default.