diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e7eb592 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# NodeJS +node_modules/ + +# Server +server + +# Local Files +.env +*.local* + +# Itself +Dockerfile +.dockerignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7ebead9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:18 AS frontend-builder +WORKDIR /frontend +COPY ./_frontend . +RUN npm install +RUN npm run build + +FROM golang:1.18-alpine AS server-builder +WORKDIR /server +COPY . . +RUN go build -buildvcs=false -o storage-server -v . + +FROM alpine:latest AS runner +WORKDIR /app +COPY --from=frontend-builder /frontend/dist ./_frontend/dist +COPY ./scripts ./scripts +COPY --from=server-builder /server/storage-server ./storage-server +EXPOSE 4000 +CMD ["./storage-server"] \ No newline at end of file diff --git a/main.go b/main.go index c92703a..3a87be1 100644 --- a/main.go +++ b/main.go @@ -48,8 +48,9 @@ func main() { // Setting up dynamic "single page application" routes (all routes these to the same html file) for _, route := range []string{ "/", - "/api-keys", + "/login", "/admin", + "/api-keys", "/buckets", "/buckets/:bucket", } { diff --git a/monitor/service.go b/monitor/service.go index 100f187..138e8c8 100644 --- a/monitor/service.go +++ b/monitor/service.go @@ -2,6 +2,7 @@ package monitor import ( "bytes" + "log" "os" "os/exec" "path" @@ -44,6 +45,8 @@ func (s *Service) LoadScripts() error { func (s *Service) GetLastOutput(command string) (string, error) { args := strings.Fields(command) + log.Printf("Running script %q with args %v", args[0], args[1:]) + scriptPath := s.scriptPaths[args[0]] cmd := exec.Command(scriptPath, args[1:]...) diff --git a/routes/monitor.go b/routes/monitor.go index a34ea81..de7e1ff 100644 --- a/routes/monitor.go +++ b/routes/monitor.go @@ -2,7 +2,6 @@ package routes import ( "fmt" - "log" "github.com/gofiber/fiber/v2" ) @@ -12,7 +11,6 @@ func (r *Router) ApiMonitor(api fiber.Router) { // - "/api/monitor/status?script=SCRIPT_NAME" where SCRIPT_NAME is the name of a file inside "./scripts" api.Get("/status", func(c *fiber.Ctx) error { if qScript := c.Query("script"); qScript != "" { - log.Printf("Script %q", qScript) output, err := r.Monitor.GetLastOutput(qScript) if err != nil {