Skip to content

Commit

Permalink
moved version to version/version.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ehearneRedHat committed Jul 4, 2024
1 parent d79b2fd commit bab591c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY version/ version/

# Build
ARG VERSION
ARG COMMIT
ARG DIRTY

ENV VERSION=${VERSION:-unknown}
ENV COMMIT=${COMMIT:-unknown}
ENV DIRTY=${DIRTY:-unknown}
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ endef
VERSION ?= 0.0.0

# ldflag variables
VERSION_LIMITADOR_OPERATOR=0.10.0-dev # change this when version increases
COMMIT=$(shell git rev-parse HEAD)
DIRTY=$(shell $(check_dirty))

Expand Down Expand Up @@ -285,15 +284,15 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests.
##@ Build

build: generate fmt vet ## Build manager binary.
go build -ldflags "-X main.version=${VERSION_LIMITADOR_OPERATOR} -X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go
go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go

run: export LOG_LEVEL = debug
run: export LOG_MODE = development
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: ## Build docker image with the manager.
docker build --build-arg VERSION=$(VERSION_LIMITADOR_OPERATOR) --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) .
docker build --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) .

docker-push: ## Push docker image with the manager.
docker push $(IMG)
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ import (
"github.com/kuadrant/limitador-operator/controllers"
"github.com/kuadrant/limitador-operator/pkg/log"
"github.com/kuadrant/limitador-operator/pkg/reconcilers"

//+kubebuilder:scaffold:imports
// import version
"github.com/kuadrant/limitador-operator/version"
)

var (
scheme = k8sruntime.NewScheme()
logLevel = env.GetString("LOG_LEVEL", "info")
logMode = env.GetString("LOG_MODE", "production")
version string
commit string
dirty string
)
Expand All @@ -70,7 +72,7 @@ func printControllerMetaInfo() {
setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version()))
setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH))
setupLog.Info("base logger", "log level", logLevel, "log mode", logMode)
setupLog.Info("booting up limitador-operator", "version", version, "commit", commit, "dirty", dirty)
setupLog.Info("booting up limitador-operator", "version", version.Version, "commit", commit, "dirty", dirty)
}

func main() {
Expand Down
21 changes: 21 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2021 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package version

var (
// This variable is dependent on what the current release is e.g. if it is v0.10.0 then this variable, outside of releases, will be v0.10.1-dev .
Version = "0.10.0-dev"
)

0 comments on commit bab591c

Please sign in to comment.