Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Aug 12, 2019
1 parent 5181dd6 commit bb671e6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
Makefile
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang:1.12rc1-alpine3.9

RUN apk --no-cache add gcc musl-dev ca-certificates
COPY . /go/src/github.com/streamhut/streamhut
WORKDIR /go/src/github.com/streamhut/streamhut
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o streamhut cmd/streamhut/main.go

CMD ["./streamhut", "server"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ release:
.PHONY: release/dry
release/dry:
goreleaser release --rm-dist --skip-publish

build/docker:
docker build -t streamhut/streamhut .

push/docker:
docker push streamhut/streamhut:latest

start/docker:
docker run -e PORT=8080 -e NET_PORT=1337 -p 8080:8080 -p 1337:1337 -p 8765:8765 streamhut/streamhut:latest

start/docker/prod:
docker run -e HOST_URL='https://stream.ht' -e NET_PORT=1337 -e PORT=8080 -p 8080:8080 -p 1337:1337 -p 8765:8765 --restart unless-stopped streamhut/streamhut:latest

migrate:
(cd migration && make migrate)

rollback:
(cd migration && make rollback)

migrate/new:
(cd migration && rake db:new_migration name=$(NAME))
12 changes: 9 additions & 3 deletions cmd/streamhut/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
lol "github.com/kris-nova/lolgopher"
log "github.com/sirupsen/logrus"
cobra "github.com/spf13/cobra"
"github.com/streamhut/streamhut/cmd/streamhut/asciiart"
"github.com/streamhut/streamhut/pkg/asciiart"
"github.com/streamhut/streamhut/pkg/client"
"github.com/streamhut/streamhut/pkg/db"
"github.com/streamhut/streamhut/pkg/db/sqlite3db"
Expand Down Expand Up @@ -53,6 +53,8 @@ For more info, visit: https://github.com/streamhut/streamhut`,
var dbPath string
var dbType string
var shareBaseURL string
var webTarURL string
var webDir string

serverCmd := &cobra.Command{
Use: "server",
Expand Down Expand Up @@ -93,8 +95,10 @@ For more info, visit: https://github.com/streamhut/streamhut`,
}()

server := httpserver.NewServer(&httpserver.Config{
Port: httpPort,
WS: ws,
Port: httpPort,
WS: ws,
WebTarURL: webTarURL,
WebDir: webDir,
})

handleExit(func() {
Expand All @@ -116,6 +120,8 @@ For more info, visit: https://github.com/streamhut/streamhut`,
serverCmd.Flags().StringVarP(&dbPath, "db-path", "", "./data/sqlite3.db", "Sqlite3 database path")
serverCmd.Flags().StringVarP(&dbType, "db-type", "", "sqlite3", "Database type: Options are \"sqlite\"")
serverCmd.Flags().StringVarP(&shareBaseURL, "share-base-url", "", "", "Share base URL. Example: \"https://stream.ht/\"")
serverCmd.Flags().StringVarP(&webTarURL, "web-tar-url", "", httpserver.DefaultWebTarURL, "Web app tarball url to download")
serverCmd.Flags().StringVarP(&webDir, "web-dir", "", httpserver.DefaultWebDir, "Web app directory")

var host string
var port uint
Expand Down
File renamed without changes.
29 changes: 23 additions & 6 deletions pkg/httpserver/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,45 @@ import (
"github.com/streamhut/streamhut/pkg/wsserver"
)

var webZip = "https://github.com/streamhut/web/releases/download/v0.0.1/streamhut-web.tar.gz"
var staticDirPath = "~/.streamhut/web"
// DefaultWebTarURL is the default web build tarball url to download
var DefaultWebTarURL = "https://github.com/streamhut/web/releases/download/v0.0.1/streamhut-web.tar.gz"

// DefaultWebDir is the default web directory
var DefaultWebDir = "~/.streamhut/web"

// Config ...
type Config struct {
Port uint
WS *wsserver.WS
Port uint
WS *wsserver.WS
WebTarURL string
WebDir string
}

// Server ...
type Server struct {
port uint
ws *wsserver.WS
staticDirPath string
webTarURL string
}

// NewServer ...
func NewServer(config *Config) *Server {
webTarURL := DefaultWebTarURL
if config.WebTarURL != "" {
webTarURL = config.WebTarURL
}

webDir := DefaultWebDir
if config.WebDir != "" {
webDir = config.WebDir
}

return &Server{
port: config.Port,
ws: config.WS,
staticDirPath: util.NormalizePath(staticDirPath),
webTarURL: webTarURL,
staticDirPath: util.NormalizePath(webDir),
}
}

Expand Down Expand Up @@ -115,7 +132,7 @@ func (s *Server) downloadWebBuildIfNotExists() error {
tempFilePath := tempFile.Name()
defer os.Remove(tempFilePath)

if err := util.DownloadFile(webZip, tempFilePath); err != nil {
if err := util.DownloadFile(s.webTarURL, tempFilePath); err != nil {
return err
}

Expand Down

0 comments on commit bb671e6

Please sign in to comment.