Create containers/nettest/default.nix using dockerTools.buildLayeredImage with the same tools as the Dockerfile (curl, jq, dnsutils, cacert, bash). Update container-list and container-tag-and-release to handle containers that have both a Dockerfile and default.nix, requiring --nix or --dockerfile flag when both exist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
110 lines
3 KiB
Bash
Executable file
110 lines
3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#MISE description="Release a container image by creating a git tag"
|
|
|
|
set -euo pipefail
|
|
|
|
CONTAINER="${1:-}"
|
|
VERSION="${2:-}"
|
|
BUILD_TYPE_FLAG="${3:-}"
|
|
|
|
if [[ -z "$CONTAINER" || -z "$VERSION" ]]; then
|
|
echo "Usage: mise run container-tag-and-release <container> <version> [--nix|--dockerfile]"
|
|
echo ""
|
|
echo "When a container has both a Dockerfile and default.nix, you must specify"
|
|
echo "the build type with --nix or --dockerfile."
|
|
echo ""
|
|
echo "Run 'mise run container-list' to see available containers and recent tags."
|
|
exit 1
|
|
fi
|
|
|
|
# Validate version format
|
|
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
echo "Error: Version must be in format vX.Y.Z (e.g. v1.0.0)"
|
|
exit 1
|
|
fi
|
|
|
|
# Determine build type: Nix or Dockerfile
|
|
CONTAINER_DIR="containers/${CONTAINER}"
|
|
HAS_NIX=false
|
|
HAS_DOCKERFILE=false
|
|
|
|
[[ -f "$CONTAINER_DIR/default.nix" ]] && HAS_NIX=true
|
|
[[ -f "$CONTAINER_DIR/Dockerfile" ]] && HAS_DOCKERFILE=true
|
|
|
|
if ! $HAS_NIX && ! $HAS_DOCKERFILE; then
|
|
echo "Error: No Dockerfile or default.nix found in '$CONTAINER_DIR'"
|
|
echo ""
|
|
echo "Available containers:"
|
|
for dir in containers/*/; do
|
|
[[ -d "$dir" ]] || continue
|
|
name=$(basename "$dir")
|
|
types=()
|
|
[[ -f "$dir/Dockerfile" ]] && types+=("dockerfile")
|
|
[[ -f "$dir/default.nix" ]] && types+=("nix")
|
|
[[ ${#types[@]} -gt 0 ]] && echo " - $name ($(IFS=, ; echo "${types[*]}"))"
|
|
done
|
|
exit 1
|
|
fi
|
|
|
|
if $HAS_NIX && $HAS_DOCKERFILE; then
|
|
# Both exist — require explicit flag
|
|
case "$BUILD_TYPE_FLAG" in
|
|
--nix)
|
|
BUILD_TYPE="nix"
|
|
;;
|
|
--dockerfile)
|
|
BUILD_TYPE="dockerfile"
|
|
;;
|
|
*)
|
|
echo "Error: '$CONTAINER' has both a Dockerfile and default.nix."
|
|
echo ""
|
|
echo "Specify the build type:"
|
|
echo " mise run container-tag-and-release $CONTAINER $VERSION --nix"
|
|
echo " mise run container-tag-and-release $CONTAINER $VERSION --dockerfile"
|
|
exit 1
|
|
;;
|
|
esac
|
|
elif $HAS_NIX; then
|
|
BUILD_TYPE="nix"
|
|
elif $HAS_DOCKERFILE; then
|
|
BUILD_TYPE="dockerfile"
|
|
fi
|
|
|
|
if [[ "$BUILD_TYPE" == "nix" ]]; then
|
|
TAG="${CONTAINER}-nix-${VERSION}"
|
|
else
|
|
TAG="${CONTAINER}-${VERSION}"
|
|
fi
|
|
|
|
echo "Creating release tag: $TAG"
|
|
echo "Build type: $BUILD_TYPE"
|
|
echo ""
|
|
|
|
# Check if tag already exists
|
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
|
echo "Error: Tag '$TAG' already exists"
|
|
echo "Existing tags for $CONTAINER:"
|
|
git tag -l "${CONTAINER}-*v*" | sort -V | tail -5
|
|
exit 1
|
|
fi
|
|
|
|
# Image name follows convention: blumeops/<container>
|
|
IMAGE="blumeops/${CONTAINER}"
|
|
|
|
echo "Container: $CONTAINER"
|
|
echo "Directory: $CONTAINER_DIR"
|
|
echo "Image: registry.ops.eblu.me/$IMAGE:$VERSION"
|
|
echo ""
|
|
|
|
# Create and push tag
|
|
git tag "$TAG"
|
|
git push origin "$TAG"
|
|
|
|
echo ""
|
|
echo "Tag '$TAG' created and pushed"
|
|
echo ""
|
|
echo "The workflow will now build and push:"
|
|
echo " registry.ops.eblu.me/$IMAGE:$VERSION"
|
|
echo ""
|
|
echo "Monitor the build at:"
|
|
echo " https://forge.ops.eblu.me/eblume/blumeops/actions"
|