add docker build

This commit is contained in:
Maxi Quoß
2023-01-28 23:10:31 +01:00
parent 7d005aa9d0
commit b1d4257013
10 changed files with 65 additions and 11 deletions

12
.dockerignore Normal file
View File

@@ -0,0 +1,12 @@
.git
.gitignore
.dockerignore
Dockerfile
README.md
frontend/.svelte-kit
frontend/node_modules
frontend/build
backend/pb_data
backend/pb_public

5
.gitignore vendored
View File

@@ -192,10 +192,7 @@ package
# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,svelte,node
frontend/build
frontend/.svelte-kit
frontend/vite.config.js.timestamp-*
frontend/vite.config.ts.timestamp-*
build
backend/pb_data
backend/pb_public/*

22
Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
FROM node:19-alpine as frontend
COPY frontend /app
WORKDIR /app
RUN npm i &&\
npm run build
FROM golang:1.19-alpine as backend
COPY backend /app
WORKDIR /app
COPY --from=frontend /app/build pb_public
RUN apk update &&\
apk add gcc musl-dev &&\
go mod tidy &&\
go build -ldflags "-s -w" -o upsnap main.go
FROM alpine:3.17
WORKDIR /app
COPY --from=backend /app/upsnap .
RUN apk update &&\
apk add --no-cache nmap curl samba-common-tools &&\
rm -rf /var/cache/apk/*
CMD ["./upsnap", "serve", "--http", "0.0.0.0:8090"]

View File

@@ -1,9 +1,16 @@
package main
import (
"embed"
"github.com/labstack/echo/v5"
"github.com/seriousm4x/upsnap/backend/pb"
)
//go:embed all:pb_public
var distDir embed.FS
var distDirFS = echo.MustSubFS(distDir, "pb_public")
func main() {
pb.StartPocketBase()
pb.StartPocketBase(distDirFS)
}

View File

@@ -1,6 +1,7 @@
package pb
import (
"io/fs"
"log"
"net/http"
"os"
@@ -18,7 +19,7 @@ import (
var App *pocketbase.PocketBase
func StartPocketBase() {
func StartPocketBase(distDirFS fs.FS) {
App = pocketbase.New()
App.RootCmd.Short = "UpSnap CLI"
App.RootCmd.Version = "3.0.0b1"
@@ -31,7 +32,7 @@ func StartPocketBase() {
// event hooks
App.OnBeforeServe().Add(func(e *core.ServeEvent) error {
// set static website path
e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), true))
e.Router.GET("/*", apis.StaticDirectoryHandler(distDirFS, true))
// add wake route to api
e.Router.AddRoute(echo.Route{

11
docker-compose.yml Normal file
View File

@@ -0,0 +1,11 @@
version: "3"
services:
upsnap:
build: .
network_mode: host
command: ["./upsnap", "serve", "--http", "0.0.0.0:8090"]
healthcheck:
test: ["CMD", "curl", "-fs", "http://localhost:8090/api/health"]
interval: 1m
timeout: 10s
retries: 3

View File

@@ -341,7 +341,10 @@
<div class="callout callout-info mb-auto">
<h5>Optional:</h5>
<p class="m-0">(1) Same cron syntax as for ping interval.</p>
<p class="m-0">(2) Shell command to be executed. e.g.:</p>
<p class="m-0">
(2) Shell command to be executed. "net rpc", "sshpass" and "nmap" are available.
e.g.:
</p>
<ul>
<li>Windows: "net rpc shutdown -I 192.168.1.13 -U test%test"</li>
<li>

View File

@@ -1 +1,2 @@
export const prerender = true;
export const trailingSlash = 'always';

View File

@@ -1,5 +1,3 @@
export const prerender = true;
/** @type {import('./$types').PageLoad} */
export function load({ params }) {
return { params };

View File

@@ -9,7 +9,9 @@ const config = {
preprocess: preprocess(),
kit: {
adapter: adapter(),
adapter: adapter({
fallback: 'index.html'
}),
alias: {
'@components': path.resolve('./src/components'),
'@stores': path.resolve('./src/stores')