feat: add Docker build
This commit is contained in:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@@ -0,0 +1,9 @@
|
||||
.git
|
||||
.gitignore
|
||||
.cursor
|
||||
*.md
|
||||
*.db
|
||||
*.bak
|
||||
spore-registry
|
||||
registry/*
|
||||
|
||||
42
Dockerfile
Normal file
42
Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
||||
# Build stage
|
||||
FROM golang:1.22-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies for CGO
|
||||
RUN apk add --no-cache gcc musl-dev sqlite-dev
|
||||
|
||||
# Copy go mod files
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
# Note: CGO_ENABLED=1 is required for sqlite3
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o spore-registry ./main.go
|
||||
|
||||
# Runtime stage
|
||||
FROM alpine:latest
|
||||
|
||||
# Install ca-certificates, sqlite runtime, and wget for health checks
|
||||
RUN apk --no-cache add ca-certificates sqlite wget
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the binary from builder
|
||||
COPY --from=builder /app/spore-registry .
|
||||
|
||||
# Create registry directory
|
||||
RUN mkdir -p /data/registry
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8080
|
||||
|
||||
# Set environment variable for registry path
|
||||
ENV REGISTRY_PATH=/data/registry
|
||||
|
||||
# Run the application
|
||||
CMD ["./spore-registry"]
|
||||
|
||||
21
Makefile
21
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: build run test clean
|
||||
.PHONY: build run test clean docker-build docker-run docker-push
|
||||
|
||||
# Build the application
|
||||
build:
|
||||
@@ -16,7 +16,6 @@ test:
|
||||
clean:
|
||||
rm -f spore-registry
|
||||
rm -rf registry/
|
||||
rm -f registry.db
|
||||
|
||||
# Run tests with coverage
|
||||
test-coverage:
|
||||
@@ -35,3 +34,21 @@ lint:
|
||||
deps:
|
||||
go mod download
|
||||
go mod tidy
|
||||
|
||||
# Docker variables
|
||||
DOCKER_REGISTRY ?=
|
||||
IMAGE_NAME = wirelos/spore-registry
|
||||
IMAGE_TAG ?= latest
|
||||
FULL_IMAGE_NAME = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/$(IMAGE_NAME),$(IMAGE_NAME)):$(IMAGE_TAG)
|
||||
|
||||
# Build Docker image
|
||||
docker-build:
|
||||
docker build -t $(FULL_IMAGE_NAME) .
|
||||
|
||||
# Run Docker container
|
||||
docker-run:
|
||||
docker run -p 8080:8080 -v registry-data:/data/registry --rm $(FULL_IMAGE_NAME)
|
||||
|
||||
# Push Docker image
|
||||
docker-push:
|
||||
docker push $(FULL_IMAGE_NAME)
|
||||
|
||||
@@ -57,7 +57,7 @@ The refactored code follows a clean architecture pattern with clear separation o
|
||||
## Environment Variables
|
||||
|
||||
- `PORT`: Server port (default: 3002)
|
||||
- `DB_PATH`: Database file path (default: ./registry.db)
|
||||
- `DB_PATH`: Database file path (default: ./registry/registry.db)
|
||||
- `REGISTRY_PATH`: Firmware storage directory (default: registry)
|
||||
- `MAX_UPLOAD_SIZE`: Maximum upload size in bytes (default: 32MB)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func LoadConfig() *Config {
|
||||
|
||||
dbPath := os.Getenv("DB_PATH")
|
||||
if dbPath == "" {
|
||||
dbPath = "./registry.db"
|
||||
dbPath = "./registry/registry.db"
|
||||
}
|
||||
|
||||
registry := os.Getenv("REGISTRY_PATH")
|
||||
|
||||
Reference in New Issue
Block a user