Docker support

This commit is contained in:
2019-01-12 23:21:50 +01:00
parent b924cb73ff
commit 322fcc3979
3 changed files with 81 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
run: run:
${MAKE} -j2 backgroundrun backgroundts ${MAKE} -j2 backgroundrun backgroundts
build: build:
tsc res/static/res/typescript/lib/*.ts --outFile res/static/res/script/pixellib.js \ tsc res/static/res/typescript/lib/*.ts --outFile res/static/res/script/pixellib.js \
@@ -12,5 +12,13 @@ deps:
backgroundrun: backgroundrun:
go run main.go go run main.go
backgroundts: backgroundts:
tsc --watch --project res/static/res/typescript/home tsc --watch --project res/static/res/typescript/home
--project res/static/res/typescript/textupload --project res/static/res/typescript/textupload
docker:
go build -o docker/pixeldrain-web docker/main.go
chmod +x docker/pixeldrain-web
docker build --tag pixeldrain-web -f docker/Dockerfile .
rm docker/pixeldrain-web
.PHONY: docker

16
docker/Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM ubuntu
RUN mkdir -p \
/bin \
/opt/pixeldrain/res
COPY docker/pixeldrain-web /bin/pixeldrain-web
COPY res /opt/pixeldrain/res
EXPOSE 8081
ENV api_url_external="" \
api_url_internal="" \
debug_mode=""
ENTRYPOINT [ "/bin/pixeldrain-web" ]

55
docker/main.go Normal file
View File

@@ -0,0 +1,55 @@
package main
import (
"net/http"
"os"
"fornaxian.com/pixeldrain-web/init/conf"
"fornaxian.com/pixeldrain-web/webcontroller"
"github.com/Fornaxian/log"
"github.com/julienschmidt/httprouter"
)
// This is just a launcher for the web server. During testing the app would
// be directly embedded by another Go project. And when deployed it will run
// independently.
func main() {
log.Info("Starting web UI server in docker mode (PID %v)", os.Getpid())
var webconf = &conf.PixelWebConfig{
StaticResourceDir: "/opt/pixeldrain/res/static",
TemplateDir: "/opt/pixeldrain/res/template",
}
if webconf.APIURLExternal, _ = os.LookupEnv("api_url_external"); webconf.APIURLExternal == "" {
webconf.APIURLExternal = "/api"
}
if webconf.APIURLInternal, _ = os.LookupEnv("api_url_internal"); webconf.APIURLInternal == "" {
panic("internal API URL is required. Please set api_url_internal")
}
// Check debug mode. When debug mode is enabled debug logging will be
// enabled, templates will be parsed on every request and analytics tracking
// will be disabled
switch d, _ := os.LookupEnv("debug_mode"); d {
case "1", "yes", "y", "true":
webconf.DebugMode = true
log.SetLogLevel(log.LevelDebug)
default:
webconf.DebugMode = false
log.SetLogLevel(log.LevelInfo)
}
// Web path prefix
prefix, _ := os.LookupEnv("api_path_prefix")
// Init the http router
r := httprouter.New()
webcontroller.New(r, prefix, webconf)
err := http.ListenAndServe(":8081", r)
if err != nil {
log.Error("Can't listen and serve Pixeldrain Web: %v", err)
}
}