fix: improve volume mounts and dev setup

This commit is contained in:
pommee
2025-06-10 21:28:38 +02:00
committed by Hugo
parent 60c3ceb754
commit fc8536ff74
9 changed files with 92 additions and 34 deletions

View File

@@ -10,17 +10,19 @@ COPY installer.sh ./
RUN apk add --no-cache curl jq bash ca-certificates && \
adduser -D -s /bin/bash appuser && \
mkdir -p /app && \
./installer.sh $GOAWAY_VERSION && \
mv /root/.local/bin/goaway /home/appuser/goaway && \
chown -R appuser:appuser /home/appuser && \
mv /root/.local/bin/goaway /app/goaway && \
chown -R appuser:appuser /app && \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/* /root/.cache /root/.local installer.sh
WORKDIR /home/appuser
WORKDIR /app
COPY updater.sh start.sh ./
COPY updater.sh ./
RUN chown appuser:appuser updater.sh
EXPOSE ${DNS_PORT}/tcp ${DNS_PORT}/udp ${WEBSITE_PORT}/tcp
USER appuser
CMD ["./start.sh"]
ENTRYPOINT [ "./goaway" ]

39
Dockerfile.dev Normal file
View File

@@ -0,0 +1,39 @@
FROM golang:1.24-alpine AS builder
RUN apk add --no-cache git ca-certificates
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o goaway .
FROM alpine:3.22
ARG DNS_PORT=6121
ARG WEBSITE_PORT=8080
ENV DNS_PORT=${DNS_PORT} WEBSITE_PORT=${WEBSITE_PORT}
RUN apk add --no-cache bash ca-certificates && \
adduser -D -s /bin/bash appuser && \
mkdir -p /app && \
chown -R appuser:appuser /app && \
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
WORKDIR /app
COPY --from=builder /src/goaway ./goaway
RUN chown appuser:appuser goaway
COPY updater.sh ./
RUN chown appuser:appuser updater.sh
EXPOSE ${DNS_PORT}/tcp ${DNS_PORT}/udp ${WEBSITE_PORT}/tcp
USER appuser
ENTRYPOINT [ "./goaway" ]

View File

@@ -23,6 +23,9 @@ start: ; docker compose up -d
lint: ; pnpm -C client lint && golangci-lint run ./backend/...
format: ; npx prettier --write "client/**/*.{html,css,js,tsx}"
dev: build
docker compose -f docker-compose.dev.yml up -d
dev-website: ; pnpm -C client install && pnpm -C client dev
dev-server: ; mkdir client/dist ; touch client/dist/.fake ; air .

View File

@@ -7,6 +7,7 @@ import (
"goaway/backend/updater"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
@@ -40,7 +41,7 @@ func (api *API) handleServer(c *gin.Context) {
log.Error("%s", err)
}
dbSize, err := getDBSize()
dbSize, err := getDBSizeMB()
if err != nil {
log.Error("%s", err)
}
@@ -81,10 +82,16 @@ func getCPUTemperature() (float64, error) {
return temp / 1000, nil
}
func getDBSize() (float64, error) {
files := []string{"database.db", "database.db-wal", "database.db-shm"}
func getDBSizeMB() (float64, error) {
var totalSize int64
basePath := "data"
files := []string{
filepath.Join(basePath, "database.db"),
filepath.Join(basePath, "database.db-wal"),
filepath.Join(basePath, "database.db-shm"),
}
for _, filename := range files {
info, err := os.Stat(filename)
if err != nil {
@@ -98,7 +105,7 @@ func getDBSize() (float64, error) {
totalSize += info.Size()
}
return float64(totalSize) / (1024 * 1024), nil // Return size in MB
return float64(totalSize) / (1024 * 1024), nil
}
func (api *API) handleMetrics(c *gin.Context) {

View File

@@ -3,6 +3,8 @@ package database
import (
"database/sql"
"fmt"
"os"
"path/filepath"
"sync"
_ "modernc.org/sqlite"
@@ -14,7 +16,12 @@ type DatabaseManager struct {
}
func Initialize() (*DatabaseManager, error) {
db, err := sql.Open("sqlite", "database.db")
if err := os.MkdirAll("data", 0755); err != nil {
return nil, fmt.Errorf("failed to create data directory %s: %w", "data", err)
}
databasePath := filepath.Join("data", "database.db")
db, err := sql.Open("sqlite", databasePath)
if err != nil {
return nil, fmt.Errorf("failed to open database: %w", err)
}

View File

@@ -49,13 +49,13 @@ func LoadSettings() (Config, error) {
if err != nil {
return Config{}, fmt.Errorf("could not determine current directory: %w", err)
}
path = filepath.Join(path, "settings.yaml")
path = filepath.Join(path, "config", "settings.yaml")
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Info("Settings file not found, creating from defaults...")
config, err = createDefaultSettings(path)
if err != nil {
return Config{}, fmt.Errorf("failed to create default settings: %w", err)
return Config{}, err
}
}
@@ -121,7 +121,7 @@ func (config *Config) Save() {
return
}
if err := os.WriteFile("./settings.yaml", data, 0644); err != nil {
if err := os.WriteFile("./config/settings.yaml", data, 0644); err != nil {
log.Error("Could not save settings %v", err)
}
}

17
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,17 @@
services:
goaway:
container_name: goaway
build:
context: .
dockerfile: Dockerfile.dev
restart: unless-stopped
environment:
- DNS_PORT=6121
- WEBSITE_PORT=8080
ports:
- "6121:6121/udp"
- "6121:6121/tcp"
- "8080:8080/tcp"
cap_add:
- NET_BIND_SERVICE
- NET_RAW

View File

@@ -2,9 +2,10 @@ services:
goaway:
image: pommee/goaway:latest
container_name: goaway
build: .
volumes:
- goaway_data:/home/appuser
restart: unless-stopped
# volumes:
# - /path/to/config:/app/config # Custom settings.yaml configuration
# - /path/to/data:/app/data # Database storage location
environment:
- DNS_PORT=${DNS_PORT:-53}
- WEBSITE_PORT=${WEBSITE_PORT:-8080}
@@ -15,7 +16,3 @@ services:
cap_add:
- NET_BIND_SERVICE
- NET_RAW
volumes:
goaway_data:
name: goaway_data

View File

@@ -1,14 +0,0 @@
#!/bin/bash
run_goaway() {
while true; do
echo "Starting goaway..."
/home/appuser/goaway --dns-port=${DNS_PORT} --webserver-port=${WEBSITE_PORT}
echo "goaway process exited with code $?. Restarting..."
done
}
trap 'echo "Received SIGTERM, shutting down..."; exit 0' SIGTERM
run_goaway &
wait