mirror of
https://github.com/wahyd4/home-docker.git
synced 2026-08-08 20:15:03 +10:00
Add script to build image
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
name: Build and Push Moltbot Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'docker/moltbot/**'
|
||||
- '.github/workflows/moltbot-docker.yml'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
force_rebuild:
|
||||
description: 'Force rebuild'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}/moltbot
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata (tags, labels)
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=sha,prefix={{branch}}-
|
||||
type=ref,event=branch
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./docker/moltbot
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
||||
- name: Image digest
|
||||
run: echo "Image pushed with digest ${{ steps.build.outputs.digest }}"
|
||||
@@ -0,0 +1,26 @@
|
||||
FROM node:25-bookworm
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /home/node
|
||||
|
||||
# Install clawdbot globally during build time (much faster than runtime install)
|
||||
RUN npm install -g clawdbot@latest
|
||||
|
||||
# Create necessary directories
|
||||
RUN mkdir -p /home/node/.clawdbot /home/node/clawd
|
||||
|
||||
# Set environment variables
|
||||
ENV HOME=/home/node \
|
||||
TERM=xterm-256color \
|
||||
PATH=/usr/local/bin:/usr/bin:/bin \
|
||||
CLAWDBOT_GATEWAY_BIND=0.0.0.0
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 18789 18790
|
||||
|
||||
# Create entrypoint script that will update config and start gateway
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
CMD ["clawdbot", "gateway", "--port", "18789", "--bind", "lan", "--verbose"]
|
||||
@@ -0,0 +1,42 @@
|
||||
# Moltbot Custom Docker Image
|
||||
|
||||
This directory contains the Dockerfile and scripts to build a custom Docker image for Moltbot (clawdbot) with pre-installed dependencies.
|
||||
|
||||
## Why?
|
||||
|
||||
The original deployment installed `clawdbot` via npm on every pod startup, causing slow startup times (2-3 minutes). This custom image pre-installs clawdbot during the Docker build, reducing startup time to seconds.
|
||||
|
||||
## What's Included
|
||||
|
||||
- **Dockerfile**: Base image with clawdbot pre-installed
|
||||
- **docker-entrypoint.sh**: Entrypoint script that configures clawdbot for Kubernetes environment
|
||||
|
||||
## Configuration
|
||||
|
||||
The entrypoint automatically creates the clawdbot config with:
|
||||
- Trusted proxies for Kubernetes pod networks (10.42.0.0/16, 10.43.0.0/16)
|
||||
- Token-based authentication
|
||||
- Insecure auth mode (safe behind reverse proxy)
|
||||
- Gateway binding to LAN interface
|
||||
|
||||
## Building Locally
|
||||
|
||||
```bash
|
||||
cd docker/moltbot
|
||||
docker build -t moltbot:local .
|
||||
docker run -p 18789:18789 moltbot:local
|
||||
```
|
||||
|
||||
## GitHub Actions
|
||||
|
||||
The image is automatically built and pushed to GitHub Container Registry (ghcr.io) when:
|
||||
- Changes are pushed to `main` branch affecting `docker/moltbot/**`
|
||||
- Workflow is manually triggered
|
||||
|
||||
Image location: `ghcr.io/wahyd4/home-docker/moltbot:latest`
|
||||
|
||||
## Startup Time Improvement
|
||||
|
||||
- **Before**: ~180 seconds (npm install on every startup)
|
||||
- **After**: ~15 seconds (pre-installed image)
|
||||
- **Savings**: ~90% faster startup time
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Always update config to ensure trustedProxies is set for k8s ingress
|
||||
# Using clawdbot.json (default config name) instead of moltbot.json
|
||||
# Config includes:
|
||||
# - trustedProxies: k8s pod network CIDRs for nginx ingress
|
||||
# - controlUi.allowInsecureAuth: true - allows token-only auth behind reverse proxy
|
||||
# - auth.mode: token - requires gateway token for authentication
|
||||
echo '{"gateway":{"mode":"local","bind":"lan","port":18789,"trustedProxies":["10.42.0.0/16","10.43.0.0/16"],"controlUi":{"allowInsecureAuth":true},"auth":{"mode":"token"}},"agents":{"defaults":{"workspace":"/home/node/clawd"}}}' > /home/node/.clawdbot/clawdbot.json
|
||||
|
||||
echo "Clawdbot config written:"
|
||||
cat /home/node/.clawdbot/clawdbot.json
|
||||
|
||||
echo "Starting clawdbot gateway..."
|
||||
exec "$@"
|
||||
+4
-26
@@ -121,31 +121,9 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: moltbot-gateway
|
||||
image: mirror.gcr.io/node:25-bookworm
|
||||
imagePullPolicy: IfNotPresent
|
||||
image: ghcr.io/wahyd4/home-docker/moltbot:latest
|
||||
imagePullPolicy: Always
|
||||
workingDir: /home/node
|
||||
command: ["/bin/bash", "-c"]
|
||||
args:
|
||||
- |
|
||||
set -e
|
||||
# Install clawdbot (moltbot) globally if not already installed
|
||||
if ! command -v clawdbot &> /dev/null; then
|
||||
echo "Installing clawdbot..."
|
||||
npm install -g clawdbot@latest
|
||||
fi
|
||||
# Create config directory and file with gateway settings
|
||||
mkdir -p /home/node/.clawdbot
|
||||
# Always update config to ensure trustedProxies is set for k8s ingress
|
||||
# Using clawdbot.json (default config name) instead of moltbot.json
|
||||
# Config includes:
|
||||
# - trustedProxies: k8s pod network CIDRs for nginx ingress
|
||||
# - controlUi.allowInsecureAuth: true - allows token-only auth behind reverse proxy (skips device pairing)
|
||||
# - auth.mode: token - requires gateway token for authentication
|
||||
echo '{"gateway":{"mode":"local","bind":"lan","port":18789,"trustedProxies":["10.42.0.0/16","10.43.0.0/16"],"controlUi":{"allowInsecureAuth":true},"auth":{"mode":"token"}},"agents":{"defaults":{"workspace":"/home/node/clawd"}}}' > /home/node/.clawdbot/clawdbot.json
|
||||
echo "Config written:"
|
||||
cat /home/node/.clawdbot/clawdbot.json
|
||||
echo "Starting clawdbot gateway..."
|
||||
exec clawdbot gateway --port 18789 --bind lan --verbose
|
||||
ports:
|
||||
- containerPort: 18789
|
||||
name: gateway
|
||||
@@ -204,7 +182,7 @@ spec:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- "curl -sf http://127.0.0.1:18789/ || exit 1"
|
||||
initialDelaySeconds: 180
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 3
|
||||
@@ -214,7 +192,7 @@ spec:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- "curl -sf http://127.0.0.1:18789/ || exit 1"
|
||||
initialDelaySeconds: 120
|
||||
initialDelaySeconds: 15
|
||||
periodSeconds: 15
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 6
|
||||
|
||||
Reference in New Issue
Block a user