added Dockerfile
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# Binaries
|
||||
mdhost
|
||||
|
||||
# IDE
|
||||
.idea
|
||||
.vscode
|
||||
*.swp
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Data
|
||||
posts/
|
||||
data/
|
||||
|
||||
# Test
|
||||
*_test.go
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
FROM golang:1.26-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build statically
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags='-w -s' -o mdhost .
|
||||
|
||||
# Final scratch image
|
||||
FROM scratch
|
||||
|
||||
# Copy binary from builder
|
||||
COPY --from=builder /app/mdhost /mdhost
|
||||
|
||||
# Run the application - directories will be bind-mounted from host
|
||||
CMD ["/mdhost"]
|
||||
@@ -117,6 +117,59 @@ The creation timestamp is stored in the file's `CreatedAt` field and persists ac
|
||||
| GET | `/logout` | Clear session |
|
||||
| GET | `/claim` | Claim anonymous files (auto-handled in register) |
|
||||
|
||||
## Docker
|
||||
|
||||
### Build the Image
|
||||
|
||||
```bash
|
||||
docker build -t mdhost .
|
||||
```
|
||||
|
||||
### Run with Docker
|
||||
|
||||
The `data` and `posts` directories are designed to be bind-mounted from the host filesystem for persistence:
|
||||
|
||||
```bash
|
||||
# Create host directories for persistent data
|
||||
mkdir -p ~/mdhost-data ~/mdhost-posts
|
||||
|
||||
# Run the container with bind mounts
|
||||
docker run -d \
|
||||
--name mdhost \
|
||||
-p 8080:8080 \
|
||||
-v ~/mdhost-posts:/posts \
|
||||
-v ~/mdhost-data:/data \
|
||||
mdhost
|
||||
```
|
||||
|
||||
The application will be available at `http://localhost:8080`.
|
||||
|
||||
- **`/posts`** - Markdown files are stored here (bind-mounted from host)
|
||||
- **`/data`** - Metadata (users, sessions, file metadata) is stored here as `data.json` (bind-mounted from host)
|
||||
|
||||
### Docker Compose
|
||||
|
||||
Create a `docker-compose.yml`:
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
services:
|
||||
mdhost:
|
||||
build: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
volumes:
|
||||
- ./posts:/posts
|
||||
- ./data:/data
|
||||
restart: unless-stopped
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Go 1.26+
|
||||
|
||||
Reference in New Issue
Block a user