chore: update dockerfile, readme, etc

This commit is contained in:
Khairul Hidayat 2024-08-18 06:33:58 +07:00
parent b554cb4dbf
commit 6ad70370d1
11 changed files with 82 additions and 29 deletions

View File

@ -2,4 +2,5 @@ node_modules
.git .git
.gitignore .gitignore
*.md *.md
.env*
dist dist

View File

@ -1,34 +1,28 @@
FROM node:20-slim AS base FROM node:20-slim AS frontend
WORKDIR /app WORKDIR /app
ENV PNPM_HOME="/pnpm" ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH" ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable RUN corepack enable
FROM base AS frontend
COPY package.json pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY . . COPY . .
RUN pnpm run build RUN pnpm run build
FROM base AS backend-deps FROM golang:1.22.5 AS backend
COPY backend/package.json backend/pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install -prod --frozen-lockfile
COPY backend .
FROM oven/bun:alpine AS backend
WORKDIR /app
COPY --from=backend-deps /app .
RUN bun run build
FROM oven/bun:alpine
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production COPY backend/go.mod backend/go.sum ./
ENV DIST_ROOT=./dist RUN go mod download
COPY --from=frontend /app/dist /app/dist COPY backend/ ./
COPY --from=backend /app/dist /app COPY --from=frontend /app/dist ./ui
RUN make
ENTRYPOINT [ "bun" , "run", "main.js" ] FROM scratch
COPY --from=backend /app/main /bin/main
CMD [ "/bin/main" ]

View File

@ -13,7 +13,7 @@ The Garage Web UI is available as a Docker image. You can install it using the c
### Docker CLI ### Docker CLI
```sh ```sh
$ docker run -p 3909:3909 -v ./garage.toml:/etc/garage.toml --restart unless-stopped --name garage-webui khairul169/garage-webui:latest $ docker run -p 3909:3909 -v ./garage.toml:/etc/garage.toml:ro --restart unless-stopped --name garage-webui khairul169/garage-webui:latest
``` ```
### Docker Compose ### Docker Compose
@ -37,7 +37,7 @@ services:
container_name: garage-webui container_name: garage-webui
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./garage.toml:/etc/garage.toml - ./garage.toml:/etc/garage.toml:ro
ports: ports:
- 3909:3909 - 3909:3909
``` ```
@ -89,7 +89,7 @@ Once your instance of Garage Web UI is started, you can open the web UI at http:
## Development ## Development
This project is bootstrapped using TypeScript, Bun, React, and Hono. If you want to build it yourself or add additional features, follow these steps: This project is bootstrapped using TypeScript & React for the UI, and Go for backend. If you want to build it yourself or add additional features, follow these steps:
### Setup ### Setup

51
backend/.air.toml Normal file
View File

@ -0,0 +1,51 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[proxy]
app_port = 0
enabled = false
proxy_port = 0
[screen]
clear_on_rebuild = false
keep_scroll = true

View File

@ -1,6 +1,6 @@
build: build:
go build -o main -tags="prod" main.go CGO_ENABLED=0 go build -o main -tags="prod" main.go
run: run:
go run main.go go run main.go

View File

@ -2,4 +2,7 @@ module khairul169/garage-webui
go 1.22.5 go 1.22.5
require github.com/pelletier/go-toml/v2 v2.2.2 // indirect require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
)

View File

@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

View File

@ -7,9 +7,13 @@ import (
"khairul169/garage-webui/utils" "khairul169/garage-webui/utils"
"log" "log"
"net/http" "net/http"
"github.com/joho/godotenv"
) )
func main() { func main() {
godotenv.Load()
if err := utils.Garage.LoadConfig(); err != nil { if err := utils.Garage.LoadConfig(); err != nil {
log.Fatal("Failed to load config! ", err) log.Fatal("Failed to load config! ", err)
} }
@ -21,7 +25,7 @@ func main() {
ui.ServeUI() ui.ServeUI()
host := utils.GetEnv("HOST", "0.0.0.0") host := utils.GetEnv("HOST", "0.0.0.0")
port := utils.GetEnv("PORT", "3908") port := utils.GetEnv("PORT", "3909")
addr := fmt.Sprintf("%s:%s", host, port) addr := fmt.Sprintf("%s:%s", host, port)
log.Printf("Starting server on http://%s", addr) log.Printf("Starting server on http://%s", addr)

View File

@ -21,7 +21,7 @@ type garage struct {
var Garage = &garage{} var Garage = &garage{}
func (g *garage) LoadConfig() error { func (g *garage) LoadConfig() error {
path := GetEnv("CONFIG_PATH", "/etc/garage/garage.toml") path := GetEnv("CONFIG_PATH", "/etc/garage.toml")
data, err := os.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {

View File

@ -13,9 +13,7 @@ services:
image: khairul169/garage-webui:latest image: khairul169/garage-webui:latest
container_name: garage-webui container_name: garage-webui
restart: unless-stopped restart: unless-stopped
environment:
- CONFIG_PATH=/etc/garage.toml
volumes: volumes:
- ./garage.toml:/etc/garage.toml - ./garage.toml:/etc/garage.toml:ro
ports: ports:
- 3909:3909 - 3909:3909

View File

@ -8,7 +8,7 @@
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview", "preview": "vite preview",
"dev:server": "cd backend && npm run dev", "dev:server": "cd backend && air",
"dev": "concurrently \"npm run dev:client\" \"npm run dev:server\"" "dev": "concurrently \"npm run dev:client\" \"npm run dev:server\""
}, },
"dependencies": { "dependencies": {