mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 01:38:32 +00:00
## Overview This PR consolidates and optimizes the Docker build system, reducing redundancy and improving CI/CD performance. The changes eliminate duplicate Dockerfiles, introduce a flexible build template, and optimize release builds to reuse CI artifacts. ## Changes Summary ### 🐳 Docker Images Restructured **Before:** 5 Dockerfiles with significant overlap **After:** 4 focused images + 1 utility #### Final Structure: 1. **`operator/Dockerfile`** ✨ Updated - **Standard operator image** for CI and release builds - Minimal node image (accepts pre-built binaries) - GHCR: `ghcr.io/datahaven-xyz/datahaven/datahaven` (CI) - DockerHub: `datahavenxyz/datahaven` (releases) 2. **`docker/datahaven-build.Dockerfile`** (moved from `operator/Dockerfile`) - Full source-to-binary build for manual releases - DockerHub: `datahavenxyz/datahaven:{label}` - Supports custom RUSTFLAGS and fast-runtime feature - Only used for manual workflow_dispatch builds 3. **`docker/datahaven-production.Dockerfile`** (kept) - Binary builder for CPU-specific releases - Used by build-prod-binary workflow template - Supports custom target-cpu flags 4. **`docker/datahaven-dev.Dockerfile`** ✨ NEW (local dev only) - **FOR LOCAL DEVELOPMENT/TROUBLESHOOTING ONLY** - Includes debug tools: gdb, strace, vim, sudo - Extra dependencies: librocksdb-dev, curl - RUST_BACKTRACE enabled by default - **DO NOT USE for CI or production builds** 5. **`test/docker/crossbuild-mac-libpq.dockerfile`** (kept) - Utility for macOS → Linux cross-compilation #### Removed (Redundant): - ❌ `docker/datahaven.Dockerfile` → replaced by operator/Dockerfile - ❌ `test/docker/datahaven-node-local.dockerfile` → replaced by datahaven-dev.Dockerfile --- ### 🔄 Workflow Improvements #### Enhanced `publish-docker` Template - Supports both GHCR and DockerHub registries - Flexible inputs: dockerfile, context, build-args, cache scope - Auto-generates OCI-compliant labels - Reduces code duplication (~70 lines → ~15 per workflow) #### Refactored CI Pipeline - **`docker-build-ci`**: Builds `operator/Dockerfile` → GHCR for CI/E2E testing - **`docker-build-release`**: Builds `operator/Dockerfile` → DockerHub (main branch only) - Both CI and release workflows now use the same minimal operator image - Release builds **reuse CI binaries** instead of rebuilding from source #### Optimized Release Workflow The `task-docker-release` workflow now has dual modes: **Mode 1: `workflow_call` (CI - main pushes)** - ✅ Reuses binary from CI's build-operator task - ✅ Uses lightweight `operator/Dockerfile` - ✅ Tags: `latest`, `sha-{short}` - ⚡ **Fast**: ~5 minutes (vs ~30 min previously) **Mode 2: `workflow_dispatch` (Manual)** - ✅ Full source build with `datahaven-build.Dockerfile` - ✅ Custom branch and label selection - ✅ Optional fast-runtime feature - ✅ Tags: `PROD-{label}` or user-defined --- ### 🔧 Additional Optimizations - Copy libpq5 from builder stage instead of reinstalling (smaller, faster) - Remove redundant protobuf-compiler package (use protoc v21.12 directly) - Standardize user UID to 1000 across all runtime images - Consistent OCI labeling and metadata --------- Co-authored-by: Claude <noreply@anthropic.com>
125 lines
3.6 KiB
YAML
125 lines
3.6 KiB
YAML
name: Publish docker image
|
|
description: |
|
|
Publish docker image tags to container registry
|
|
|
|
inputs:
|
|
dockerfile:
|
|
description: "Path to Dockerfile"
|
|
required: true
|
|
context:
|
|
description: "Build context path"
|
|
required: false
|
|
default: "."
|
|
registry:
|
|
description: "Container registry (ghcr.io or docker.io)"
|
|
required: false
|
|
default: "docker.io"
|
|
registry_username:
|
|
description: "Registry username"
|
|
required: true
|
|
registry_password:
|
|
description: "Registry password"
|
|
required: true
|
|
image_tags:
|
|
description: "Image tags (newline or comma-separated)"
|
|
required: true
|
|
image_title:
|
|
description: "Image title"
|
|
required: false
|
|
default: "DataHaven Node"
|
|
image_description:
|
|
description: "Image description"
|
|
required: false
|
|
default: "DataHaven blockchain node"
|
|
image_url:
|
|
description: "Image url"
|
|
required: false
|
|
default: "https://github.com/datahaven-xyz/datahaven"
|
|
image_source:
|
|
description: "Image source"
|
|
required: false
|
|
default: "https://github.com/datahaven-xyz/datahaven"
|
|
image_created:
|
|
description: "Image creation timestamp"
|
|
required: false
|
|
default: ""
|
|
image_revision:
|
|
description: "Image revision (git sha)"
|
|
required: false
|
|
default: ""
|
|
image_licenses:
|
|
description: "Image licenses"
|
|
required: false
|
|
default: "Apache-2.0"
|
|
cache_scope:
|
|
description: "Cache scope for GitHub Actions cache"
|
|
required: false
|
|
default: "docker-build"
|
|
build_args:
|
|
description: "Build arguments (newline or comma-separated)"
|
|
required: false
|
|
default: ""
|
|
platforms:
|
|
description: "Target platforms"
|
|
required: false
|
|
default: "linux/amd64"
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
version: latest
|
|
driver-opts: |
|
|
image=moby/buildkit:master
|
|
|
|
- name: Login to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ inputs.registry }}
|
|
username: ${{ inputs.registry_username }}
|
|
password: ${{ inputs.registry_password }}
|
|
|
|
- name: Prepare labels
|
|
id: labels
|
|
shell: bash
|
|
run: |
|
|
CREATED="${{ inputs.image_created }}"
|
|
if [ -z "$CREATED" ]; then
|
|
CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
fi
|
|
|
|
REVISION="${{ inputs.image_revision }}"
|
|
if [ -z "$REVISION" ]; then
|
|
REVISION="${{ github.sha }}"
|
|
fi
|
|
|
|
echo "created=$CREATED" >> $GITHUB_OUTPUT
|
|
echo "revision=$REVISION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push image
|
|
id: docker_build
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ${{ inputs.context }}
|
|
file: ${{ inputs.dockerfile }}
|
|
platforms: ${{ inputs.platforms }}
|
|
push: true
|
|
tags: ${{ inputs.image_tags }}
|
|
build-args: ${{ inputs.build_args }}
|
|
cache-from: type=gha,scope=${{ inputs.cache_scope }}
|
|
cache-to: type=gha,mode=max,scope=${{ inputs.cache_scope }}
|
|
provenance: mode=max
|
|
sbom: true
|
|
labels: |
|
|
org.opencontainers.image.title=${{ inputs.image_title }}
|
|
org.opencontainers.image.description=${{ inputs.image_description }}
|
|
org.opencontainers.image.url=${{ inputs.image_url }}
|
|
org.opencontainers.image.source=${{ inputs.image_source }}
|
|
org.opencontainers.image.created=${{ steps.labels.outputs.created }}
|
|
org.opencontainers.image.revision=${{ steps.labels.outputs.revision }}
|
|
org.opencontainers.image.licenses=${{ inputs.image_licenses }}
|