Compare commits

...

5 Commits

Author SHA1 Message Date
fcfa43cca3 fix(frontend): correct build output path for Docker compatibility
All checks were successful
continuous-integration/drone/push Build is passing
Change build script to output to public/dist instead of ../backend/web/static/dist.
The Dockerfile copies from frontend/public/, so the previous path caused builds
to output to a non-existent directory, resulting in stale files being deployed.

Also add mkdir -p to dev script for robustness.
2026-02-22 20:48:39 -05:00
eaa8a58d4f fix(build): add placeholder for embed static directory
All checks were successful
continuous-integration/drone/push Build is passing
Add .gitkeep to backend/web/static/ to ensure directory exists
for Go embed directive. The static/* pattern requires at least
one file to exist at build time, otherwise compilation fails.

Update .gitignore to allow .gitkeep while ignoring other contents.
2026-02-22 20:38:07 -05:00
59de41f827 feat(build): embed static assets into Go binary
Some checks failed
continuous-integration/drone/push Build is failing
Embed frontend build output directly into Go binary using //go:embed.
This removes runtime dependency on ../frontend/public/ path and
simplifies Docker builds by serving assets from embedded filesystem.

- Add backend/web/embed.go with embed.FS directive
- Update server to serve from embedded static assets
- Update Makefile to copy frontend build to web/static/
- Update Dockerfile for simplified multi-stage build
- Update frontend package.json output paths
- Remove custom 'oc' command from flake.nix dev shell
2026-02-22 20:36:03 -05:00
93b5c3f110 refactor(docker): use environment variables instead of hardcoded CMD args
All checks were successful
continuous-integration/drone/push Build is passing
Replace hardcoded CMD arguments with ENV directives:
- AETHERA_LISTEN=0.0.0.0
- AETHERA_PORT=8080
- AETHERA_DATA_DIR=/app/data

This allows runtime configuration via docker run -e or compose files.
2026-02-20 22:36:23 -05:00
0dc3add8ff feat(backend): add environment variable configuration support
Add AETHERA_ prefixed env vars for server configuration:
- AETHERA_DATA_DIR: data directory path
- AETHERA_LISTEN: listen address
- AETHERA_PORT: listen port

Env vars take precedence over defaults but CLI flags override both.
2026-02-20 22:35:13 -05:00
10 changed files with 61 additions and 68 deletions

View File

@@ -1,68 +1,30 @@
# Multi-stage build for Aethera
# Stage 1: Build frontend assets
# Step 1: Build Frontend
FROM oven/bun:1 AS frontend-builder
WORKDIR /app/frontend
# Copy frontend package files
COPY frontend/package.json frontend/bun.lock ./
# Install dependencies
RUN bun install --frozen-lockfile
# Copy frontend source code
COPY frontend/ ./
# Build frontend assets
RUN bun run build
# Stage 2: Build Go binary
# Stage 2: Build Backend
FROM golang:1.25-alpine AS backend-builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git
# Copy go mod files
COPY backend/go.mod backend/go.sum ./
# Download Go dependencies
RUN go mod download
# Copy backend source code
COPY backend/ ./
COPY --from=frontend-builder /app/frontend/public/ ./web/static/
RUN go build -ldflags="-w -s" -o aethera ./cmd
# Copy frontend assets from previous stage
COPY --from=frontend-builder /app/frontend/public/dist ./public/dist
COPY --from=frontend-builder /app/frontend/public/index.html ./public/
COPY --from=frontend-builder /app/frontend/public/pages ./public/pages
# Build the Go binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o aethera ./cmd
# Stage 3: Create minimal runtime image
# Stage 3: Minimal Runtime
FROM alpine:3.21
# Install ca-certificates for HTTPS calls
RUN apk add --no-cache ca-certificates
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=backend-builder /app/aethera .
# Copy static assets
COPY --from=backend-builder /app/public ./public
# Create data directory
RUN mkdir -p /app/data
# Expose the default port
EXPOSE 8080
# Set the entrypoint
ENV AETHERA_LISTEN=0.0.0.0
ENV AETHERA_PORT=8080
ENV AETHERA_DATA_DIR=/app/data
ENTRYPOINT ["./aethera"]
# Default command with recommended production settings
CMD ["--listen", "0.0.0.0", "--port", "8080", "--data-dir", "/app/data"]

View File

@@ -4,6 +4,9 @@ all: frontend backend
frontend:
cd frontend && bun run build
mkdir -p backend/web/static
cp frontend/public/index.html backend/web/static/ 2>/dev/null || true
cp -r frontend/public/pages backend/web/static/ 2>/dev/null || true
backend:
cd backend && go build -o ./dist/aethera ./cmd
@@ -11,6 +14,7 @@ backend:
clean:
rm -rf frontend/public/dist
rm -rf backend/dist
rm -rf backend/web/static
dev:
cd backend && go run ./cmd --listen 0.0.0.0 &

2
backend/.gitignore vendored
View File

@@ -1 +1,3 @@
dist
web/static/*
!web/static/.gitkeep

View File

@@ -4,8 +4,11 @@ import (
"fmt"
"os"
"path"
"strconv"
)
const envPrefix = "AETHERA_"
type cliParams struct {
ListenAddr string
ListenPort int
@@ -13,6 +16,24 @@ type cliParams struct {
SettingsFile string
}
// getEnvOrDefault returns the value of an environment variable or a default value
func getEnvOrDefault(key, defaultValue string) string {
if value := os.Getenv(envPrefix + key); value != "" {
return value
}
return defaultValue
}
// getEnvIntOrDefault returns the integer value of an environment variable or a default value
func getEnvIntOrDefault(key string, defaultValue int) int {
if value := os.Getenv(envPrefix + key); value != "" {
if intVal, err := strconv.Atoi(value); err == nil {
return intVal
}
}
return defaultValue
}
func (p *cliParams) Validate() error {
// Ensure Generated Directories
imgDir := path.Join(p.DataDir, "generated/images")

View File

@@ -13,17 +13,17 @@ import (
var (
params = cliParams{
ListenAddr: "localhost",
ListenPort: 8080,
DataDir: "./data",
ListenAddr: getEnvOrDefault("LISTEN", "localhost"),
ListenPort: getEnvIntOrDefault("PORT", 8080),
DataDir: getEnvOrDefault("DATA_DIR", "./data"),
}
rootCmd = &cobra.Command{Use: "aethera"}
)
func init() {
rootCmd.PersistentFlags().StringVar(&params.DataDir, "data-dir", "data", "Directory to store generated images")
rootCmd.PersistentFlags().StringVar(&params.ListenAddr, "listen", "localhost", "Address to listen on")
rootCmd.PersistentFlags().IntVar(&params.ListenPort, "port", 8080, "Port to listen on")
rootCmd.PersistentFlags().StringVar(&params.DataDir, "data-dir", params.DataDir, "Directory to store generated images (env: AETHERA_DATA_DIR)")
rootCmd.PersistentFlags().StringVar(&params.ListenAddr, "listen", params.ListenAddr, "Address to listen on (env: AETHERA_LISTEN)")
rootCmd.PersistentFlags().IntVar(&params.ListenPort, "port", params.ListenPort, "Port to listen on (env: AETHERA_PORT)")
}
func main() {

View File

@@ -2,6 +2,7 @@ package server
import (
"fmt"
"io/fs"
"net/http"
"path"
"time"
@@ -9,6 +10,7 @@ import (
"github.com/sirupsen/logrus"
"reichard.io/aethera/internal/api"
"reichard.io/aethera/internal/store"
"reichard.io/aethera/web"
)
func StartServer(settingsStore store.Store, dataDir, listenAddress string, listenPort int) {
@@ -17,12 +19,13 @@ func StartServer(settingsStore store.Store, dataDir, listenAddress string, liste
// Create API Instance - use settingsStore as the unified store for both settings and chat
logger := logrus.New()
api := api.New(settingsStore, dataDir, logger)
feFS := http.FileServer(http.Dir("../frontend/public/"))
mux.Handle("GET /", feFS)
// Serve UI Pages
pagesFS := http.FileServer(http.Dir("../frontend/public/pages/"))
mux.Handle("GET /pages/", http.StripPrefix("/pages/", pagesFS))
// Serve embedded static assets
staticFS, err := fs.Sub(web.Assets, "static")
if err != nil {
logrus.Fatal("Failed to create static filesystem: ", err)
}
mux.Handle("GET /", http.FileServer(http.FS(staticFS)))
// Serve Generated Data
genFS := http.FileServer(http.Dir(path.Join(dataDir, "generated")))

6
backend/web/embed.go Normal file
View File

@@ -0,0 +1,6 @@
package web
import "embed"
//go:embed static/*
var Assets embed.FS

View File

View File

@@ -21,11 +21,6 @@
config.allowUnfree = true;
}
);
oc = pkgs.writeShellScriptBin "oc" ''
PRJ_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
cd "$PRJ_ROOT" && OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode
'';
in
{
devShells.default = pkgs.mkShell {
@@ -38,11 +33,11 @@
# Frontend
bun
watchman
tailwindcss_4
# Custom Commands
oc
];
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
'';
};
}
);

View File

@@ -2,8 +2,8 @@
"name": "aethera",
"private": true,
"scripts": {
"dev": "bun build src/main.ts --outdir public/dist --target browser --watch & bunx @tailwindcss/cli -i styles.css -o public/dist/styles.css --watch",
"build": "bun build src/main.ts --outdir public/dist --target browser && bunx @tailwindcss/cli -i styles.css -o public/dist/styles.css --minify",
"dev": "mkdir -p public/dist && bun build src/main.ts --outdir public/dist --target browser --watch & bunx tailwindcss -i styles.css -o public/dist/styles.css --watch",
"build": "bun build src/main.ts --outdir public/dist --target browser && bunx tailwindcss -i styles.css -o public/dist/styles.css --minify",
"lint": "eslint ./src/**"
},
"devDependencies": {