build-q (bq) 🚀
build-q (dibaca bq) adalah CLI Python zero-dependency untuk operasi docker buildx lokal & remote yang selaras dengan pipeline CI/CD (Jenkins X). Satu perintah pendek bq menggantikan docker buildx build yang panjang, dengan auto-detect Git, cicd/cicd.json, secret netrc, resource limit, dan idempotency check terhadap registry.
Selain itu, bq menyediakan scaffolding CI/CD (--init-jx), setup secrets GitHub Actions (--init-secrets), migrasi Dockerfile legacy ke pola --mount=type=secret (--fix-dockerfile), dan auto-init Docker Buildx builder (--init).
🛠 Fitur
Build & Push
- Zero-dependency: hanya Python 3.7+ standard library.
- Git auto-detection: nama repo & ref (branch/tag/short-SHA) dari Git.
- Mode sumber kode: build lokal,
--clone(viaghCLI), atau--remote(Buildx Git context). - Registry idempotency: cek image di registry sebelum build → skip bila sudah ada (bypass
--rebuild). - Smart branch build-arg:
BRANCH=productionuntuk tagv*, elseBRANCH=develop. - Default netrc secret:
--secret id=netrc,src=$HOME/.netrcotomatis. - Resource limit default: memory & CPU aman untuk laptop.
- CI/CD alignment: baca
PORT/PORT2/PROJECT/IMAGEdaricicd/cicd.json. - Dry run: pratinjau command tanpa eksekusi.
- GitHub org shorthand: set
GITHUB_ORG=...di config → cukupbq <repo>bukanbq <owner>/<repo>.
Setup & Automation
--init: buat file config~/.build-q/.envdan auto-create Docker Buildx builder (bootstrap).--init-jx: scaffoldMakefile+compose.yaml+Dockerfile(modern secret mount) +.github/workflows/trigger-ci.ymldaricicd/cicd.json. Auto-panggil--init-secretsbila git remote GitHub terdeteksi.--init-secrets: set GitHub Actions secrets (WEBHOOK_TRIGGER_URL,WEBHOOK_TRIGGER_TOKEN) — auto-fetch token dari k8s secretwebhook-trigger-tokendi namespacejenkins-x, auto-detect target repo darigit remote.--fix-dockerfile: migrasi Dockerfile legacy —FROM ... as ...→AS, hapusARG GITHUB_USER/TOKEN, ubahRUN echo "machine github.com..." > ~/.netrc && ...→RUN --mount=type=secret,id=netrc,target=/root/.netrc \ .... Simpan backup keDockerfile.bak.--gh-auth: injeksi--build-arg GITHUB_USER+GITHUB_TOKENdarighCLI (workaround untuk Dockerfile legacy yang belum dimigrasi).- Auto-recover builder stale:
ensure_builderdeteksi endpoint rusak (misal socket Colima lama) dan recreate otomatis.
📦 Instalasi
pipx install build-q # rekomendasi (CLI global, virtualenv terisolasi)
# atau
pip install build-q
Dua entry point tersedia: build-q dan shorthand bq.
⚙️ Konfigurasi Awal (sekali saja)
bq --init # buat ~/.build-q/.env + create Docker buildx builder
bq --init --force # recreate config; builder tetap aman (cek dulu, buat bila tidak ada)
bq --config # tampilkan konfigurasi aktif
~/.build-q/.env
| Variable | Default | Keterangan |
|---|---|---|
BUILDER_NAME |
mybuilder |
Nama Docker Buildx builder |
REGISTRY_URL |
registry.example.com |
Docker registry (Qoin: loyaltolpi) |
DEFAULT_MEMORY |
4g |
Memory limit build |
DEFAULT_CPU_PERIOD |
100000 |
CPU period |
DEFAULT_CPU_QUOTA |
200000 |
CPU quota |
GIT_SSH_PREFIX |
git@github.com: |
Prefix SSH untuk --remote |
GITHUB_ORG |
(kosong) | Default org untuk shorthand bq <repo> |
WEBHOOK_TRIGGER_URL |
https://cicd-hw.qoin.id/trigger |
Endpoint webhook Jenkins X |
JX_KUBE_CONTEXT |
(kosong = current) | kubectl context untuk fetch token |
JX_KUBE_NAMESPACE |
jenkins-x |
Namespace secret |
JX_TOKEN_SECRET |
webhook-trigger-token |
Nama k8s secret berisi token |
Contoh minimal untuk Qoin:
BUILDER_NAME=cloud-loyaltolpi
REGISTRY_URL=loyaltolpi
GITHUB_ORG=Qoin-Digital-Indonesia
WEBHOOK_TRIGGER_URL=https://cicd-hw.qoin.id/trigger
🚀 Panduan Penggunaan
1. Build dari direktori lokal
Auto-detect nama repo & branch dari git:
cd my-service
bq # build + push (default)
bq --no-push # build tanpa push
bq --dry-run # preview command saja
bq my-service staging # eksplisit repo/ref
2. Build dari repo remote tanpa clone
# Dengan GITHUB_ORG di config → shorthand
bq plus-be-paymentlink-manager staging --remote
# Tanpa GITHUB_ORG → sertakan owner
bq Qoin-Digital-Indonesia/plus-be-paymentlink-manager staging --remote
# URL SSH/HTTPS penuh juga OK
bq git@github.com:owner/repo.git v1.0.0 --remote
3. Build dengan clone via gh CLI
bq --clone plus-be-paymentlink-manager staging
bq --clone plus-be-paymentlink-manager staging --clean # hapus folder setelah build
4. Preview command (dry-run)
bq --dry-run
bq plus-be-paymentlink-manager staging --remote --no-image-check --dry-run
5. Paksa rebuild (bypass image check)
bq plus-be-paymentlink-manager staging --remote --rebuild
6. Bootstrap CI/CD service baru (Jenkins X)
mkdir my-new-service && cd my-new-service
cat > cicd/cicd.json <<EOF # buat dulu manual
{"IMAGE":"my-new-service","PROJECT":"qoinplus","PORT":"8080"}
EOF
bq --init-jx # scaffold Makefile/compose/Dockerfile/workflow
git init && git remote add origin git@github.com:Qoin-Digital-Indonesia/my-new-service.git
bq --init-secrets # set webhook secrets di GitHub (auto-detect repo)
git add . && git commit -m "chore: bootstrap CI/CD"
git push -u origin main # trigger Jenkins X pipeline via GitHub Actions
7. Migrasi Dockerfile legacy (ARG-based netrc → secret mount)
cd my-old-service
bq --fix-dockerfile # migrasi ./Dockerfile (backup ke .bak)
bq --fix-dockerfile path/to/Dockerfile
bq --no-push --rebuild # test build hasil migrasi
8. Workaround Dockerfile legacy tanpa migrasi (--gh-auth)
bq plus-be-service staging --remote --rebuild --gh-auth
# → inject GITHUB_USER dari `gh api user` + GITHUB_TOKEN dari `gh auth token`
9. Setup secrets Jenkins X untuk repo existing
cd existing-repo
bq --init-secrets # auto-detect dari git
bq --init-secrets Qoin-Digital-Indonesia/foo-service # eksplisit
bq --init-secrets foo-service --token xxxx # skip kubectl
10. Contoh full (customize secret, platform, build-arg)
bq plus-be-service staging \
--secret id=custom,src=/path/to/secret \
--platform linux/amd64 \
--no-push \
--build-arg BRANCH=custom-branch \
--build-arg FEATURE_FLAG=on
🔗 Perintah Lengkap
bq [<repo> [<ref>]] [OPTIONS]
Subcommands (mutually exclusive):
--init Buat ~/.build-q/.env + init Buildx builder
--init --force Recreate config
--config Tampilkan konfigurasi aktif
--init-jx Scaffold Makefile/compose/Dockerfile/workflow
--init-jx --force Overwrite file existing
--init-secrets [<repo>] Set GitHub Actions webhook secrets
--fix-dockerfile [PATH] Migrasi Dockerfile legacy ke secret mount
Build modes:
(default) Build dari direktori lokal
--clone <owner/repo> Clone via `gh` CLI, lalu build
--clone ... --clean Hapus folder clone setelah build
--remote Build via Buildx Git context (tanpa clone)
Build options:
--cicd PATH Path cicd.json (default: cicd/cicd.json)
--context DIR Build context (default: .)
-f, --dockerfile PATH Path Dockerfile (default: Dockerfile)
-t, --tag IMAGE:TAG Override image tag
--push / --no-push Push image (default: push)
--image-check / --rebuild Cek image di registry, skip bila ada (default: on)
--no-image-check Sama dengan --rebuild
--platform PLATFORM Target platform (default: linux/amd64)
--build-arg KEY=VALUE Build arg (dapat diulang)
--secret id=ID,src=PATH Secret build (dapat diulang; netrc otomatis)
--gh-auth Inject GITHUB_USER/TOKEN dari `gh` CLI
--token VALUE Webhook token (dengan --init-secrets)
--dry-run Preview command tanpa eksekusi
--version Tampilkan versi
📋 Requirements
- Python 3.7+
- Docker + Buildx plugin
- Git (opsional; wajib untuk auto-detect & mode local)
- GitHub CLI (
gh) — wajib untuk--clone,--remote,--gh-auth,--init-secrets - kubectl — opsional; hanya untuk
--init-secrets(fetch token otomatis dari cluster)
🚀 Development & Release
Proyek pakai Makefile untuk build & release.
make build # build sdist + wheel ke dist/
make install # install local (pipx editable)
make release # bump patch, build, install, upload ke PyPI
make release V=1.0.0 # release versi spesifik
make clean # bersihkan artefak
Release process (make release):
scripts/bump_version.pybump patch version dipyproject.toml&build_q/__init__.py.- Build sdist + wheel via
python3 -m build(fallback:pipx run --spec build pyproject-build). - Install lokal editable via
pipx. - Upload ke PyPI via
pipx run twine. Kredensial dibaca dari~/.pypirc.
📄 License
MIT
Release files for build-q 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| build_q-0.1.10.tar.gz | 22.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| build_q-0.1.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.9 kB
Release files / build_q-0.1.10.tar.gz
| Download URL | build_q-0.1.10.tar.gz |
|---|---|
| Size | 22.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dce1cbaf830daf975f52f75c6775c1826295e4b057d6fefbf03e3204b5aaa22b
|
|
BLAKE2b-256 checksum How to use checksums |
c90502e88102a80d89128d1ac5f8ec9d893c4b4423554d632563ad8888aa83b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / build_q-0.1.10-py3-none-any.whl
| Download URL | build_q-0.1.10-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ad3c332eaa32ecfddbb8ad8068e02e7ae3a1d7de6fd96569578339b9a2cfb30
|
|
BLAKE2b-256 checksum How to use checksums |
4b02dea47936614085e3396458475cc0413e244cc829fe090efaa5f599e14e8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|