Skip to main content

Docker Buildx CLI wrapper with GitOps integration

Project description

ngen-buildx

Docker Buildx CLI wrapper with GitOps integration.

Overview

ngen-buildx is a CLI tool that simplifies Docker image building using docker buildx. It integrates with ngen-gitops to automatically fetch CI/CD configuration from repositories and supports both remote and local builds.

Features

  • 🚀 Remote Build: Build directly from remote Git repositories (default)
  • 📁 Local Build: Build from local source directory with --local flag
  • 🔧 GitOps Integration: Fetches cicd/cicd.json from repositories using gitops get-file
  • 📦 Resource Management: Configurable memory and CPU limits for builds
  • 🏗️ Multi-platform Support: Build for multiple architectures
  • 🔄 Smart Image Check: Skip build if image already exists (use --rebuild to force)
  • 📣 Teams Notification: Send build notifications to Microsoft Teams
  • 🏷️ Smart Tagging: Uses commit ID for branches, tag name for version tags

Installation

pip install ngen-buildx

Prerequisites

  • Docker with buildx plugin installed
  • ngen-gitops installed and configured with Bitbucket credentials
  • ~/.netrc configured with Bitbucket credentials (for remote builds)

Quick Start

  1. Initialize configuration:

    buildx --init
    
  2. Edit configuration files:

    # Edit ~/.ngen-buildx/.env for environment variables
    # Edit ~/.ngen-buildx/arg.json for build arguments
    
  3. Build an image:

    # Remote build (from Git repository)
    buildx saas-apigateway develop
    
    # Local build (from current directory)
    buildx myproject develop --local
    

Configuration

Environment Variables (~/.ngen-buildx/.env)

# Builder Configuration
BUILDER_NAME=container-builder
DEFAULT_MEMORY=4g
DEFAULT_CPU_PERIOD=100000
DEFAULT_CPU_QUOTA=200000

# Registry Configuration
REGISTRY01_URL=myregistry

# GitOps Settings
BITBUCKET_ORG=myorg

# Notifications (Microsoft Teams)
TEAMS_WEBHOOK=https://your-org.webhook.office.com/webhookb2/...

Build Arguments (~/.ngen-buildx/arg.json)

{
    "REGISTRY01": "$REGISTRY01_URL",
    "BRANCH": "$REFS",
    "PROJECT": "$IMAGE",
    "PORT": "$PORT",
    "PORT2": "$PORT2"
}

CICD Configuration (cicd/cicd.json in repository)

{
    "IMAGE": "saas-apigateway",
    "CLUSTER": "qoin",
    "PROJECT": "saas",
    "DEPLOYMENT": "saas-apigateway",
    "NODETYPE": "front",
    "PORT": "8005"
}

Usage

Remote Build (Default)

Build directly from remote Git repository:

# Basic build
buildx <repo> <ref>

# Examples
buildx saas-apigateway develop
buildx saas-apigateway develop --dry-run
buildx myrepo v1.0.0

Local Build

Build from local source directory:

# Build from current directory (uses cicd/cicd.json)
buildx myrepo develop --local

# Build with custom context
buildx myrepo develop --local --context ./src

# Build with custom cicd.json path
buildx myrepo develop --local --cicd config/cicd.json

# Local build with push
buildx myrepo v1.0.0 --local --tag myregistry/myapp:v1.0.0 --push

Build Options

Option Description
--local Build from local directory instead of remote repo
--rebuild Force rebuild even if image already exists
--cicd PATH Path to local cicd.json (default: cicd/cicd.json)
--context PATH Build context path (default: .)
--dockerfile, -f Dockerfile path (default: Dockerfile)
--tag, -t Image tag (default: from cicd.json)
--push Push image after build (default for remote builds)
--platform Target platform(s) (e.g., linux/amd64,linux/arm64)
--org Organization name
--build-arg KEY=VALUE Set build argument (can be used multiple times)
--dry-run Show command without executing
--json Output as JSON

Configuration Commands

# Show configuration
buildx --config

# Show as JSON
buildx --config --json

Initialize Command

# Create config files
buildx --init

# Recreate config files
buildx --init --force

Image Tagging

The tool uses smart tagging based on the reference type:

Reference Type Tag Format
Branch (develop, main) 6-char commit ID (e.g., 2195e0)
Version tag (v1.0.0, 1.2.3) Tag name (e.g., v1.0.0)

Generated Build Command

For remote builds, the tool generates a command like:

docker buildx build \
  --builder container-builder \
  --sbom=true \
  --no-cache \
  --attest type=provenance,mode=max \
  --memory 4g \
  --cpu-period 100000 \
  --cpu-quota 200000 \
  --progress=plain \
  --build-arg REGISTRY01=myregistry \
  --build-arg BRANCH=develop \
  --build-arg PROJECT=saas-apigateway \
  --build-arg PORT=8005 \
  -t myregistry/saas-apigateway:2195e0 \
  --push \
  https://***:***@bitbucket.org/myorg/saas-apigateway.git#develop

Teams Notification

When TEAMS_WEBHOOK is configured in .env, build notifications are sent to Microsoft Teams:

  • ✅ Success notification with image details
  • ❌ Failure notification with error info

Related Tools

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ngen_buildx-0.1.3.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ngen_buildx-0.1.3-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file ngen_buildx-0.1.3.tar.gz.

File metadata

  • Download URL: ngen_buildx-0.1.3.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ngen_buildx-0.1.3.tar.gz
Algorithm Hash digest
SHA256 69725ff748eca0e17d050b169bd5e87c91893307da55dc0407df1092bf73e438
MD5 1ccfbb0577d3dc2f68c67aeb9342f91b
BLAKE2b-256 2cc2816046177f92712437f40dd0c60e56f46878da09f8c6e4d49b90811f7290

See more details on using hashes here.

File details

Details for the file ngen_buildx-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ngen_buildx-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for ngen_buildx-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5eb5f3940319d57e4ca398e1dbb8be18da2208b0187c85ca12a6a64b4ff3b380
MD5 81ea21b73208bce1889ce026c1c0c76f
BLAKE2b-256 3bb22ff9f73aed5b189976ae4f99187cf3e8e55e71a1679885f41bc57acc226a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page