mirror of
https://github.com/dstotijn/hetty
synced 2024-11-10 06:04:19 +00:00
Add Dockerfile
This commit is contained in:
parent
8828a586a1
commit
28ae2b6efb
6 changed files with 46 additions and 20 deletions
4
.dockerignore
Normal file
4
.dockerignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
/admin/.env
|
||||
/admin/.next
|
||||
/admin/dist
|
||||
/admin/node_modules
|
29
Dockerfile
Normal file
29
Dockerfile
Normal file
|
@ -0,0 +1,29 @@
|
|||
ARG GO_VERSION=1.15
|
||||
ARG CGO_ENABLED=0
|
||||
ARG NODE_VERSION=14.11
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine AS go-builder
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY cmd ./cmd
|
||||
COPY pkg ./pkg
|
||||
COPY gqlgen.yml .
|
||||
RUN go build -o hetty ./cmd/
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS node-builder
|
||||
WORKDIR /app
|
||||
COPY admin/package.json admin/yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
COPY admin/ .
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
RUN yarn run export
|
||||
|
||||
FROM alpine:3.12
|
||||
WORKDIR /app
|
||||
COPY --from=go-builder /app/hetty .
|
||||
COPY --from=node-builder /app/dist admin
|
||||
|
||||
ENTRYPOINT ["./hetty"]
|
||||
|
||||
EXPOSE 80
|
2
admin/.gitignore
vendored
2
admin/.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
/node_modules
|
||||
/.next
|
||||
/build
|
||||
/dist
|
||||
|
||||
*.log*
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"export": "next build && next export"
|
||||
"export": "next build && next export -o dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.2.0",
|
||||
|
@ -22,7 +22,8 @@
|
|||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-monaco-editor": "^0.34.0",
|
||||
"react-syntax-highlighter": "^13.5.3"
|
||||
"react-syntax-highlighter": "^13.5.3",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.11.1",
|
||||
|
@ -30,7 +31,6 @@
|
|||
"eslint": "^7.9.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"prettier": "^2.1.2",
|
||||
"typescript": "^4.0.3"
|
||||
"prettier": "^2.1.2"
|
||||
}
|
||||
}
|
||||
|
|
19
cmd/main.go
19
cmd/main.go
|
@ -7,8 +7,6 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -25,7 +23,8 @@ var (
|
|||
caCertFile = flag.String("cert", "", "CA certificate file path")
|
||||
caKeyFile = flag.String("key", "", "CA private key file path")
|
||||
dev = flag.Bool("dev", false, "Run in development mode")
|
||||
adminPath = flag.String("adminPath", "", "File path to admin build")
|
||||
addr = flag.String("addr", ":80", "TCP address to listen on, in the form \"host:port\"")
|
||||
adminPath = flag.String("adminPath", "./admin/dist", "File path to admin build")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -53,15 +52,9 @@ func main() {
|
|||
|
||||
var adminHandler http.Handler
|
||||
|
||||
if *dev {
|
||||
adminURL, err := url.Parse("http://localhost:3000")
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] Invalid admin URL: %v", err)
|
||||
}
|
||||
adminHandler = httputil.NewSingleHostReverseProxy(adminURL)
|
||||
} else {
|
||||
if !*dev {
|
||||
if *adminPath == "" {
|
||||
log.Fatal("[FATAL] `adminPath` must be set")
|
||||
*adminPath = "./admin/dist"
|
||||
}
|
||||
adminHandler = http.FileServer(http.Dir(*adminPath))
|
||||
}
|
||||
|
@ -87,12 +80,12 @@ func main() {
|
|||
router.PathPrefix("").Handler(p)
|
||||
|
||||
s := &http.Server{
|
||||
Addr: ":8080",
|
||||
Addr: *addr,
|
||||
Handler: router,
|
||||
TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){}, // Disable HTTP/2
|
||||
}
|
||||
|
||||
log.Println("[INFO] Running server on :8080 ...")
|
||||
log.Printf("[INFO] Running server on %v ...", *addr)
|
||||
err = s.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("[FATAL] HTTP server closed: %v", err)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
@cert = $HOME/.ssh/hetty_cert.pem
|
||||
@key = $HOME/.ssh/hetty_key.pem
|
||||
@dev = false
|
||||
@adminPath = $PWD/admin/out
|
||||
@addr = :8080
|
||||
|
||||
**/*.go {
|
||||
daemon +sigterm: go run ./cmd \
|
||||
-cert=@cert \
|
||||
-key=@key \
|
||||
-dev=@dev \
|
||||
-adminPath=@adminPath
|
||||
-addr=@addr
|
||||
}
|
Loading…
Reference in a new issue