Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make buildimg IMG="${IMAGE}:${TAG}"
make buildimg IMG="${IMAGE}:${TAG}" VERSION="$(cat VERSION)"
podman login -u "${ACTOR}" -p "${GH_TOKEN}" ghcr.io
podman push "${IMAGE}:${TAG}"

Expand Down
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN --mount=type=cache,id=dnf,target=/var/cache/libdnf5 \
FROM ${GO_BUILDER_IMAGE} AS builder

ARG VERSION=dev
ARG GIT_COMMIT=unknown
ARG GIT_COMMIT=
WORKDIR /workspace
COPY go.mod go.sum ./
RUN --mount=type=cache,id=gomod,target=/root/go/pkg/mod \
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ CONTAINER_TOOL ?= podman
BINK_CLUSTER_NAME ?= e2e
KUBECONFIG_BINK ?= ./kubeconfig-$(BINK_CLUSTER_NAME)
ARTIFACTS ?= $(abspath _output/logs)
VERSION ?= $(shell git describe --tags --always --dirty)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= dev
GIT_COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),dirty,$(shell git rev-parse HEAD))
LDFLAGS := -X github.com/bootc-dev/bootc-operator/internal/version.Version=$(VERSION) \
-X github.com/bootc-dev/bootc-operator/internal/version.GitCommit=$(GIT_COMMIT)
DEFAULT_KUBE_MINOR ?= 1.36
Expand Down Expand Up @@ -176,7 +176,9 @@ build-daemon: ## Build daemon binary.

.PHONY: buildimg
buildimg: ## Build container image.
$(CONTAINER_TOOL) build -t $(IMG) .
$(CONTAINER_TOOL) build \
--build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) \
-t $(IMG) .

.PHONY: release-manifest
release-manifest: kustomize yq ## Build install manifest (override IMG to set the image reference).
Expand Down
7 changes: 7 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"flag"
"fmt"
"os"
"strings"
"time"
Expand Down Expand Up @@ -46,6 +47,7 @@ func init() {

func main() {
var enableLeaderElection bool
var showVersion bool
var probeAddr string
var tagResolutionInterval time.Duration
var allowInsecureRegistry bool
Expand All @@ -70,11 +72,16 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&showVersion, "version", false, "Print version and exit.")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if showVersion {
fmt.Println(version.String())
return
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

Expand Down
6 changes: 6 additions & 0 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,24 @@ func init() {

func main() {
var pollInterval time.Duration
var showVersion bool
flag.DurationVar(
&pollInterval,
"bootc-poll-interval",
daemon.DefaultPollInterval,
"Interval for polling bootc status as a fallback to fsnotify",
)
flag.BoolVar(&showVersion, "version", false, "Print version and exit.")

opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if showVersion {
fmt.Println(version.String())
return
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

Expand Down
16 changes: 15 additions & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
// Package version holds build metadata set via linker flags.
package version

// dirtyCommit marks builds from a worktree with uncommitted changes.
const dirtyCommit = "dirty"

var (
Version = "dev"
GitCommit = "unknown"
GitCommit = ""
)

// String returns the version and its Git revision when available.
func String() string {
switch GitCommit {
case "":
return Version
case dirtyCommit:
return Version + " (" + dirtyCommit + ")"
}
return Version + " (commit " + GitCommit + ")"
}
Loading