Nix container build for nettest (#214)
## Summary - Add `containers/nettest/default.nix` using `dockerTools.buildLayeredImage` with curl, jq, dnsutils, cacert, and bash — equivalent to the existing Dockerfile - Update `container-tag-and-release` to require `--nix` or `--dockerfile` flag when both build types exist for a container - Update `container-list` to show `[dockerfile+nix]` label when both exist ## Deployment and Testing - [ ] SSH to ringtail, run `nix build -f containers/nettest/default.nix -o result` to verify the nix expression builds - [ ] Tag `nettest-nix-v1.0.0`, confirm `build-container-nix` workflow runs on `nix-container-builder` runner and pushes to registry - [ ] Smoke test on ringtail k3s: `kubectl run nettest --image=registry.ops.eblu.me/blumeops/nettest:v1.0.0 --restart=Never && kubectl logs nettest` - [ ] Verify `mise run container-list` shows `[dockerfile+nix]` for nettest - [ ] Verify `mise run container-tag-and-release nettest v1.1.0` prompts for build type Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/214
This commit is contained in:
parent
b475a1fcd7
commit
695089499e
10 changed files with 244 additions and 130 deletions
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Build Container Image
|
||||
modified: 2026-02-15
|
||||
modified: 2026-02-19
|
||||
last-reviewed: 2026-02-15
|
||||
tags:
|
||||
- how-to
|
||||
|
|
@ -14,30 +14,35 @@ How to create a custom container image in BlumeOps, build it locally, and releas
|
|||
|
||||
## Prerequisites
|
||||
|
||||
- [Dagger CLI](https://docs.dagger.io/install) installed locally
|
||||
- A Dockerfile for the service you want to build
|
||||
- [Dagger CLI](https://docs.dagger.io/install) installed locally (for Dockerfile builds)
|
||||
- A `Dockerfile` and/or `default.nix` for the service
|
||||
|
||||
## 1. Create the container directory
|
||||
|
||||
Add a `Dockerfile` (and any supporting files) under `containers/<name>/`:
|
||||
Add build files under `containers/<name>/`:
|
||||
|
||||
```
|
||||
containers/<name>/
|
||||
├── Dockerfile
|
||||
├── Dockerfile (built by Dagger on the k8s runner)
|
||||
├── default.nix (built by nix-build on the ringtail runner)
|
||||
└── (optional scripts, configs)
|
||||
```
|
||||
|
||||
The directory name becomes the image name: `registry.ops.eblu.me/blumeops/<name>`.
|
||||
A container can have one or both build files. The directory name becomes the image name: `registry.ops.eblu.me/blumeops/<name>`.
|
||||
|
||||
## 2. Build locally
|
||||
|
||||
Test your image with Dagger:
|
||||
**Dockerfile** — test with Dagger:
|
||||
|
||||
```bash
|
||||
dagger call build --src=. --container-name=<name>
|
||||
```
|
||||
|
||||
This builds `containers/<name>/Dockerfile` using the Dagger `docker_build()` function. Fix any build errors before proceeding.
|
||||
**Nix** — test with nix-build (requires nix, e.g. on [[ringtail]]):
|
||||
|
||||
```bash
|
||||
nix-build containers/<name>/default.nix -o result
|
||||
```
|
||||
|
||||
## 3. Release
|
||||
|
||||
|
|
@ -47,7 +52,14 @@ Once the image builds cleanly, create a tagged release:
|
|||
mise run container-tag-and-release <name> v1.0.0
|
||||
```
|
||||
|
||||
This creates a git tag `<name>-v1.0.0` and pushes it. The `build-container` Forgejo workflow triggers on the tag, builds the image via Dagger, and publishes it to the registry as `registry.ops.eblu.me/blumeops/<name>:v1.0.0`.
|
||||
Use `--dry-run` to preview without creating tags.
|
||||
|
||||
This creates a single git tag `<name>-v1.0.0` and pushes it. Both Forgejo workflows trigger on the tag — each checks for its build file and skips if not present:
|
||||
|
||||
| Build file | Workflow | Runner | Registry tag |
|
||||
|------------|----------|--------|--------------|
|
||||
| `Dockerfile` | `build-container.yaml` | `k8s` (indri) | `:v1.0.0` |
|
||||
| `default.nix` | `build-container-nix.yaml` | `nix-container-builder` ([[ringtail]]) | `:v1.0.0-nix` |
|
||||
|
||||
Check available images and tags with:
|
||||
|
||||
|
|
@ -76,6 +88,7 @@ Existing containers demonstrate several build approaches:
|
|||
| Multi-stage with Node + Go | [[#navidrome]] | Separate UI and backend build stages |
|
||||
| Multi-stage Elixir | [[#teslamate]] | Elixir release with Node assets |
|
||||
| Runtime tarball download | [[#kiwix-serve]] | Download pre-built binary with arch detection |
|
||||
| Nix `dockerTools` | [[#nettest-nix]] | `buildLayeredImage` with nixpkgs tools |
|
||||
|
||||
### transmission
|
||||
|
||||
|
|
@ -97,6 +110,10 @@ Existing containers demonstrate several build approaches:
|
|||
|
||||
`containers/kiwix-serve/Dockerfile` — Downloads a pre-built binary from upstream, with architecture detection for cross-platform support.
|
||||
|
||||
### nettest (nix)
|
||||
|
||||
`containers/nettest/default.nix` — Uses `dockerTools.buildLayeredImage` with `buildEnv` to merge nixpkgs tools (curl, jq, dnsutils, bash). Runs alongside the existing Dockerfile; the nix variant is tagged `:version-nix` in the registry.
|
||||
|
||||
## Related
|
||||
|
||||
- [[deploy-k8s-service]] — Deploying the service that uses the image
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue