Added Dockerfile for building server images
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
# NodeJS
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Server
|
||||||
|
server
|
||||||
|
|
||||||
|
# Local Files
|
||||||
|
.env
|
||||||
|
*.local*
|
||||||
|
|
||||||
|
# Itself
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
+18
@@ -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"]
|
||||||
@@ -48,8 +48,9 @@ func main() {
|
|||||||
// Setting up dynamic "single page application" routes (all routes these to the same html file)
|
// Setting up dynamic "single page application" routes (all routes these to the same html file)
|
||||||
for _, route := range []string{
|
for _, route := range []string{
|
||||||
"/",
|
"/",
|
||||||
"/api-keys",
|
"/login",
|
||||||
"/admin",
|
"/admin",
|
||||||
|
"/api-keys",
|
||||||
"/buckets",
|
"/buckets",
|
||||||
"/buckets/:bucket",
|
"/buckets/:bucket",
|
||||||
} {
|
} {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package monitor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -44,6 +45,8 @@ func (s *Service) LoadScripts() error {
|
|||||||
func (s *Service) GetLastOutput(command string) (string, error) {
|
func (s *Service) GetLastOutput(command string) (string, error) {
|
||||||
args := strings.Fields(command)
|
args := strings.Fields(command)
|
||||||
|
|
||||||
|
log.Printf("Running script %q with args %v", args[0], args[1:])
|
||||||
|
|
||||||
scriptPath := s.scriptPaths[args[0]]
|
scriptPath := s.scriptPaths[args[0]]
|
||||||
|
|
||||||
cmd := exec.Command(scriptPath, args[1:]...)
|
cmd := exec.Command(scriptPath, args[1:]...)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package routes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"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/monitor/status?script=SCRIPT_NAME" where SCRIPT_NAME is the name of a file inside "./scripts"
|
||||||
api.Get("/status", func(c *fiber.Ctx) error {
|
api.Get("/status", func(c *fiber.Ctx) error {
|
||||||
if qScript := c.Query("script"); qScript != "" {
|
if qScript := c.Query("script"); qScript != "" {
|
||||||
log.Printf("Script %q", qScript)
|
|
||||||
|
|
||||||
output, err := r.Monitor.GetLastOutput(qScript)
|
output, err := r.Monitor.GetLastOutput(qScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user