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
98 changes: 98 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Release

on:
pull_request:
types: [closed]

permissions: {}

jobs:
release:
if: >-
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
env:
IMAGE: ghcr.io/${{ github.repository }}
steps:
- name: Create GitHub App token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Extract version
id: version
run: |
VERSION=$(cat VERSION)
if ! echo "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid version format: ${VERSION}"
exit 1
fi
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "tag=v${VERSION}" >> "${GITHUB_OUTPUT}"

- name: Create and push tag
env:
TAG: ${{ steps.version.outputs.tag }}
APP_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
if git rev-parse "${TAG}" >/dev/null 2>&1; then
echo "::error::Tag ${TAG} already exists"
exit 1
fi
git tag -a -m "Release ${TAG}" "${TAG}"
git remote set-url origin "https://x-access-token:${APP_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push origin "${TAG}"
git remote set-url origin "https://github.com/${GITHUB_REPOSITORY}.git"

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: true # zizmor: ignore[cache-poisoning]

- name: Build and push container image
env:
TAG: ${{ steps.version.outputs.tag }}
ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
make buildimg IMG="${IMAGE}:${TAG}"
podman login -u "${ACTOR}" -p "${GH_TOKEN}" ghcr.io
podman push "${IMAGE}:${TAG}"

- name: Build install manifest
env:
TAG: ${{ steps.version.outputs.tag }}
run: make release-manifest IMG="${IMAGE}:${TAG}"

- name: Create release
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
{
printf '## Installation\n\n'
printf '```bash\n'
printf 'kubectl apply -f https://github.com/%s/releases/download/%s/install.yaml\n' \
"${GITHUB_REPOSITORY}" "${TAG}"
printf '```\n'
} > notes.md
gh release create "${TAG}" \
--title "Release ${TAG}" \
--notes-file notes.md \
--generate-notes \
--draft \
install.yaml
7 changes: 5 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ RUN --mount=type=cache,id=dnf,target=/var/cache/libdnf5 \
dnf install ${DNF_FLAGS} golang

FROM buildroot as builder
ARG VERSION=dev
ARG GIT_COMMIT=unknown
WORKDIR /workspace
COPY go.mod go.sum ./
RUN --mount=type=cache,id=gomod,target=/root/go/pkg/mod \
go mod download
COPY . .
RUN --mount=type=cache,id=gomod,target=/root/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
go build -o manager ./cmd/controller/ && \
go build -o daemon ./cmd/daemon/
LDFLAGS="-X github.com/bootc-dev/bootc-operator/internal/version.Version=${VERSION} -X github.com/bootc-dev/bootc-operator/internal/version.GitCommit=${GIT_COMMIT}" && \
go build -ldflags "${LDFLAGS}" -o manager ./cmd/controller/ && \
go build -ldflags "${LDFLAGS}" -o daemon ./cmd/daemon/

FROM quay.io/fedora/fedora-minimal:44
COPY --from=builder /workspace/manager /workspace/daemon /usr/local/bin/
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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)
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.35
BINK_NODE_DISK_IMAGE ?= ghcr.io/bootc-dev/bink/node:v$(DEFAULT_KUBE_MINOR)-fedora-44-disk
BINK_LOCAL_REGISTRY_NODE_IMAGE ?= registry.cluster.local:5000/node
Expand Down Expand Up @@ -105,16 +109,23 @@ build: build-manager build-daemon ## Build all binaries.

.PHONY: build-manager
build-manager: ## Build manager binary.
go build -o bin/manager ./cmd/controller/
go build -ldflags '$(LDFLAGS)' -o bin/manager ./cmd/controller/

.PHONY: build-daemon
build-daemon: ## Build daemon binary.
go build -o bin/daemon ./cmd/daemon/
go build -ldflags '$(LDFLAGS)' -o bin/daemon ./cmd/daemon/

.PHONY: buildimg
buildimg: ## Build container image.
$(CONTAINER_TOOL) build -t $(IMG) .

.PHONY: release-manifest
release-manifest: kustomize yq ## Build install manifest (override IMG to set the image reference).
"$(KUSTOMIZE)" build config/default | \
"$(YQ)" '(select(.kind == "Deployment") | .spec.template.spec.containers[] | select(.name == "manager")).image = "$(IMG)"' | \
"$(YQ)" '(select(.kind == "DaemonSet") | .spec.template.spec.containers[] | select(.name == "daemon")).image = "$(IMG)"' \
> install.yaml

.PHONY: build-update-image
build-update-image: ## Build derived node images for update testing and push to bink registry.
@printf 'FROM localhost:5000/node:latest\nRUN touch /usr/share/update-marker\n' | \
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
11 changes: 11 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
bootcv1alpha1 "github.com/bootc-dev/bootc-operator/api/v1alpha1"
"github.com/bootc-dev/bootc-operator/internal/controller"
"github.com/bootc-dev/bootc-operator/internal/registry"
"github.com/bootc-dev/bootc-operator/internal/version"
)

var (
Expand Down Expand Up @@ -64,6 +65,16 @@ func main() {

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

setupLog.Info(
"starting",
"component",
"controller",
"version",
version.Version,
"commit",
version.GitCommit,
)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: probeAddr,
Expand Down
11 changes: 11 additions & 0 deletions cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
bootcv1alpha1 "github.com/bootc-dev/bootc-operator/api/v1alpha1"
"github.com/bootc-dev/bootc-operator/internal/bootc"
"github.com/bootc-dev/bootc-operator/internal/daemon"
"github.com/bootc-dev/bootc-operator/internal/version"
)

var (
Expand Down Expand Up @@ -50,6 +51,16 @@ func main() {

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

setupLog.Info(
"starting",
"component",
"daemon",
"version",
version.Version,
"commit",
version.GitCommit,
)

nodeName := os.Getenv("NODE_NAME")
if nodeName == "" {
setupLog.Error(
Expand Down
8 changes: 8 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

package version

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