Skip to content

Commit

Permalink
build(docker): modify Dockerfile for embeding static files into go bi…
Browse files Browse the repository at this point in the history
…nary.
  • Loading branch information
genshen committed Nov 17, 2018
1 parent 005603b commit fe554c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 23 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# build method 1: run `go mod vendor` on host to generate vendor dir,
# and build with `docker build -t genshen/ssh-web-console .`
# build method 2: just run `docker build --build-arg GOMODULE=on -t genshen/ssh-web-console .`
# and build with `docker build --rm -t genshen/ssh-web-console .`
# build method 2: just run `docker build --rm --build-arg GOMODULE=on -t genshen/ssh-web-console .`

FROM golang:1.11.2-alpine AS builder

# set to 'on' if using go module
ARG GOMODULE=auto

COPY ./ /go/src/github.com/genshen/ssh-web-console/

RUN cd ./src/github.com/genshen/ssh-web-console/ \
&& export GO111MODULE=${GOMODULE} \
&& go build \
&& go install


# compile frontend code
# build frontend code
FROM node:10-alpine AS frontend-builder

ARG FRONTEND_REP="https://github.com/genshen/webConsole.git"
Expand All @@ -30,20 +18,37 @@ RUN apk add --no-cache git \
&& yarn build


FROM golang:1.11.2-alpine AS builder

# set to 'on' if using go module
ARG GOMODULE=auto
ARG STATIC_DIR=auto

RUN apk add --no-cache git \
&& go get -u github.com/rakyll/statik

COPY ./ /go/src/github.com/genshen/ssh-web-console/
COPY --from=frontend-builder /web-console/dist /go/src/github.com/genshen/ssh-web-console/${STATIC_DIR}/

RUN cd ./src/github.com/genshen/ssh-web-console/ \
&& statik -src=${STATIC_DIR} \
&& export GO111MODULE=${GOMODULE} \
&& go build \
&& go install

## copy binary
FROM alpine:latest
ARG USRR="web"
ARG HOME="/home/web"

RUN adduser -D ${USRR}

COPY --from=builder --chown=web /go/bin/ssh-web-console ${HOME}/ssh-web-console
COPY --from=frontend-builder --chown=web /web-console/dist/static ${HOME}/static/
COPY --from=frontend-builder --chown=web /web-console/dist/index.html ${HOME}/views/

WORKDIR ${HOME}
USER ${USER}

VOLUME ["${HOME}/conf"]
VOLUME ["${HOME}/conf", "${HOME}/views"]

# fixme still using root user.
CMD ["./ssh-web-console"]
2 changes: 0 additions & 2 deletions src/controllers/message_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/genshen/ssh-web-console/src/models"
"golang.org/x/crypto/ssh"
"io"
"log"
)

func DispatchMessage(sshSession *ssh.Session, messageType int, wsData []byte, wc io.WriteCloser) error {
Expand All @@ -27,7 +26,6 @@ func DispatchMessage(sshSession *ssh.Session, messageType int, wsData []byte, wc
if err := json.Unmarshal(socketData, &resize); err != nil {
return nil // skip error
}
log.Println(resize)
sshSession.WindowChange(resize.Rows, resize.Cols)
case models.SSHWebSocketMessageTypeTerminal:
var message models.TerminalMessage
Expand Down

0 comments on commit fe554c5

Please sign in to comment.