Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion deployment/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,16 @@ services:
- "7091:7091"
depends_on:
- mysql
- metald-aio
- otel
environment:
# Database configuration - use existing mysql service
UNKEY_DATABASE_PRIMARY: "unkey:password@tcp(mysql:3306)/unkey?parseTime=true"
UNKEY_DATABASE_HYDRA: "unkey:password@tcp(mysql:3306)/hydra?parseTime=true"

# Control plane configuration
UNKEY_HTTP_PORT: "7091"
UNKEY_METALD_ADDRESS: "http://localhost:8080"
UNKEY_METALD_ADDRESS: "http://metald-aio:8080"

# Override the entrypoint to run ctrl command

Expand Down Expand Up @@ -256,8 +258,46 @@ services:
UNKEY_WORKSPACE_ID: "ws_local_root"
UNKEY_API_ID: "api_local_root_keys"

# Unkey Deploy Services - All-in-one development container with all 4 services
metald-aio:
build:
context: ../go
dockerfile: deploy/Dockerfile.dev
platform: linux/amd64
container_name: metald-aio
hostname: metald-aio
privileged: true # Required for systemd
volumes:
# Mount Docker socket for metald Docker backend
- /var/run/docker.sock:/var/run/docker.sock
# Persistent storage for development
- metald-aio-data:/opt
# Systemd requires these mounts
- /sys/fs/cgroup:/sys/fs/cgroup:ro
ports:
# Only expose metald port (agent already uses 8080)
- "8090:8080" # metald
depends_on:
- otel
environment:
# Development environment
- UNKEY_ENVIRONMENT=development
- UNKEY_LOG_LEVEL=debug

# Docker backend configuration
- UNKEY_METALD_BACKEND=docker
- UNKEY_METALD_DOCKER_HOST=unix:///var/run/docker.sock

# Service discovery (internal container ports)
- UNKEY_METALD_BILLING_ENDPOINT=http://localhost:8081
- UNKEY_METALD_ASSETMANAGER_ENDPOINT=http://localhost:8083
- UNKEY_ASSETMANAGERD_BUILDERD_ENDPOINT=http://localhost:8082
- UNKEY_BUILDERD_ASSETMANAGER_ENDPOINT=http://localhost:8083


volumes:
mysql:
clickhouse:
clickhouse-keeper:
s3:
metald-aio-data:
225 changes: 225 additions & 0 deletions go/deploy/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Dockerfile.dev - Development environment for all Unkey deploy services
# Based on LOCAL_DEPLOYMENT_GUIDE.md for maximum production parity

# Build stage - compile all services
FROM fedora:42 AS builder

# Install development tools (following LOCAL_DEPLOYMENT_GUIDE.md)
RUN dnf install -y dnf-plugins-core && \
dnf group install -y development-tools && \
dnf install -y git make golang curl wget iptables-legacy && \
dnf clean all


# Set up Go environment
ENV GOPATH=/go
ENV PATH=$PATH:/go/bin:/usr/local/go/bin

# Copy source code
COPY . /src/go
WORKDIR /src/go

# Protobuf files are already generated in go/proto/ - no need to generate them again

# Build all services directly using go build (protobufs already generated)
# Go will download dependencies as needed during build
WORKDIR /src/go/deploy/assetmanagerd
RUN go build -o assetmanagerd ./cmd/assetmanagerd

WORKDIR /src/go/deploy/billaged
RUN go build -o billaged ./cmd/billaged

WORKDIR /src/go/deploy/builderd
RUN go build -o builderd ./cmd/builderd

WORKDIR /src/go/deploy/metald
RUN go build -o metald ./cmd/metald

# Runtime stage - Fedora with systemd
FROM fedora:42

# Install runtime dependencies
RUN dnf update -y && \
dnf install -y \
systemd \
systemd-devel \
iptables-legacy \
curl \
wget \
procps-ng \
util-linux \
&& \
dnf clean all

# Install Docker CLI for metald Docker backend
RUN dnf install -y dnf-plugins-core && \
dnf config-manager addrepo --from-repofile=https://download.docker.com/linux/fedora/docker-ce.repo && \
dnf install -y docker-ce-cli && \
dnf clean all

# Create billaged user (following systemd service requirements)
RUN useradd -r -s /bin/false billaged

# Create required directories (following LOCAL_DEPLOYMENT_GUIDE.md structure)
RUN mkdir -p /opt/assetmanagerd/{cache,data} && \
mkdir -p /opt/billaged && \
mkdir -p /opt/builderd/{scratch,rootfs,workspace,data} && \
mkdir -p /opt/metald/{sockets,logs,assets} && \
mkdir -p /srv/jailer && \
mkdir -p /var/log/{assetmanagerd,billaged,builderd,metald} && \
mkdir -p /opt/vm-assets

# Set ownership for service directories
RUN chown -R billaged:billaged /opt/billaged /var/log/billaged

# Copy built binaries from builder stage
COPY --from=builder /src/go/deploy/assetmanagerd/assetmanagerd /usr/local/bin/
COPY --from=builder /src/go/deploy/billaged/billaged /usr/local/bin/
COPY --from=builder /src/go/deploy/builderd/builderd /usr/local/bin/
COPY --from=builder /src/go/deploy/metald/metald /usr/local/bin/


# Make binaries executable
RUN chmod +x /usr/local/bin/assetmanagerd* /usr/local/bin/billaged* /usr/local/bin/builderd* /usr/local/bin/metald*

