serve static assets from embeded filesystem. add build files for lazyos
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,5 +10,7 @@ node_modules/
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
package.json
|
package.json
|
||||||
|
|
||||||
|
build/survey
|
||||||
|
|
||||||
# Added by goreleaser init:
|
# Added by goreleaser init:
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -33,6 +33,10 @@ docker-run:
|
|||||||
docker-push:
|
docker-push:
|
||||||
@docker push telikz/lazypm:latest
|
@docker push telikz/lazypm:latest
|
||||||
|
|
||||||
|
build-os: build
|
||||||
|
@cp ./bin/survey ./build/survey
|
||||||
|
@docker build -t lazyos ./build
|
||||||
|
|
||||||
start:
|
start:
|
||||||
@go run ./cmd/survey start
|
@go run ./cmd/survey start
|
||||||
|
|
||||||
|
|||||||
7
build/Dockerfile
Normal file
7
build/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
FROM lscr.io/linuxserver/webtop:arch-kde
|
||||||
|
|
||||||
|
COPY survey /usr/local/bin/survey
|
||||||
|
RUN chmod +x /usr/local/bin/survey
|
||||||
|
|
||||||
|
COPY setup-desktop.sh /custom-cont-init.d/01-setup-desktop.sh
|
||||||
|
RUN chmod +x /custom-cont-init.d/01-setup-desktop.sh
|
||||||
1
build/README.md
Normal file
1
build/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# This describes the build process for lazyos
|
||||||
23
build/setup-desktop.sh
Normal file
23
build/setup-desktop.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# This script runs as root when the container starts
|
||||||
|
echo "**** Setting up custom desktop shortcuts ****"
|
||||||
|
|
||||||
|
# Ensure the Desktop folder exists for the default 'abc' user
|
||||||
|
mkdir -p /config/Desktop
|
||||||
|
|
||||||
|
cat <<EOF > /config/Desktop/MyGoApp.desktop
|
||||||
|
[Desktop Entry]
|
||||||
|
Version=1.0
|
||||||
|
Type=Application
|
||||||
|
Name=PM Survey
|
||||||
|
Comment=Launch my custom Go binary
|
||||||
|
Exec=/usr/local/bin/survey start
|
||||||
|
Icon=utilities-terminal
|
||||||
|
Terminal=true
|
||||||
|
Categories=Utility;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x /config/Desktop/MyGoApp.desktop
|
||||||
|
chown abc:abc /config/Desktop/MyGoApp.desktop
|
||||||
|
|
||||||
|
echo "**** Desktop setup complete ****"
|
||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ListTasksCmd = &cobra.Command{
|
var ListTasksCmd = &cobra.Command{
|
||||||
Use: "list-tasks",
|
Use: "tasks",
|
||||||
Aliases: []string{"ls-t"},
|
Aliases: []string{"t"},
|
||||||
Short: "List available tasks",
|
Short: "List available tasks",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
for i, name := range task.ListTasks() {
|
for i, name := range task.ListTasks() {
|
||||||
@@ -18,8 +18,8 @@ var ListTasksCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ListInterfacesCmd = &cobra.Command{
|
var ListInterfacesCmd = &cobra.Command{
|
||||||
Use: "list-interfaces",
|
Use: "interfaces",
|
||||||
Aliases: []string{"ls-i"},
|
Aliases: []string{"i"},
|
||||||
Short: "List available interfaces",
|
Short: "List available interfaces",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
for i, name := range task.ListInterfaces() {
|
for i, name := range task.ListInterfaces() {
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"io/fs"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -53,7 +56,18 @@ func (s *Server) RegisterRoutes(assets embed.FS) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleAssets(r chi.Router, assets embed.FS) {
|
func (s *Server) handleAssets(r chi.Router, assets embed.FS) {
|
||||||
fileServer := http.FileServer(http.Dir("pkg/web/assets"))
|
var fileServer http.Handler
|
||||||
|
|
||||||
|
if os.Getenv("DEV") == "True" {
|
||||||
|
log.Println("Running in development mode: serving assets from disk")
|
||||||
|
fileServer = http.FileServer(http.Dir("pkg/web/assets"))
|
||||||
|
} else {
|
||||||
|
subFS, err := fs.Sub(assets, "assets")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to create sub filesystem: %v", err)
|
||||||
|
}
|
||||||
|
fileServer = http.FileServer(http.FS(subFS))
|
||||||
|
}
|
||||||
|
|
||||||
r.Handle("/assets/*",
|
r.Handle("/assets/*",
|
||||||
http.StripPrefix("/assets/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.StripPrefix("/assets/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user