Skip to content

Commit

Permalink
feat(server): edit docker envs to build Vue project
Browse files Browse the repository at this point in the history
* update Go file server to handle vue project
* delete old static files
* change vue-router mode to web history
  • Loading branch information
hbollon committed Jul 21, 2021
1 parent 37a1273 commit 56c81b8
Show file tree
Hide file tree
Showing 23 changed files with 12 additions and 1,573 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Expand Up @@ -3,10 +3,17 @@ WORKDIR /opt/build
COPY . .
RUN make build

FROM node:16.5-alpine3.14 as node-builder
WORKDIR /opt/build
COPY static/terraboard-vuejs ./terraboard-vuejs
WORKDIR /opt/build/terraboard-vuejs
RUN npm install
RUN npm run build

FROM scratch
WORKDIR /
COPY static /static
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /opt/build/terraboard /
COPY --from=node-builder /opt/build/terraboard-vuejs/dist /static
ENTRYPOINT ["/terraboard"]
CMD [""]
2 changes: 0 additions & 2 deletions docker-compose.yml
Expand Up @@ -18,8 +18,6 @@ services:
depends_on:
db:
condition: service_healthy
volumes:
- ./static:/static:ro
ports:
- "8080:8080"

Expand Down
25 changes: 2 additions & 23 deletions main.go
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"

Expand All @@ -18,23 +17,6 @@ import (
log "github.com/sirupsen/logrus"
)

// idx serves index.html, always,
// so as to let AngularJS manage the app routing.
// The <base> HTML tag is edited on the fly
// to reflect the proper base URL
func idx(w http.ResponseWriter, _ *http.Request) {
idx, err := ioutil.ReadFile("static/index.html")
if err != nil {
log.Errorf("Failed to open index.html: %v", err)
// TODO: Return error page
}
idxStr := string(idx)
idxStr = util.ReplaceBasePath(idxStr, "base href=\"/\"", "base href=\"%s\"")
if _, err := io.WriteString(w, idxStr); err != nil {
log.Error(err.Error())
}
}

// Pass the DB to API handlers
// This takes a callback and returns a HandlerFunc
// which calls the callback with the DB
Expand Down Expand Up @@ -183,12 +165,9 @@ func main() {
defer database.Close()

mux := http.NewServeMux()
// Index is a wildcard for all paths
mux.HandleFunc(util.GetFullPath(""), idx)

// Serve static files (CSS, JS, images) from dir
// Serve static files generated from the VueJS project by the Dockerfile
staticFs := http.FileServer(http.Dir("static"))
mux.Handle(util.GetFullPath("static/"), http.StripPrefix(util.GetFullPath("static"), staticFs))
mux.Handle("/", http.StripPrefix("/", staticFs))

// Handle API points
mux.HandleFunc(util.GetFullPath("api/version"), getVersion)
Expand Down
Binary file removed static/c2c-logo.png
Binary file not shown.
11 changes: 0 additions & 11 deletions static/footer.html

This file was deleted.

41 changes: 0 additions & 41 deletions static/index.html

This file was deleted.

55 changes: 0 additions & 55 deletions static/lineage.html

This file was deleted.

Binary file removed static/logo.png
Binary file not shown.
62 changes: 0 additions & 62 deletions static/main.html

This file was deleted.

38 changes: 0 additions & 38 deletions static/navbar.html

This file was deleted.

93 changes: 0 additions & 93 deletions static/search.html

This file was deleted.

0 comments on commit 56c81b8

Please sign in to comment.