# Copy systemd service files for container environment
COPY deploy/docker/systemd/ /etc/systemd/system/

# Create development environment file
RUN cat > /etc/default/unkey-deploy << 'EOF'
# Development environment variables for all services
# TLS disabled for development
UNKEY_ASSETMANAGERD_TLS_MODE=disabled
UNKEY_BILLAGED_TLS_MODE=disabled
UNKEY_BUILDERD_TLS_MODE=disabled
UNKEY_METALD_TLS_MODE=disabled

# Configure Docker backend for metald
UNKEY_METALD_BACKEND=docker

# Service endpoints (HTTP for development)
UNKEY_METALD_BILLING_ENDPOINT=http://localhost:8081
UNKEY_METALD_ASSETMANAGER_ENDPOINT=http://localhost:8083
UNKEY_ASSETMANAGERD_BUILDERD_ENDPOINT=http://localhost:8082
UNKEY_BUILDERD_ASSETMANAGER_ENDPOINT=http://localhost:8083

# Service configuration
UNKEY_ASSETMANAGERD_PORT=8083
UNKEY_ASSETMANAGERD_ADDRESS=0.0.0.0
UNKEY_BILLAGED_PORT=8081
UNKEY_BILLAGED_ADDRESS=0.0.0.0
UNKEY_BUILDERD_PORT=8082
UNKEY_BUILDERD_ADDRESS=0.0.0.0
UNKEY_METALD_PORT=8080
UNKEY_METALD_ADDRESS=0.0.0.0

# Storage configuration
UNKEY_ASSETMANAGERD_STORAGE_BACKEND=local
UNKEY_ASSETMANAGERD_LOCAL_STORAGE_PATH=/opt/builderd/rootfs
UNKEY_ASSETMANAGERD_DATABASE_PATH=/opt/assetmanagerd/assets.db
UNKEY_ASSETMANAGERD_CACHE_DIR=/opt/assetmanagerd/cache

# Build configuration
UNKEY_BUILDERD_SCRATCH_DIR=/opt/builderd/scratch
UNKEY_BUILDERD_ROOTFS_OUTPUT_DIR=/opt/builderd/rootfs
UNKEY_BUILDERD_WORKSPACE_DIR=/opt/builderd/workspace
UNKEY_BUILDERD_DATABASE_DATA_DIR=/opt/builderd/data

# Disable observability for development
UNKEY_ASSETMANAGERD_OTEL_ENABLED=false
UNKEY_BILLAGED_OTEL_ENABLED=false
UNKEY_BUILDERD_OTEL_ENABLED=false
UNKEY_METALD_OTEL_ENABLED=false
EOF

# Enable services (following LOCAL_DEPLOYMENT_GUIDE.md order)
RUN systemctl enable assetmanagerd.service && \
systemctl enable billaged.service && \
systemctl enable builderd.service && \
systemctl enable metald.service

# Create entrypoint script
RUN cat > /entrypoint.sh << 'EOF'
#!/bin/bash
set -e

# Source environment variables
source /etc/default/unkey-deploy

# Check Docker socket access
if [ -S /var/run/docker.sock ]; then
echo "Docker socket found, testing access..."
if timeout 10 docker version > /dev/null 2>&1; then
echo "Docker access confirmed"
else
echo "Warning: Docker socket exists but not accessible"
fi
else
echo "Warning: Docker socket not found at /var/run/docker.sock"
fi

# Start services directly (systemd is problematic in containers)
echo "Starting services directly..."

# Start services directly in background with proper ordering
echo "Starting assetmanagerd..."
/usr/local/bin/assetmanagerd &
ASSETMANAGERD_PID=$!

echo "Starting billaged..."
/usr/local/bin/billaged &
BILLAGED_PID=$!

echo "Starting builderd..."
/usr/local/bin/builderd &
BUILDERD_PID=$!

# Wait a moment for dependencies to start
sleep 5

echo "Starting metald..."
/usr/local/bin/metald &
METALD_PID=$!

echo "All services started. PIDs: assetmanagerd=$ASSETMANAGERD_PID billaged=$BILLAGED_PID builderd=$BUILDERD_PID metald=$METALD_PID"

# Function to handle shutdown
shutdown_services() {
echo "Shutting down services..."
kill $METALD_PID $BUILDERD_PID $BILLAGED_PID $ASSETMANAGERD_PID 2>/dev/null || true
wait
}

# Set up signal handler
trap shutdown_services SIGTERM SIGINT

# Wait for all background processes
wait
EOF

RUN chmod +x /entrypoint.sh

# Expose service ports
EXPOSE 8080 8081 8082 8083

# Set up systemd as PID 1
ENTRYPOINT ["/entrypoint.sh"]

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1

# Labels for identification
LABEL org.unkey.component="deploy-services" \
org.unkey.version="dev" \
org.unkey.description="Development environment for all Unkey deploy services"

# AIDEV-NOTE: This Dockerfile follows the LOCAL_DEPLOYMENT_GUIDE.md as closely as possible
# Key features:
# 1. Uses Fedora 42 (production parity)
# 2. Multi-stage build with development tools
# 3. systemd as process manager
# 4. All services built using existing Makefiles
# 5. TLS disabled for development
# 6. Docker backend configured for metald
# 7. Proper directory structure and permissions
Loading
Loading