π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
feat: add Docker containerization and fix production deployment issues
Samuel BAGATTINcebcf7fa73c9
diff --git a/.dockerignore b/.dockerignorenew file mode 100644index 00000000..ef4f9d2e--- /dev/null+++ b/.dockerignore@@ -0,0 +1,90 @@+# Git+.git+.gitignore+.gitattributes++# Documentation+README.md+*.md+LICENSE+CONTRIBUTING.md+CODE_OF_CONDUCT.md++# Development files+.github/+.vscode/+.idea/++# Node.js+node_modules/+npm-debug.log*+yarn-debug.log*+yarn-error.log*+.npm+.yarn/++# Frontend development+frontend/node_modules/+frontend/.nuxt/+frontend/.output/+frontend/dist/+frontend/.env*++# Go+backend/vendor/+backend/*.exe+backend/*.exe~+backend/*.dll+backend/*.so+backend/*.dylib+backend/*.test+backend/*.out+backend/go.work++# Test files+**/test/+**/tests/+**/*.test.*+**/*_test.*++# Logs+logs/+*.log++# Runtime data+pids/+*.pid+*.seed+*.pid.lock++# Coverage directory used by tools like istanbul+coverage/+*.lcov++# Environment files+.env+.env.local+.env.development.local+.env.test.local+.env.production.local++# OS generated files+.DS_Store+.DS_Store?+._*+.Spotlight-V100+.Trashes+ehthumbs.db+Thumbs.db++# Temporary files+tmp/+temp/++# Docker+Dockerfile*+docker-compose*.yml+.dockerignore++# MinIO data (if running locally)+minio/\ No newline at end of filediff --git a/backend/app/database.go b/backend/app/database.goindex 7b4a1d25..2eb4a86f 100644--- a/backend/app/database.go+++ b/backend/app/database.go@@ -11,9 +11,22 @@ func DBConection(config Config, multiStatements bool) (conecction *sql.DB) {Driver := config.Database.DriverUser := os.Getenv("DATABASE_USER")Password := os.Getenv("DATABASE_PASSWORD")- Host := config.Database.Host- Port := fmt.Sprint(config.Database.Port)- Database := config.Database.Name++ // Use environment variables for host/port/database if set, otherwise fall back to config+ Host := os.Getenv("DATABASE_HOST")+ if Host == "" {+ Host = config.Database.Host+ }++ Port := os.Getenv("DATABASE_PORT")+ if Port == "" {+ Port = fmt.Sprint(config.Database.Port)+ }++ Database := os.Getenv("DATABASE_NAME")+ if Database == "" {+ Database = config.Database.Name+ }multiStatementsConfig := "?multiStatements=false"if multiStatements {diff --git a/backend/app/migrations.go b/backend/app/migrations.goindex a5b5fa88..d22166c3 100644--- a/backend/app/migrations.go+++ b/backend/app/migrations.go@@ -17,7 +17,19 @@ func Migrate(config *Config) {db := DBConection(*config, true) // Use multiStatements for migrationdefer db.Close()- driver, _ := mysql.WithInstance(db, &mysql.Config{})++ // Test the database connection+ if err := db.Ping(); err != nil {+ panic(fmt.Sprintf("failed to ping database: %v", err))+ }++ driver, err := mysql.WithInstance(db, &mysql.Config{+ MigrationsTable: "schema_migrations",+ })+ if err != nil {+ panic(fmt.Sprintf("failed to create mysql driver: %v", err))+ }+m, err := migrate.NewWithDatabaseInstance(fmt.Sprintf("file://%s/migrations", absPath),"mysql",@@ -26,6 +38,7 @@ func Migrate(config *Config) {if err != nil {panic(fmt.Sprintf("failed to create migrate instance: %v", err))}+ defer m.Close()if err := m.Up(); err != nil && err.Error() != "no change" {panic(fmt.Sprintf("failed to apply migrations: %v", err))diff --git a/backend/main.go b/backend/main.goindex c9ccfe33..c5625003 100644--- a/backend/main.go+++ b/backend/main.go@@ -10,5 +10,5 @@ func main() {fmt.Println("Starting server on port:", application.Config.Port)defer application.DB.Close()- server.Run("localhost:" + fmt.Sprintf("%d", application.Config.Port))+ server.Run(":" + fmt.Sprintf("%d", application.Config.Port))}diff --git a/docker-compose.yml b/docker-compose.ymlnew file mode 100644index 00000000..22a1f30b--- /dev/null+++ b/docker-compose.yml@@ -0,0 +1,119 @@+services:+ # MySQL Database+ mysql:+ image: mysql:8.0+ container_name: alexandrie-mysql+ restart: unless-stopped+ environment:+ MYSQL_ROOT_PASSWORD: rootpassword+ MYSQL_DATABASE: alexandrie+ MYSQL_USER: alexandrie+ MYSQL_PASSWORD: password+ volumes:+ - mysql_data:/var/lib/mysql+ ports:+ - "3306:3306"+ networks:+ - alexandrie-network+ healthcheck:+ test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]+ timeout: 10s+ retries: 5+ start_period: 30s++ # MinIO Object Storage+ minio:+ image: minio/minio:latest+ container_name: alexandrie-minio+ restart: unless-stopped+ environment:+ MINIO_ROOT_USER: minioadmin+ MINIO_ROOT_PASSWORD: minioadmin+ command: server /data --console-address ":9001"+ volumes:+ - minio_data:/data+ ports:+ - "9000:9000"+ - "9001:9001"+ networks:+ - alexandrie-network+ healthcheck:+ test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]+ interval: 30s+ timeout: 20s+ retries: 3++ # Alexandrie Backend+ backend:+ build:+ context: ./backend+ dockerfile: ../docker/backend/Dockerfile+ container_name: alexandrie-backend+ environment:+ # Database Configuration+ DATABASE_HOST: mysql+ DATABASE_PORT: 3306+ DATABASE_NAME: alexandrie+ DATABASE_USER: alexandrie+ DATABASE_PASSWORD: password++ # Application Configuration+ JWT_SECRET: your-secure-jwt-secret-key-change-this-in-production+ DOMAIN_CLIENT: http://localhost:8200+ COOKIE_DOMAIN: localhost++ # MinIO Configuration+ MINIO_ENDPOINT: minio:9000+ MINIO_ACCESSKEY: minioadmin+ MINIO_SECRETKEY: minioadmin+ MINIO_BUCKET: alexandrie++ # SMTP Configuration (optional)+ SMTP_HOST: ""+ SMTP_MAIL: ""+ SMTP_PASSWORD: ""++ # Port Configuration+ PORT: 8201+ CPWD: /app/+ CONFIG_CPWD: ""+ GIN_MODE: release+ ports:+ - "8201:8201"+ depends_on:+ mysql:+ condition: service_healthy+ minio:+ condition: service_healthy+ networks:+ - alexandrie-network++ # Alexandrie Frontend+ frontend:+ build:+ context: ./frontend+ dockerfile: ../docker/frontend/Dockerfile+ container_name: alexandrie-frontend+ restart: unless-stopped+ environment:+ PORT: 8200+ # Runtime configuration - builds with these values at startup+ VITE_BASE_API: http://localhost:8201+ VITE_BASE_CDN: http://localhost:9000/alexandrie+ NUXT_PUBLIC_BASE_URL: http://localhost:8200+ ports:+ - "8200:8200"+ depends_on:+ - backend+ networks:+ - alexandrie-network++networks:+ alexandrie-network:+ driver: bridge++volumes:+ mysql_data:+ driver: local+ minio_data:+ driver: local\ No newline at end of filediff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfilenew file mode 100644index 00000000..a451d008--- /dev/null+++ b/docker/backend/Dockerfile@@ -0,0 +1,56 @@+# Backend Dockerfile for Alexandrie+FROM golang:1.23-alpine AS builder++WORKDIR /app++# Copy go mod files+COPY go.mod go.sum ./++# Download dependencies+RUN go mod download++# Copy source code+COPY . .++# Build the application+RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o backend_app .++# Production stage+FROM alpine:latest++# Install required packages+RUN apk --no-cache add ca-certificates tzdata mysql-client netcat-openbsd wget++# Install migrate tool for database migrations - detect architecture+RUN ARCH=$(uname -m) && \+ case $ARCH in \+ x86_64) MIGRATE_ARCH="amd64" ;; \+ aarch64) MIGRATE_ARCH="arm64" ;; \+ *) echo "Unsupported architecture: $ARCH" && exit 1 ;; \+ esac && \+ wget -O- https://github.com/golang-migrate/migrate/releases/latest/download/migrate.linux-${MIGRATE_ARCH}.tar.gz | tar xvz && \+ mv migrate /usr/local/bin/migrate++# Create app user+RUN addgroup -g 1001 -S appgroup && \+ adduser -S appuser -G appgroup -u 1001++WORKDIR /app++# Copy built application+COPY --from=builder --chown=appuser:appgroup /app/backend_app ./+COPY --chown=appuser:appgroup config.toml ./+COPY --chown=appuser:appgroup migrations ./migrations/++# Switch to app user+USER appuser++# Expose port+EXPOSE 8201++# Health check+HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \+ CMD nc -z localhost 8201 || exit 1++# Default command+CMD ["./backend_app"]\ No newline at end of filediff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfilenew file mode 100644index 00000000..39181891--- /dev/null+++ b/docker/frontend/Dockerfile@@ -0,0 +1,57 @@+# Frontend Dockerfile for Alexandrie - Runtime build with build-time config+FROM node:20-alpine++# Install bun+RUN apk add --no-cache curl unzip bash && \+ curl -fsSL https://bun.sh/install | bash && \+ cp /root/.bun/bin/bun /usr/local/bin/bun && \+ chmod +x /usr/local/bin/bun++# Create app user+RUN addgroup -g 1001 -S appgroup && \+ adduser -S appuser -G appgroup -u 1001++WORKDIR /app++# Copy package files and install dependencies as root+COPY package.json bun.lock ./+RUN bun install++# Copy source code+COPY . .++# Create entrypoint script that builds with current environment variables+COPY <<EOF /app/entrypoint.sh+#!/bin/bash+echo "Building application with current environment variables..."+echo "API: \$VITE_BASE_API"+echo "CDN: \$VITE_BASE_CDN"+echo "URL: \$NUXT_PUBLIC_BASE_URL"+bun run build+echo "Starting Nitro server..."+exec bun .output/server/index.mjs+EOF++# Make script executable and change ownership to app user+RUN chmod +x /app/entrypoint.sh && \+ chown -R appuser:appgroup /app++# Switch to app user+USER appuser++# Expose port+EXPOSE 8200++# Health check+HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \+ CMD curl -f http://localhost:8200/ || exit 1++# Runtime environment variables - can be overridden at container startup+ENV NODE_ENV=production+ENV PORT=8200+ENV VITE_BASE_API=""+ENV VITE_BASE_CDN=""+ENV NUXT_PUBLIC_BASE_URL=""++# Use entrypoint script+ENTRYPOINT ["/app/entrypoint.sh"]\ No newline at end of filediff --git a/frontend/app/composables/TreeStructure.ts b/frontend/app/composables/TreeStructure.tsindex fe895a4b..b324090f 100644--- a/frontend/app/composables/TreeStructure.ts+++ b/frontend/app/composables/TreeStructure.ts@@ -41,12 +41,12 @@ export class TreeStructure {}public generateTree(): Item[] {- return this.items.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id || '') || (item.data.type === 'category' && item.data.role === 2)).map(root => this.buildTree(root));+ return this.items.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id || '') || (item.data.type === 'category' && item.data.role === 2)).map(root => this.buildTree(root, new Set()));}public getSubTreeById(id: string): Item | undefined {const root = this.getItem(id);if (!root) return undefined;- return this.buildTree(root);+ return this.buildTree(root, new Set());}public treeToArray(tree: Item[]): Item[] {const result: Item[] = [];@@ -62,11 +62,19 @@ export class TreeStructure {}// Generate sub tree- private buildTree(item: Item): Item {+ private buildTree(item: Item, visited: Set<string> = new Set()): Item {+ // Prevent infinite recursion by checking if we've already visited this item+ if (visited.has(item.id)) {+ return { ...item, childrens: [] };+ }++ visited.add(item.id);const children = this.childrenMap.get(item.id) || [];+ const newVisited = new Set(visited);+return {...item,- childrens: children.map(child => this.buildTree(child)),+ childrens: children.map(child => this.buildTree(child, newVisited)),};}}